diff --git a/ortools/algorithms/python/pywrapknapsack_solver.cc b/ortools/algorithms/python/pywrapknapsack_solver.cc index 96c9c46615..678255b61c 100644 --- a/ortools/algorithms/python/pywrapknapsack_solver.cc +++ b/ortools/algorithms/python/pywrapknapsack_solver.cc @@ -28,12 +28,12 @@ using ::py::arg; PYBIND11_MODULE(pywrapknapsack_solver, m) { py::class_(m, "KnapsackSolver") .def(py::init()) - .def("Init", &KnapsackSolver::Init, arg("profits"), arg("weights"), + .def("init", &KnapsackSolver::Init, arg("profits"), arg("weights"), arg("capacities")) - .def("Solve", &KnapsackSolver::Solve) - .def("BestSolutionContains", &KnapsackSolver::BestSolutionContains, + .def("solve", &KnapsackSolver::Solve) + .def("best_solution_contains", &KnapsackSolver::BestSolutionContains, arg("item_id")) - .def("IsSolutionOptimal", &KnapsackSolver::IsSolutionOptimal) + .def("is_solution_optimal", &KnapsackSolver::IsSolutionOptimal) .def("set_time_limit", &KnapsackSolver::set_time_limit, arg("time_limit_seconds")) .def("set_use_reduction", &KnapsackSolver::set_use_reduction, diff --git a/ortools/algorithms/python/pywrapknapsack_solver_test.py b/ortools/algorithms/python/pywrapknapsack_solver_test.py index 557b283240..ce3e0c34f6 100755 --- a/ortools/algorithms/python/pywrapknapsack_solver_test.py +++ b/ortools/algorithms/python/pywrapknapsack_solver_test.py @@ -27,8 +27,8 @@ class PyWrapAlgorithmsKnapsackSolverTest(unittest.TestCase): def RealSolve(self, profits, weights, capacities, solver_type, use_reduction): solver = pywrapknapsack_solver.KnapsackSolver(solver_type, "solver") solver.set_use_reduction(use_reduction) - solver.Init(profits, weights, capacities) - profit = solver.Solve() + solver.init(profits, weights, capacities) + profit = solver.solve() return profit diff --git a/ortools/algorithms/samples/BUILD.bazel b/ortools/algorithms/samples/BUILD.bazel index 94b15d3f33..6da65fd105 100644 --- a/ortools/algorithms/samples/BUILD.bazel +++ b/ortools/algorithms/samples/BUILD.bazel @@ -13,17 +13,12 @@ load( ":code_samples.bzl", - "code_sample_cc", + "code_sample_cc_py", "code_sample_java", - "code_sample_py", ) -code_sample_cc(name = "knapsack") +code_sample_cc_py(name = "knapsack") -code_sample_py(name = "knapsack") - -code_sample_cc(name = "simple_knapsack_program") - -code_sample_py(name = "simple_knapsack_program") +code_sample_cc_py(name = "simple_knapsack_program") code_sample_java(name = "Knapsack") diff --git a/ortools/algorithms/samples/knapsack.py b/ortools/algorithms/samples/knapsack.py index dee7710afe..2a9cea719b 100644 --- a/ortools/algorithms/samples/knapsack.py +++ b/ortools/algorithms/samples/knapsack.py @@ -139,8 +139,8 @@ def main(): # [END data] # [START solve] - solver.Init(values, weights, capacities) - computed_value = solver.Solve() + solver.init(values, weights, capacities) + computed_value = solver.solve() # [END solve] # [START print_solution] @@ -149,7 +149,7 @@ def main(): total_weight = 0 print("Total value =", computed_value) for i in range(len(values)): - if solver.BestSolutionContains(i): + if solver.best_solution_contains(i): packed_items.append(i) packed_weights.append(weights[0][i]) total_weight += weights[0][i] diff --git a/ortools/algorithms/samples/simple_knapsack_program.py b/ortools/algorithms/samples/simple_knapsack_program.py index 8a04163d0b..788106a4ad 100644 --- a/ortools/algorithms/samples/simple_knapsack_program.py +++ b/ortools/algorithms/samples/simple_knapsack_program.py @@ -56,13 +56,13 @@ def main(): # [END data] # [START solve] - solver.Init(values, weights, capacities) - computed_value = solver.Solve() + solver.init(values, weights, capacities) + computed_value = solver.solve() # [END solve] # [START print_solution] packed_items = [ - x for x in range(0, len(weights[0])) if solver.BestSolutionContains(x) + x for x in range(0, len(weights[0])) if solver.best_solution_contains(x) ] packed_weights = [weights[0][i] for i in packed_items]