diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ec7b30..b6e79be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.18.2 (unreleased) + +- Added `best_objective_bound` method to `CpSolver` and `CpSolverSolutionCallback` + ## 0.18.1 (2026-10-02) - Added support for breaks for routing diff --git a/ext/or-tools/constraint.cpp b/ext/or-tools/constraint.cpp index 74ae9f6..5d7bc2c 100644 --- a/ext/or-tools/constraint.cpp +++ b/ext/or-tools/constraint.cpp @@ -927,6 +927,7 @@ void init_constraint(Rice::Module& m) { Rice::define_class_under(m, "CpSolverResponse") .define_method("objective_value", &CpSolverResponse::objective_value) + .define_method("best_objective_bound", &CpSolverResponse::best_objective_bound) .define_method("num_conflicts", &CpSolverResponse::num_conflicts) .define_method("num_branches", &CpSolverResponse::num_branches) .define_method("wall_time", &CpSolverResponse::wall_time) diff --git a/lib/or_tools/cp_solver.rb b/lib/or_tools/cp_solver.rb index 99d482a..8e710e3 100644 --- a/lib/or_tools/cp_solver.rb +++ b/lib/or_tools/cp_solver.rb @@ -4,7 +4,7 @@ module ORTools class CpSolver extend Forwardable - def_delegators :@response, :objective_value, :num_conflicts, :num_branches, :wall_time + def_delegators :@response, :objective_value, :best_objective_bound, :num_conflicts, :num_branches, :wall_time def solve(model, observer = nil) @response = _solve(model, parameters, observer) diff --git a/lib/or_tools/cp_solver_solution_callback.rb b/lib/or_tools/cp_solver_solution_callback.rb index bf2b742..91721ed 100644 --- a/lib/or_tools/cp_solver_solution_callback.rb +++ b/lib/or_tools/cp_solver_solution_callback.rb @@ -17,6 +17,10 @@ def objective_value @response&.objective_value end + def best_objective_bound + @response&.best_objective_bound + end + def stop_search @stopped = true end diff --git a/test/constraint_test.rb b/test/constraint_test.rb index fdad09d..b73c325 100644 --- a/test/constraint_test.rb +++ b/test/constraint_test.rb @@ -141,6 +141,7 @@ def test_optimization y = 3 z = 5 EOS + assert_equal 35, solver.best_objective_bound end # https://developers.google.com/optimization/cp/cryptarithmetic diff --git a/test/solution_printer_test.rb b/test/solution_printer_test.rb index e3129c0..9fb6cb3 100644 --- a/test/solution_printer_test.rb +++ b/test/solution_printer_test.rb @@ -11,6 +11,7 @@ def test_objective_solution_printer solver.parameters.enumerate_all_solutions = true solution_printer = ORTools::ObjectiveSolutionPrinter.new assert_nil solution_printer.objective_value + assert_nil solution_printer.best_objective_bound stdout, _ = capture_io do solver.solve(model, solution_printer)