From d7a33542a20cc60f2c55669e295c7cf8966e3467 Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Tue, 14 May 2019 09:44:13 +0200 Subject: [PATCH] Sync g3 -> github --- ortools/algorithms/csharp/knapsack_solver.i | 3 --- ortools/algorithms/java/knapsack_solver.i | 2 +- ortools/algorithms/python/knapsack_solver.i | 2 +- ortools/algorithms/samples/Knapsack.cs | 11 ++++++----- ortools/algorithms/samples/knapsack.cc | 3 +++ ortools/algorithms/samples/knapsack.py | 17 ++++++++--------- ortools/constraint_solver/samples/tsp_cities.py | 2 +- .../linear_solver/samples/SimpleLpProgram.java | 3 ++- .../linear_solver/samples/simple_lp_program.py | 10 +++++----- .../linear_solver/samples/simple_mip_program.py | 10 +++++----- 10 files changed, 32 insertions(+), 31 deletions(-) diff --git a/ortools/algorithms/csharp/knapsack_solver.i b/ortools/algorithms/csharp/knapsack_solver.i index b52c97bd34..fd30704412 100644 --- a/ortools/algorithms/csharp/knapsack_solver.i +++ b/ortools/algorithms/csharp/knapsack_solver.i @@ -25,9 +25,6 @@ #include "ortools/algorithms/knapsack_solver.h" %} -typedef int64_t int64; -typedef uint64_t uint64; - // See the comment in // ../../constraint_solver/csharp/constraint_solver.i about naming // the template instantiation of std::vector<> differently. diff --git a/ortools/algorithms/java/knapsack_solver.i b/ortools/algorithms/java/knapsack_solver.i index 6053e49925..0a05c94545 100644 --- a/ortools/algorithms/java/knapsack_solver.i +++ b/ortools/algorithms/java/knapsack_solver.i @@ -14,7 +14,7 @@ // Java wrapping of ../knapsack_solver.h. See that file. // // USAGE EXAMPLE (which is also used as unit test): -// - java/com/google/ortools/samples/Knapsack.java +// - java/com/google/ortools/algorithms/samples/Knapsack.java // // TODO(user): test all lines marked "untested". diff --git a/ortools/algorithms/python/knapsack_solver.i b/ortools/algorithms/python/knapsack_solver.i index 4055a55a61..736060176d 100644 --- a/ortools/algorithms/python/knapsack_solver.i +++ b/ortools/algorithms/python/knapsack_solver.i @@ -14,7 +14,7 @@ // Python wrapping of ../knapsack_solver.h. See that file. // // USAGE EXAMPLES: -// - examples/python/knapsack.py +// - ortools/algorithms/samples/knapsack.py // - ./pywrapknapsack_solver_test.py %include "stdint.i" diff --git a/ortools/algorithms/samples/Knapsack.cs b/ortools/algorithms/samples/Knapsack.cs index 127b938094..9422119efe 100644 --- a/ortools/algorithms/samples/Knapsack.cs +++ b/ortools/algorithms/samples/Knapsack.cs @@ -23,7 +23,8 @@ public class Knapsack { // [START solver] KnapsackSolver solver = new KnapsackSolver( - KnapsackSolver.SolverType.KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER, "test"); + KnapsackSolver.SolverType.KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER, + "KnapsackExample"); // [END solver] // [START data] @@ -44,14 +45,14 @@ public class Knapsack long[] capacities = { 850 }; // [END data] - // [START print_solution] - Console.WriteLine("Solving knapsack with " + values.Length + - " items, and " + weights.GetLength(0) + " dimension"); + // [START solve] solver.Init(values, weights, capacities); long computedValue = solver.Solve(); + // [END solve] + // [START print_solution] Console.WriteLine("Optimal Value = " + computedValue); - // [END print_solution] + // [END print_solution] } } // [END program] diff --git a/ortools/algorithms/samples/knapsack.cc b/ortools/algorithms/samples/knapsack.cc index 9c398fd55d..544f6ffb00 100644 --- a/ortools/algorithms/samples/knapsack.cc +++ b/ortools/algorithms/samples/knapsack.cc @@ -42,6 +42,8 @@ void RunKnapsackExample() { 7, 29, 93, 44, 71, 3, 86, 66, 31, 65, 0, 79, 20, 65, 52, 13}}; std::vector capacities = {850}; + // [END data] + // [START solve] solver.Init(values, weights, capacities); int64 computed_value = solver.Solve(); @@ -83,3 +85,4 @@ int main(int argc, char **argv) { operations_research::RunKnapsackExample(); return EXIT_SUCCESS; } +// [END program] diff --git a/ortools/algorithms/samples/knapsack.py b/ortools/algorithms/samples/knapsack.py index b5656f09ae..1fd433f2a3 100644 --- a/ortools/algorithms/samples/knapsack.py +++ b/ortools/algorithms/samples/knapsack.py @@ -10,9 +10,8 @@ # 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] """A simple knapsack problem.""" - +# [START program] # [START import] from __future__ import print_function from ortools.algorithms import pywrapknapsack_solver @@ -23,8 +22,8 @@ def main(): # Create the solver. # [START solver] solver = pywrapknapsack_solver.KnapsackSolver( - pywrapknapsack_solver.KnapsackSolver.KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER, - 'KnapsackExample') + pywrapknapsack_solver.KnapsackSolver. + KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER, 'KnapsackExample') # [END solver] # [START data] @@ -42,15 +41,15 @@ def main(): capacities = [850] # [END data] - # [START solver] + # [START solve] solver.Init(values, weights, capacities) computed_profit = solver.Solve() - # [END solver] - - # [START solve] - print('optimal profit = ' + str(computed_profit)) # [END solve] + # [START print_solution] + print('optimal profit =', computed_profit) + # [END print_solution] + if __name__ == '__main__': main() diff --git a/ortools/constraint_solver/samples/tsp_cities.py b/ortools/constraint_solver/samples/tsp_cities.py index 3e96d21fd9..d92fadb939 100644 --- a/ortools/constraint_solver/samples/tsp_cities.py +++ b/ortools/constraint_solver/samples/tsp_cities.py @@ -39,7 +39,7 @@ def create_data_model(): [1420, 1374, 940, 1056, 879, 225, 1891, 1605, 1645, 679, 0, 1017, 1200], [2145, 357, 1453, 1280, 586, 887, 1114, 2300, 653, 1272, 1017, 0, 504], [1972, 579, 1260, 987, 371, 999, 701, 2099, 600, 1162, 1200, 504, 0], - ] # yapf: disable + ] # yapf: disable data['num_vehicles'] = 1 data['depot'] = 0 return data diff --git a/ortools/linear_solver/samples/SimpleLpProgram.java b/ortools/linear_solver/samples/SimpleLpProgram.java index 76a83dcb95..7890b0b26d 100644 --- a/ortools/linear_solver/samples/SimpleLpProgram.java +++ b/ortools/linear_solver/samples/SimpleLpProgram.java @@ -29,7 +29,8 @@ public class SimpleLpProgram { public static void main(String[] args) throws Exception { // [START solver] // Create the linear solver with the GLOP backend. - MPSolver solver = new MPSolver("SimpleLpProgram", + MPSolver solver = new MPSolver( + "SimpleLpProgram", MPSolver.OptimizationProblemType.GLOP_LINEAR_PROGRAMMING); // [END solver] diff --git a/ortools/linear_solver/samples/simple_lp_program.py b/ortools/linear_solver/samples/simple_lp_program.py index 7c6f5caa6e..0f4b4561f1 100644 --- a/ortools/linear_solver/samples/simple_lp_program.py +++ b/ortools/linear_solver/samples/simple_lp_program.py @@ -30,7 +30,7 @@ def main(): x = solver.NumVar(0, 1, 'x') y = solver.NumVar(0, 2, 'y') - print('Number of variables = ', solver.NumVariables()) + print('Number of variables =', solver.NumVariables()) # [END variables] # [START constraints] @@ -39,7 +39,7 @@ def main(): ct.SetCoefficient(x, 1) ct.SetCoefficient(y, 1) - print('Number of constraints = ', solver.NumConstraints()) + print('Number of constraints =', solver.NumConstraints()) # [END constraints] # [START objective] @@ -56,9 +56,9 @@ def main(): # [START print_solution] print('Solution:') - print('Objective value = ', objective.Value()) - print('x = ', x.solution_value()) - print('y = ', y.solution_value()) + print('Objective value =', objective.Value()) + print('x =', x.solution_value()) + print('y =', y.solution_value()) # [END print_solution] diff --git a/ortools/linear_solver/samples/simple_mip_program.py b/ortools/linear_solver/samples/simple_mip_program.py index 1ce863f0a9..167b5584db 100644 --- a/ortools/linear_solver/samples/simple_mip_program.py +++ b/ortools/linear_solver/samples/simple_mip_program.py @@ -31,7 +31,7 @@ def main(): x = solver.IntVar(0.0, infinity, 'x') y = solver.IntVar(0.0, infinity, 'y') - print('Number of variables = ', solver.NumVariables()) + print('Number of variables =', solver.NumVariables()) # [END variables] # [START constraints] @@ -41,7 +41,7 @@ def main(): # x <= 3.5. solver.Add(x <= 3.5) - print('Number of constraints = ', solver.NumConstraints()) + print('Number of constraints =', solver.NumConstraints()) # [END constraints] # [START objective] @@ -61,9 +61,9 @@ def main(): # [START print_solution] print('Solution:') - print('Objective value = ', solver.Objective().Value()) - print('x = ', x.solution_value()) - print('y = ', y.solution_value()) + print('Objective value =', solver.Objective().Value()) + print('x =', x.solution_value()) + print('y =', y.solution_value()) # [END print_solution] # [START advanced]