From 2e5e79cdc7398fe06aafca5a68e619d9e4000054 Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Fri, 9 Nov 2018 09:21:33 +0100 Subject: [PATCH] Add linear_solver/samples/SimpleLPProgram --- examples/dotnet/SimpleProgram.csproj | 20 -- examples/python/simple_program.py | 37 ---- makefiles/Makefile.cpp.mk | 106 ++++++----- makefiles/Makefile.dotnet.mk | 90 ++++----- makefiles/Makefile.java.mk | 96 ++++++---- makefiles/Makefile.python.mk | 172 +++++++++--------- .../linear_solver/samples/SimpleLpProgram.cs | 20 +- .../samples/SimpleLpProgram.java | 19 +- .../samples/simple_lp_program.cc | 35 ++-- .../samples/simple_lp_program.py | 12 +- 10 files changed, 319 insertions(+), 288 deletions(-) delete mode 100644 examples/dotnet/SimpleProgram.csproj delete mode 100644 examples/python/simple_program.py rename examples/dotnet/SimpleProgram.cs => ortools/linear_solver/samples/SimpleLpProgram.cs (69%) rename examples/java/SimpleProgram.java => ortools/linear_solver/samples/SimpleLpProgram.java (75%) rename examples/cpp/simple_program.cc => ortools/linear_solver/samples/simple_lp_program.cc (58%) diff --git a/examples/dotnet/SimpleProgram.csproj b/examples/dotnet/SimpleProgram.csproj deleted file mode 100644 index fa65ddcad6..0000000000 --- a/examples/dotnet/SimpleProgram.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - Exe - 7.2 - netcoreapp2.1 - false - ../../packages;$(RestoreSources);https://api.nuget.org/v3/index.json - - - - full - true - true - - - - - - - diff --git a/examples/python/simple_program.py b/examples/python/simple_program.py deleted file mode 100644 index 6d504c102c..0000000000 --- a/examples/python/simple_program.py +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2018 Google LLC -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# [START program] -from __future__ import print_function -from ortools.linear_solver import pywraplp - -def main(): - solver = pywraplp.Solver('SolveSimpleSystem', - pywraplp.Solver.GLOP_LINEAR_PROGRAMMING) - # Create the variables x and y. - x = solver.NumVar(0, 1, 'x') - y = solver.NumVar(0, 2, 'y') - # Create the objective function, x + y. - objective = solver.Objective() - objective.SetCoefficient(x, 1) - objective.SetCoefficient(y, 1) - objective.SetMaximization() - # Call the solver and display the results. - solver.Solve() - print('Solution:') - print('x = ', x.solution_value()) - print('y = ', y.solution_value()) - -if __name__ == '__main__': - main() -# [END program] diff --git a/makefiles/Makefile.cpp.mk b/makefiles/Makefile.cpp.mk index 2008d656fe..54a9ced1bf 100755 --- a/makefiles/Makefile.cpp.mk +++ b/makefiles/Makefile.cpp.mk @@ -29,8 +29,8 @@ endif # Main target .PHONY: cc # Build C++ OR-Tools library. -.PHONY: check_cc # Quick check only running few C++ OR-Tools examples. -.PHONY: test_cc # Run all C++ OR-Tools examples. +.PHONY: check_cc # Quick check only running C++ OR-Tools samples targets. +.PHONY: test_cc # Run all C++ OR-Tools test targets. .PHONY: test_fz # Run all Flatzinc OR-Tools examples. ifndef HAS_CCC cc: @@ -41,13 +41,9 @@ test_cc: cc test_fz: cc else cc: $(OR_TOOLS_LIBS) -check_cc: check_cc_examples -test_cc: \ - test_cc_tests \ - test_cc_samples \ - test_cc_examples -test_fz: \ - test_fz_examples +check_cc: check_cc_pimpl +test_cc: test_cc_pimpl +test_fz: test_fz_pimpl BUILT_LANGUAGES += C++ endif @@ -407,6 +403,9 @@ $(OBJ_DIR)/%.$O: $(CC_EX_DIR)/%.cc $(OR_TOOLS_LIBS) | $(OBJ_DIR) $(OBJ_DIR)/%.$O: $(CONTRIB_EX_DIR)/%.cc $(OR_TOOLS_LIBS) | $(OBJ_DIR) $(CCC) $(CFLAGS) -c $(CONTRIB_EX_PATH)$S$*.cc $(OBJ_OUT)$(OBJ_DIR)$S$*.$O +$(OBJ_DIR)/%.$O: ortools/linear_solver/samples/%.cc $(OR_TOOLS_LIBS) | $(OBJ_DIR) + $(CCC) $(CFLAGS) -c ortools$Slinear_solver$Ssamples$S$*.cc $(OBJ_OUT)$(OBJ_DIR)$S$*.$O + $(OBJ_DIR)/%.$O: ortools/sat/samples/%.cc $(OR_TOOLS_LIBS) | $(OBJ_DIR) $(CCC) $(CFLAGS) -c ortools$Ssat$Ssamples$S$*.cc $(OBJ_OUT)$(OBJ_DIR)$S$*.$O @@ -416,22 +415,33 @@ $(BIN_DIR)/%$E: $(OBJ_DIR)/%.$O $(OR_TOOLS_LIBS) | $(BIN_DIR) rcc_%: $(BIN_DIR)/%$E FORCE $(BIN_DIR)$S$*$E $(ARGS) -.PHONY: test_cc_tests # Build and Run all C++ tests (located in examples/tests) -test_cc_tests: \ - rcc_ac4r_table_test \ - rcc_boolean_test \ - rcc_bug_fz1 \ - rcc_cpp11_test \ - rcc_forbidden_intervals_test \ - rcc_gcc_test \ - rcc_issue57 \ - rcc_min_max_test \ - rcc_visitor_test -# $(MAKE) rcc_issue173 # error: too long +.PHONY: test_cc_sat_samples # Build and Run all C++ Sat Samples (located in ortools/sat/samples) +test_cc_sat_samples: \ + rcc_binpacking_problem \ + rcc_bool_or_sample \ + rcc_channeling_sample \ + rcc_code_sample \ + rcc_interval_sample \ + rcc_literal_sample \ + rcc_no_overlap_sample \ + rcc_optional_interval_sample \ + rcc_rabbits_and_pheasants \ + rcc_ranking_sample \ + rcc_reified_sample \ + rcc_simple_solve \ + rcc_solve_all_solutions \ + rcc_solve_with_intermediate_solutions \ + rcc_solve_with_time_limit \ + rcc_stop_after_n_solutions -.PHONY: check_cc_examples # Build and Run few C++ Examples (located in examples/cpp) -check_cc_examples: \ - rcc_simple_program \ +.PHONY: test_cc_linear_solver_samples # Build and Run all C++ LP Samples (located in ortools/linear_solver/samples) +test_cc_linear_solver_samples: \ + rcc_simple_lp_program + +.PHONY: check_cc_pimpl +check_cc_pimpl: \ + test_cc_sat_samples \ + test_cc_linear_solver_samples \ rcc_linear_programming \ rcc_stigler_diet \ rcc_constraint_programming_cp \ @@ -445,8 +455,24 @@ check_cc_examples: \ rcc_nurses_cp \ rcc_job_shop_cp ; -.PHONY: test_cc_examples # Build and Run all C++ Examples (located in examples/cpp) -test_cc_examples: check_cc_examples \ +.PHONY: test_cc_tests # Build and Run all C++ Tests (located in ortools/examples/tests) +test_cc_tests: \ + rcc_ac4r_table_test \ + rcc_boolean_test \ + rcc_bug_fz1 \ + rcc_cpp11_test \ + rcc_forbidden_intervals_test \ + rcc_gcc_test \ + rcc_issue57 \ + rcc_min_max_test \ + rcc_visitor_test +# $(MAKE) rcc_issue173 # error: too long + +.PHONY: test_cc_contrib # Build and Run all C++ Contrib (located in ortools/examples/contrib) +test_cc_contrib: ; + +.PHONY: test_cc_cpp # Build and Run all C++ Examples (located in ortools/examples/cpp) +test_cc_cpp: \ rcc_costas_array \ rcc_cryptarithm \ rcc_cvrp_disjoint_tw \ @@ -502,27 +528,15 @@ test_cc_examples: check_cc_examples \ # $(MAKE) run SOURCE=examples/cpp/shift_minimization_sat.cc # Port to new API. # $(MAKE) run SOURCE=examples/cpp/solve.cc # Need data file -.PHONY: test_cc_samples # Build and Run all C++ Samples (located in ortools/*/samples) -test_cc_samples: \ - rcc_binpacking_problem \ - rcc_bool_or_sample \ - rcc_channeling_sample \ - rcc_code_sample \ - rcc_interval_sample \ - rcc_literal_sample \ - rcc_no_overlap_sample \ - rcc_optional_interval_sample \ - rcc_rabbits_and_pheasants \ - rcc_ranking_sample \ - rcc_reified_sample \ - rcc_simple_solve \ - rcc_solve_all_solutions \ - rcc_solve_with_intermediate_solutions \ - rcc_solve_with_time_limit \ - rcc_stop_after_n_solutions +.PHONY: test_cc_pimpl +test_cc_pimpl: \ + check_cc_pimpl \ + test_cc_tests \ + test_cc_contrib \ + test_cc_cpp -.PHONY: test_fz_examples # Build and Run few Flatzinc Samples (located in examples/flatzinc) -test_fz_examples: \ +.PHONY: test_fz_pimpl +test_fz_pimpl: \ rfz_golomb \ rfz_alpha diff --git a/makefiles/Makefile.dotnet.mk b/makefiles/Makefile.dotnet.mk index 759d00e057..1cf1a76912 100644 --- a/makefiles/Makefile.dotnet.mk +++ b/makefiles/Makefile.dotnet.mk @@ -37,16 +37,9 @@ dotnet: check_dotnet: dotnet test_dotnet: dotnet else -dotnet: \ - dotnet_csharp \ - dotnet_fsharp -check_dotnet: check_dotnet_examples -test_dotnet: \ - test_dotnet_csharp \ - test_dotnet_fsharp \ - test_dotnet_tests \ - test_donet_samples \ - test_dotnet_examples +dotnet: dotnet_csharp dotnet_fsharp +check_dotnet: check_dotnet_pimpl +test_dotnet: test_dotnet_pimpl BUILT_LANGUAGES +=, dotnet \(netstandard2.0\) endif @@ -477,6 +470,42 @@ rdotnet_%.cs: \ "$(DOTNET_BIN)" build ortools$Ssat$Ssamples$S$*.csproj "$(DOTNET_BIN)" run --no-build --project ortools$Ssat$Ssamples$S$*.csproj -- $(ARGS) +rdotnet_%.cs: \ + ortools/linear_solver/samples/%.cs \ + ortools/linear_solver/samples/%.csproj \ + $(DOTNET_ORTOOLS_NUPKG) FORCE + "$(DOTNET_BIN)" build ortools$Slinear_solver$Ssamples$S$*.csproj + "$(DOTNET_BIN)" run --no-build --project ortools$Slinear_solver$Ssamples$S$*.csproj -- $(ARGS) + +.PHONY: test_donet_sat_samples # Build and Run all .Net SAT Samples (located in ortools/sat/samples) +test_dotnet_samples: \ + rdotnet_binpacking_problem.cs \ + rdotnet_bool_or_sample.cs \ + rdotnet_channeling_sample.cs \ + rdotnet_code_sample.cs \ + rdotnet_interval_sample.cs \ + rdotnet_literal_sample.cs \ + rdotnet_no_overlap_sample.cs \ + rdotnet_optional_interval_sample.cs \ + rdotnet_rabbits_and_pheasants.cs \ + rdotnet_ranking_sample.cs \ + rdotnet_reified_sample.cs \ + rdotnet_simple_solve.cs \ + rdotnet_solve_all_solutions.cs \ + rdotnet_solve_with_intermediate_solutions.cs \ + rdotnet_solve_with_time_limit.cs \ + rdotnet_stop_after_n_solutions.cs + +.PHONY: test_donet_linear_solver_samples # Build and Run all .Net LP Samples (located in ortools/linear_solver/samples) +test_dotnet_linear_solver_samples: \ + rdotnet_SimpleLpProgram + +.PHONY: check_dotnet_pimpl +check_dotnet_pimpl: \ + test_donet_sat_samples \ + test_donet_linear_solver_samples \ + rdotnet_SimpleProgramFSharp.fs + .PHONY: test_dotnet_tests # Build and Run all .Net Tests (located in examples/test) test_dotnet_tests: \ rdotnet_issue18.cs \ @@ -487,18 +516,7 @@ test_dotnet_tests: \ rdotnet_testsat.cs \ rdotnet_test_sat_model.cs -.PHONY: check_dotnet_examples # Build and Run few C++ Examples (located in examples/cpp) -check_dotnet_examples: \ - rdotnet_SimpleProgram.cs \ - rdotnet_SimpleProgramFSharp.fs - -.PHONY: test_dotnet_examples # Build and Run all .Net Examples (located in examples/dotnet) -test_dotnet_examples: \ - check_dotnet_examples \ - test_dotnet_examples_csharp \ - test_dotnet_examples_fsharp - -.PHONY: test_dotnet_examples_csharp # Build and Run all CSharp Examples (located in examples/dotnet) +.PHONY: test_dotnet_examples_csharp # Build and Run all CSharp Examples (located in examples/dotnet and examples/contrib) test_dotnet_examples_csharp: \ rdotnet_3_jugs_regular.cs \ rdotnet_alldifferent_except_0.cs \ @@ -622,7 +640,7 @@ test_dotnet_examples_csharp: \ # $(MAKE) rdotnet_secret_santa # too long # $(MAKE) rdotnet_word_square # depends on /usr/share/dict/words -.PHONY: test_dotnet_examples_fsharp # Build and Run all FSharp Samples (located in examples/dotnet) +.PHONY: test_dotnet_examples_fsharp # Build and Run all FSharp Samples (located in examples/dotnet and examples/contrib) test_dotnet_examples_fsharp: \ rdotnet_fsintegerprogramming.fs \ rdotnet_fslinearprogramming.fs \ @@ -640,24 +658,12 @@ test_dotnet_examples_fsharp: \ rdotnet_fsvolsay3-lpSolve.fs \ rdotnet_fsvolsay.fs -.PHONY: test_donet_samples # Build and Run all .Net Samples (located in ortools/*/samples) -test_dotnet_samples: \ - rdotnet_binpacking_problem.cs \ - rdotnet_bool_or_sample.cs \ - rdotnet_channeling_sample.cs \ - rdotnet_code_sample.cs \ - rdotnet_interval_sample.cs \ - rdotnet_literal_sample.cs \ - rdotnet_no_overlap_sample.cs \ - rdotnet_optional_interval_sample.cs \ - rdotnet_rabbits_and_pheasants.cs \ - rdotnet_ranking_sample.cs \ - rdotnet_reified_sample.cs \ - rdotnet_simple_solve.cs \ - rdotnet_solve_all_solutions.cs \ - rdotnet_solve_with_intermediate_solutions.cs \ - rdotnet_solve_with_time_limit.cs \ - rdotnet_stop_after_n_solutions.cs +.PHONY: test_dotnet_pimpl +test_dotnet_pimpl: \ + check_dotnet_pimpl \ + test_dotnet_tests \ + test_dotnet_examples_csharp \ + test_dotnet_examples_fsharp ################ ## Cleaning ## @@ -706,6 +712,8 @@ clean_dotnet: -$(DELREC) $(TEST_PATH)$Sobj -$(DELREC) ortools$Ssat$Ssamples$Sbin -$(DELREC) ortools$Ssat$Ssamples$Sobj + -$(DELREC) ortools$Slinear_solver$Ssamples$Sbin + -$(DELREC) ortools$Slinear_solver$Ssamples$Sobj -$(DELREC) $(TEMP_DOTNET_DIR) -@"$(DOTNET_BIN)" nuget locals all --clear diff --git a/makefiles/Makefile.java.mk b/makefiles/Makefile.java.mk index 0f7a10abb0..16138d03c8 100755 --- a/makefiles/Makefile.java.mk +++ b/makefiles/Makefile.java.mk @@ -41,11 +41,8 @@ check_java: java test_java: java else java: $(JAVA_OR_TOOLS_LIBS) -check_java: check_java_examples -test_java: \ - test_java_tests \ - test_java_samples \ - test_java_examples +check_java: check_java_pimpl +test_java: test_java_pimpl BUILT_LANGUAGES +=, Java endif @@ -320,6 +317,13 @@ $(CLASS_DIR)/%: $(SRC_DIR)/ortools/sat/samples/%.java $(JAVA_OR_TOOLS_LIBS) | $( -cp $(LIB_DIR)$Scom.google.ortools.jar$(CPSEP)$(LIB_DIR)$Sprotobuf.jar \ ortools$Ssat$Ssamples$S$*.java +$(CLASS_DIR)/%: $(SRC_DIR)/ortools/linear_solver/samples/%.java $(JAVA_OR_TOOLS_LIBS) | $(CLASS_DIR) + -$(DELREC) $(CLASS_DIR)$S$* + -$(MKDIR_P) $(CLASS_DIR)$S$* + "$(JAVAC_BIN)" -d $(CLASS_DIR)$S$* \ + -cp $(LIB_DIR)$Scom.google.ortools.jar$(CPSEP)$(LIB_DIR)$Sprotobuf.jar \ + ortools$Slinear_solver$Ssamples$S$*.java + $(LIB_DIR)/%$J: $(CLASS_DIR)/% | $(LIB_DIR) -$(DEL) $(LIB_DIR)$S$*.jar "$(JAR_BIN)" cvf $(LIB_DIR)$S$*.jar -C $(CLASS_DIR)$S$* . @@ -329,24 +333,47 @@ rjava_%: $(LIB_DIR)/%$J FORCE -cp $(LIB_DIR)$S$*$J$(CPSEP)$(LIB_DIR)$Scom.google.ortools.jar$(CPSEP)$(LIB_DIR)$Sprotobuf.jar \ $* $(ARGS) -.PHONY: test_java_tests # Build and Run all Java Tests (located in examples/tests) -test_java_tests: \ - rjava_TestLp +.PHONY: test_java_sat_samples # Build and Run all Java SAT Samples (located in ortools/sat/samples) +test_java_sat_samples: \ + rjava_BinPackingProblem \ + rjava_BoolOrSample \ + rjava_ChannelingSample \ + rjava_CodeSample \ + rjava_IntervalSample \ + rjava_LiteralSample \ + rjava_NoOverlapSample \ + rjava_OptionalIntervalSample \ + rjava_RabbitsAndPheasants \ + rjava_RankingSample \ + rjava_ReifiedSample \ + rjava_SimpleSolve \ + rjava_SolveAllSolutions \ + rjava_SolveWithIntermediateSolutions \ + rjava_SolveWithTimeLimit \ + rjava_StopAfterNSolutions -.PHONY: check_java_examples # Build and Run few Java Examples (located in examples/java) -check_java_examples: \ - rjava_SimpleProgram \ +.PHONY: test_java_linear_solver_samples # Build and Run all Java LP Samples (located in ortools/linear_solver/samples) +test_java_linear_solver_samples: \ + rjava_SimpleLpProgram + +.PHONY: check_java_pimpl +check_java_pimpl: \ + test_java_sat_samples \ + test_java_linear_solver_samples \ rjava_LinearProgramming \ rjava_IntegerProgramming \ rjava_Tsp \ rjava_Vrp \ rjava_Knapsack -.PHONY: test_java_examples # Build and Run all Java Examples (located in examples/java) -test_java_examples: check_java_examples \ +.PHONY: test_java_tests # Build and Run all Java Tests (located in examples/tests) +test_java_tests: \ + rjava_TestLp + +.PHONY: test_java_contrib # Build and Run all Java Contrib (located in examples/contrib) +test_java_contrib: \ rjava_AllDifferentExcept0 \ rjava_AllInterval \ - rjava_CapacitatedVehicleRoutingProblemWithTimeWindows \ rjava_Circuit \ rjava_CoinsGridMIP \ rjava_ColoringMIP \ @@ -356,12 +383,9 @@ test_java_examples: check_java_examples \ rjava_Diet \ rjava_DietMIP \ rjava_DivisibleBy9Through1 \ - rjava_FlowExample \ rjava_GolombRuler \ rjava_KnapsackMIP \ rjava_LeastDiff \ - rjava_LinearAssignmentAPI \ - rjava_LsApi \ rjava_MagicSquare \ rjava_Map2 \ rjava_Map \ @@ -371,7 +395,6 @@ test_java_examples: check_java_examples \ rjava_NQueens \ rjava_Partition \ rjava_QuasigroupCompletion \ - rjava_RabbitsPheasants \ rjava_SendMoreMoney2 \ rjava_SendMoreMoney \ rjava_SendMostMoney \ @@ -392,24 +415,25 @@ test_java_examples: check_java_examples \ rjava_Xkcd \ rjava_YoungTableaux -.PHONY: test_java_samples # Build and Run all Java Samples (located in ortools/*/samples) -test_java_samples: \ - rjava_BinPackingProblem \ - rjava_BoolOrSample \ - rjava_ChannelingSample \ - rjava_CodeSample \ - rjava_IntervalSample \ - rjava_LiteralSample \ - rjava_NoOverlapSample \ - rjava_OptionalIntervalSample \ - rjava_RabbitsAndPheasants \ - rjava_RankingSample \ - rjava_ReifiedSample \ - rjava_SimpleSolve \ - rjava_SolveAllSolutions \ - rjava_SolveWithIntermediateSolutions \ - rjava_SolveWithTimeLimit \ - rjava_StopAfterNSolutions +.PHONY: test_java_java # Build and Run all Java Examples (located in ortools/examples/java) +test_java_java: \ + rjava_CapacitatedVehicleRoutingProblemWithTimeWindows \ + rjava_FlowExample \ + rjava_IntegerProgramming \ + rjava_Knapsack \ + rjava_LinearAssignmentAPI \ + rjava_LinearProgramming \ + rjava_LsApi \ + rjava_RabbitsPheasants \ + rjava_Tsp \ + rjava_Vrp + +.PHONY: test_java_pimpl +test_java_pimpl: \ + check_java_pimpl \ + test_java_tests \ + test_java_contrib \ + test_java_java ################ ## Cleaning ## diff --git a/makefiles/Makefile.python.mk b/makefiles/Makefile.python.mk index 7735509608..31da8d82f1 100755 --- a/makefiles/Makefile.python.mk +++ b/makefiles/Makefile.python.mk @@ -54,24 +54,17 @@ PYTHON_OR_TOOLS_LIBS = \ # Main target .PHONY: python # Build Python OR-Tools. -.PHONY: check_python # Quick check only running few Python OR-Tools examples. -.PHONY: test_python # Test Python OR-Tools using various examples. +.PHONY: check_python # Quick check only running Python OR-Tools samples. +.PHONY: test_python # Run all Python OR-Tools test targets. ifneq ($(PYTHON_EXECUTABLE),) python: $(PYTHON_OR_TOOLS_LIBS) - -check_python: check_python_examples - -test_python: \ - test_python_tests \ - test_python_samples \ - test_python_examples - +check_python: check_python_pimpl +test_python: test_python_pimpl BUILT_LANGUAGES +=, Python$(PYTHON_VERSION) else python: @echo PYTHON_EXECUTABLE = "${PYTHON_EXECUTABLE}" $(warning Cannot find '$(PYTHON_COMPILER)' command which is needed for build. Please make sure it is installed and in system path.) - check_python: python test_python: python endif @@ -492,12 +485,36 @@ rpy_%: ortools/sat/samples/%.py $(PYTHON_OR_TOOLS_LIBS) FORCE rpy_%: ortools/linear_solver/samples/%.py $(PYTHON_OR_TOOLS_LIBS) FORCE $(SET_PYTHONPATH) "$(PYTHON_EXECUTABLE)" ortools$Slinear_solver$Ssamples$S$*.py $(ARGS) -.PHONY: check_python_examples # Build and Run few Python Examples (located in examples/python and examples/contrib) -check_python_examples: \ - rpy_simple_program \ +.PHONY: test_python_sat_samples # Run all Python Sat Samples (located in ortools/sat/samples) +test_python_sat_samples: \ + rpy_binpacking_problem \ + rpy_bool_or_sample \ + rpy_channeling_sample \ + rpy_code_sample \ + rpy_interval_sample \ + rpy_literal_sample \ + rpy_minimal_jobshop \ + rpy_no_overlap_sample \ + rpy_optional_interval_sample \ + rpy_rabbits_and_pheasants \ + rpy_ranking_sample \ + rpy_reified_sample \ + rpy_simple_solve \ + rpy_solve_all_solutions \ + rpy_solve_with_intermediate_solutions \ + rpy_solve_with_time_limit \ + rpy_stop_after_n_solutions + +.PHONY: test_python_linear_solver_samples # Run all Python LP Samples (located in ortools/linear_solver/samples) +test_python_linear_solver_samples: \ + rpy_simple_lp_program + +.PHONY: check_python_pimpl +check_python_pimpl: \ + test_python_sat_samples \ + test_python_linear_solver_samples \ rpy_linear_programming \ rpy_stigler_diet -# rpy_constraint_programming_cp \ # rpy_constraint_programming_sat \ # rpy_rabbits_pheasants_cp \ # rpy_rabbits_pheasants_sat \ @@ -524,52 +541,23 @@ test_python_tests: \ rpy_test_cp_api \ rpy_test_lp_api -.PHONY: test_python_samples # Run all Python Samples (located in ortools/*/python) -test_python_samples: \ - rpy_binpacking_problem \ - rpy_bool_or_sample \ - rpy_channeling_sample \ - rpy_code_sample \ - rpy_interval_sample \ - rpy_literal_sample \ - rpy_minimal_jobshop \ - rpy_no_overlap_sample \ - rpy_optional_interval_sample \ - rpy_rabbits_and_pheasants \ - rpy_ranking_sample \ - rpy_reified_sample \ - rpy_simple_lp_program \ - rpy_simple_solve \ - rpy_solve_all_solutions \ - rpy_solve_with_intermediate_solutions \ - rpy_solve_with_time_limit \ - rpy_stop_after_n_solutions - -.PHONY: test_python_examples # Run all Python Examples (located in examples/python and examples/contrib) -test_python_examples: \ +.PHONY: test_python_contrib # Run all Python Contrib (located in examples/python and examples/contrib) +test_python_contrib: \ rpy_3_jugs_mip \ rpy_3_jugs_regular \ rpy_alldifferent_except_0 \ rpy_all_interval \ rpy_alphametic \ - rpy_appointments \ rpy_a_round_of_golf \ rpy_assignment6_mip \ rpy_assignment \ - rpy_assignment_sat \ - rpy_assignment_with_constraints \ - rpy_assignment_with_constraints_sat \ rpy_bacp \ - rpy_balance_group_sat \ rpy_blending \ rpy_broken_weights \ rpy_bus_schedule \ rpy_car \ rpy_check_dependencies \ - rpy_chemical_balance_lp \ - rpy_chemical_balance_sat \ rpy_circuit \ - rpy_code_samples_sat \ rpy_coins3 \ rpy_coins_grid_mip \ rpy_coloring_ip \ @@ -577,14 +565,11 @@ test_python_examples: \ rpy_contiguity_regular \ rpy_costas_array \ rpy_covering_opl \ - rpy_cp_is_fun_sat \ rpy_crew \ rpy_crossword2 \ rpy_crypta \ rpy_crypto \ rpy_curious_set_of_integers \ - rpy_cvrp \ - rpy_cvrptw \ rpy_debruijn_binary \ rpy_diet1_b \ rpy_diet1_mip \ @@ -597,35 +582,22 @@ test_python_examples: \ rpy_eq10 \ rpy_eq20 \ rpy_fill_a_pix \ - rpy_flexible_job_shop_sat \ rpy_furniture_moving \ rpy_futoshiki \ rpy_game_theory_taha \ - rpy_gate_scheduling_sat \ - rpy_golomb8 \ rpy_grocery \ - rpy_hidato_sat \ - rpy_hidato_table \ - rpy_integer_programming \ - rpy_jobshop_ft06_distance \ - rpy_jobshop_ft06 \ - rpy_jobshop_ft06_sat \ rpy_just_forgotten \ rpy_kakuro \ rpy_kenken2 \ rpy_killer_sudoku \ rpy_knapsack_cp \ rpy_knapsack_mip \ - rpy_knapsack \ rpy_labeled_dice \ rpy_langford \ rpy_least_diff \ rpy_least_square \ rpy_lectures \ - rpy_linear_assignment_api \ - rpy_linear_programming \ rpy_magic_sequence_sat \ - rpy_magic_sequence_distribute \ rpy_magic_square_and_cards \ rpy_magic_square_mip \ rpy_magic_square \ @@ -642,10 +614,8 @@ test_python_examples: \ rpy_nqueens2 \ rpy_nqueens3 \ rpy_nqueens \ - rpy_nqueens_sat \ rpy_nurse_rostering \ rpy_nurses_cp \ - rpy_nurses_sat \ rpy_olympic \ rpy_organize_day \ rpy_pandigital_numbers \ @@ -654,11 +624,8 @@ test_python_examples: \ rpy_p_median \ rpy_post_office_problem2 \ rpy_production \ - rpy_pyflow_example \ rpy_pyls_api \ rpy_quasigroup_completion \ - rpy_rabbit_pheasant \ - rpy_rcpsp_sat \ rpy_regular \ rpy_regular_table2 \ rpy_regular_table \ @@ -668,7 +635,6 @@ test_python_examples: \ rpy_scheduling_speakers \ rpy_secret_santa2 \ rpy_send_more_money_any_base \ - rpy_sendmore \ rpy_send_most_money \ rpy_seseman_b \ rpy_seseman \ @@ -680,45 +646,87 @@ test_python_examples: \ rpy_set_covering_skiena \ rpy_set_partition \ rpy_sicherman_dice \ - rpy_simple_meeting \ - rpy_single_machine_scheduling_with_setup_release_due_dates_sat \ rpy_ski_assignment \ rpy_slitherlink \ rpy_stable_marriage \ rpy_steel_lns \ - rpy_steel_mill_slab_sat \ rpy_steel \ rpy_stigler \ rpy_strimko2 \ rpy_subset_sum \ - rpy_sudoku \ rpy_survo_puzzle \ rpy_toNum \ rpy_traffic_lights \ - rpy_transit_time \ - rpy_tsp \ - rpy_vendor_scheduling \ rpy_volsay2 \ rpy_volsay3 \ rpy_volsay \ - rpy_vrpgs \ - rpy_vrp \ rpy_wedding_optimal_chart \ - rpy_wedding_optimal_chart_sat \ rpy_who_killed_agatha \ - rpy_worker_schedule_sat \ rpy_xkcd \ - rpy_young_tableaux \ - rpy_zebra + rpy_young_tableaux $(MAKE) run SOURCE=examples/contrib/coins_grid.py ARGS="5 2" $(MAKE) run SOURCE=examples/contrib/hidato.py ARGS="3 3" -# $(MAKE) rpy_cvrptw_plot # error: py3 failure, missing numpy. # $(MAKE) rpy_nontransitive_dice # error: too long # warning: nurse_sat take 18s # $(MAKE) rpy_school_scheduling_sat # error: too long # $(MAKE) rpy_secret_santa # error: too long # $(MAKE) rpy_word_square # Not working on window since it rely on /usr/share/dict/words +.PHONY: test_python_python # Build and Run all Python Examples (located in ortools/examples/python) +test_python_python: \ + rpy_appointments \ + rpy_assignment_sat \ + rpy_assignment_with_constraints \ + rpy_assignment_with_constraints_sat \ + rpy_balance_group_sat \ + rpy_chemical_balance_lp \ + rpy_chemical_balance_sat \ + rpy_code_samples_sat \ + rpy_constraint_programming_cp \ + rpy_cp_is_fun_sat \ + rpy_cvrp \ + rpy_cvrptw \ + rpy_flexible_job_shop_sat \ + rpy_gate_scheduling_sat \ + rpy_golomb8 \ + rpy_hidato_sat \ + rpy_hidato_table \ + rpy_integer_programming \ + rpy_jobshop_ft06_distance \ + rpy_jobshop_ft06 \ + rpy_jobshop_ft06_sat \ + rpy_knapsack \ + rpy_linear_assignment_api \ + rpy_linear_programming \ + rpy_magic_sequence_distribute \ + rpy_nqueens_sat \ + rpy_nurses_sat \ + rpy_pyflow_example \ + rpy_rabbit_pheasant \ + rpy_rcpsp_sat \ + rpy_sendmore \ + rpy_simple_meeting \ + rpy_single_machine_scheduling_with_setup_release_due_dates_sat \ + rpy_steel_mill_slab_sat \ + rpy_stigler_diet \ + rpy_sudoku \ + rpy_transit_time \ + rpy_tsp \ + rpy_vendor_scheduling \ + rpy_vrpgs \ + rpy_vrp \ + rpy_wedding_optimal_chart_sat \ + rpy_worker_schedule_sat \ + rpy_zebra +# $(MAKE) rpy_cvrptw_plot # error: py3 failure, missing numpy. + +.PHONY: test_python_pimpl +test_python_pimpl: \ + check_python_pimpl \ + test_python_tests \ + test_python_contrib \ + test_python_python + ################ ## Cleaning ## ################ diff --git a/examples/dotnet/SimpleProgram.cs b/ortools/linear_solver/samples/SimpleLpProgram.cs similarity index 69% rename from examples/dotnet/SimpleProgram.cs rename to ortools/linear_solver/samples/SimpleLpProgram.cs index b81c6bdba6..801460ce6d 100644 --- a/examples/dotnet/SimpleProgram.cs +++ b/ortools/linear_solver/samples/SimpleLpProgram.cs @@ -1,4 +1,4 @@ -// Copyright 2018 Google LLC +// Copyright 2010-2018 Google LLC // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -11,23 +11,33 @@ // See the License for the specific language governing permissions and // limitations under the License. +// Minimal example to call the GLOP solver. // [START program] using System; using Google.OrTools.LinearSolver; -public class SimpleProgram +public class SimpleLpProgram { static void Main() { - Solver solver = Solver.CreateSolver("SimpleProgram", "GLOP_LINEAR_PROGRAMMING"); + // Create the linear solver with the GLOP backend. + Solver solver = Solver.CreateSolver("SimpleLpProgram", "GLOP_LINEAR_PROGRAMMING"); + // Create the variables x and y. Variable x = solver.MakeNumVar(0.0, 1.0, "x"); Variable y = solver.MakeNumVar(0.0, 2.0, "y"); - // Create the objective function, x + y. + + // Create a linear constraint, 0 <= x + y <= 2. + Constraint ct = solver.MakeConstraint(0.0, 2.0, "ct"); + ct.SetCoefficient(x, 1); + ct.SetCoefficient(y, 1); + + // Create the objective function, 3 * x + y. Objective objective = solver.Objective(); - objective.SetCoefficient(x, 1); + objective.SetCoefficient(x, 3); objective.SetCoefficient(y, 1); objective.SetMaximization(); + // Call the solver and display the results. solver.Solve(); Console.WriteLine("Solution:"); diff --git a/examples/java/SimpleProgram.java b/ortools/linear_solver/samples/SimpleLpProgram.java similarity index 75% rename from examples/java/SimpleProgram.java rename to ortools/linear_solver/samples/SimpleLpProgram.java index 4b5d76dd50..71a608979f 100644 --- a/examples/java/SimpleProgram.java +++ b/ortools/linear_solver/samples/SimpleLpProgram.java @@ -1,4 +1,4 @@ -// Copyright 2018 Google LLC +// Copyright 2010-2018 Google LLC // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -11,25 +11,36 @@ // See the License for the specific language governing permissions and // limitations under the License. +// Minimal example to call the GLOP solver. // [START program] import com.google.ortools.linearsolver.MPConstraint; import com.google.ortools.linearsolver.MPObjective; import com.google.ortools.linearsolver.MPSolver; import com.google.ortools.linearsolver.MPVariable; -public class SimpleProgram { +public class SimpleLpProgram { static { System.loadLibrary("jniortools"); } public static void main(String[] args) throws Exception { - MPSolver solver = new MPSolver("SimpleProgram", + // Create the linear solver with the GLOP backend. + MPSolver solver = new MPSolver("SimpleLpProgram", MPSolver.OptimizationProblemType.valueOf("GLOP_LINEAR_PROGRAMMING")); + // Create the variables x and y. MPVariable x = solver.makeNumVar(0.0, 1.0, "x"); MPVariable y = solver.makeNumVar(0.0, 2.0, "y"); - // Create the objective function, x + y. + + // Create a linear constraint, 0 <= x + y <= 2. + MPConstraint ct = solver.makeConstraint(0.0, 2.0, "ct"); + ct.setCoefficient(x, 1); + ct.setCoefficient(y, 1); + + // Create the objective function, 3 * x + y. MPObjective objective = solver.objective(); + objective.setCoefficient(x, 3); objective.setCoefficient(y, 1); objective.setMaximization(); + // Call the solver and display the results. solver.solve(); System.out.println("Solution:"); diff --git a/examples/cpp/simple_program.cc b/ortools/linear_solver/samples/simple_lp_program.cc similarity index 58% rename from examples/cpp/simple_program.cc rename to ortools/linear_solver/samples/simple_lp_program.cc index 5f8ebf7ffd..117e737b57 100644 --- a/examples/cpp/simple_program.cc +++ b/ortools/linear_solver/samples/simple_lp_program.cc @@ -1,4 +1,4 @@ -// Copyright 2018 Google LLC +// Copyright 2010-2018 Google LLC // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -11,30 +11,41 @@ // See the License for the specific language governing permissions and // limitations under the License. +// Minimal example to call the GLOP solver. // [START program] -#include "ortools/linear_solver/linear_solver.h" -#include "ortools/linear_solver/linear_solver.pb.h" #include +#include "ortools/linear_solver/linear_solver.h" -int main() { - using namespace operations_research; - using namespace std; +namespace operations_research { +void run() { + // Create the linear solver with the GLOP backend. + MPSolver solver("simple_lp_program", MPSolver::GLOP_LINEAR_PROGRAMMING); - MPSolver solver("SimpleProgram", MPSolver::GLOP_LINEAR_PROGRAMMING); // Create the variables x and y. MPVariable* const x = solver.MakeNumVar(0.0, 1, "x"); MPVariable* const y = solver.MakeNumVar(0.0, 2, "y"); - // Create the objective function, x + y. + + // Create a linear constraint, 0 <= x + y <= 2. + MPConstraint* const ct = solver.MakeRowConstraint(0.0, 2.0, "ct"); + ct->SetCoefficient(x, 1); + ct->SetCoefficient(y, 1); + + // Create the objective function, 3 * x + y. MPObjective* const objective = solver.MutableObjective(); - objective->SetCoefficient(x, 1); + objective->SetCoefficient(x, 3); objective->SetCoefficient(y, 1); objective->SetMaximization(); + // Call the solver and display the results. solver.Solve(); - cout << "Solution:" << endl; - cout << "x = " << x->solution_value() << endl; - cout << "y = " << y->solution_value() << endl; + std::cout << "Solution:" << std::endl; + std::cout << "x = " << x->solution_value() << std::endl; + std::cout << "y = " << y->solution_value() << std::endl; +} +} // namespace operations_research +int main() { + operations_research::run(); return EXIT_SUCCESS; } // [END program] diff --git a/ortools/linear_solver/samples/simple_lp_program.py b/ortools/linear_solver/samples/simple_lp_program.py index 4c52c07927..1abe887833 100644 --- a/ortools/linear_solver/samples/simple_lp_program.py +++ b/ortools/linear_solver/samples/simple_lp_program.py @@ -1,4 +1,4 @@ -# Copyright 2010-2017 Google +# Copyright 2010-2018 Google LLC # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -20,18 +20,20 @@ from ortools.linear_solver import pywraplp def main(): # Create the linear solver with the GLOP backend. - solver = pywraplp.Solver('simple_lp_program', - pywraplp.Solver.GLOP_LINEAR_PROGRAMMING) + solver = pywraplp.Solver( + 'simple_lp_program', + pywraplp.Solver.GLOP_LINEAR_PROGRAMMING) + # Create the variables x and y. x = solver.NumVar(0, 1, 'x') y = solver.NumVar(0, 2, 'y') - # Create a linear constraint. + # Create a linear constraint, 0 <= x + y <= 2. ct = solver.Constraint(0, 2, 'ct') ct.SetCoefficient(x, 1) ct.SetCoefficient(y, 1) - # Create the objective function, x + y. + # Create the objective function, 3 * x + y. objective = solver.Objective() objective.SetCoefficient(x, 3) objective.SetCoefficient(y, 1)