Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
ip_model_solve_parameters_tests.cc
Go to the documentation of this file.
1// Copyright 2010-2024 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
15
16#include <optional>
17#include <ostream>
18#include <sstream>
19#include <string>
20#include <vector>
21
22#include "absl/status/statusor.h"
23#include "gtest/gtest.h"
24#include "ortools/base/gmock.h"
28#include "ortools/math_opt/parameters.pb.h"
30
31namespace operations_research {
32namespace math_opt {
33namespace {
34
35using ::testing::DoubleNear;
36using ::testing::status::IsOkAndHolds;
37
38std::string PrintParams(const std::optional<SolveParameters>& params) {
39 return params.has_value() ? ProtobufShortDebugString(params->Proto())
40 : "nullopt";
41}
42
43} // namespace
44
45std::ostream& operator<<(std::ostream& out,
46 const SolutionHintTestParams& params) {
47 out << "{ solver_type: " << params.solver_type
48 << " single_hint_params: " << PrintParams(params.single_hint_params)
49 << " two_hint_params: " << PrintParams(params.two_hint_params)
50 << ", hint_message_regex: " << params.hint_accepted_message_regex << " }";
51 return out;
52}
53
54std::ostream& operator<<(std::ostream& out,
55 const BranchPrioritiesTestParams& params) {
56 out << "{ solver_type: " << params.solver_type << " solve_params: "
57 << ProtobufShortDebugString(params.solve_params.Proto()) << " }";
58 return out;
59}
60
61std::ostream& operator<<(std::ostream& out,
62 const LazyConstraintsTestParams& params) {
63 out << "{ solver_type: " << params.solver_type << " solve_params: "
65 return out;
66}
67
68namespace {
69
70TEST_P(IpModelSolveParametersTest, SolutionFilterSkipZeros) {
72 const Variable x = model.AddBinaryVariable("x");
73 const Variable y = model.AddBinaryVariable("y");
74 model.Maximize(2.0 * x + y);
75 model.AddLinearConstraint(0.0 <= x + y <= 1.5, "c");
77 const SolveResult result,
78 Solve(model, TestedSolver(),
79 {.model_parameters = {
80 .variable_values_filter = {.skip_zero_values = true}}}));
81 ASSERT_THAT(result, IsOptimal(2.0));
82 EXPECT_THAT(result.variable_values(), IsNear({{x, 1.0}}));
83}
84
85TEST_P(IpModelSolveParametersTest, SolutionFilterByKey) {
86 Model model;
87 const Variable x = model.AddBinaryVariable("x");
88 const Variable y = model.AddBinaryVariable("y");
89 model.Maximize(2.0 * x + y);
90 model.AddLinearConstraint(0.0 <= x + y <= 1.5, "c");
91
93 const SolveResult result,
94 Solve(model, TestedSolver(),
95 {.model_parameters =
97 ASSERT_THAT(result, IsOptimal(2.0));
98 EXPECT_THAT(result.variable_values(), IsNear({{y, 0.0}}));
99}
100
101TEST_P(MipSolutionHintTest, SingleHintTest) {
102 if (!SingleHintParams().has_value()) {
103 GTEST_SKIP() << "Single hints not supported. Ignoring this test.";
104 }
105
106 ModelSolveParameters model_parameters;
107
108 Model model("Solution Hint MIP");
109
110 Variable x1 = model.AddBinaryVariable("x1");
111 Variable x2 = model.AddBinaryVariable("x2");
112 model.AddLinearConstraint(x1 + x2 == 1);
113
114 Variable x3 = model.AddBinaryVariable("x3");
115 Variable x4 = model.AddBinaryVariable("x4");
116 model.AddLinearConstraint(x3 + x4 == 1);
117
118 model.Maximize(x1 + 3 * x2 + 2 * x3 + 4 * x4);
119
120 // Only feasible completion of this hint has (x1, x2, x3, x4) = (1, 0, 1, 0)
121 // with objective value equal to 3.
122 ModelSolveParameters::SolutionHint hint;
123 hint.variable_values = {{x1, 1.0}, {x4, 0.0}};
124 model_parameters.solution_hints.emplace_back(hint);
125
126 std::ostringstream log;
127 const SolveArguments args = {
128 // SingleHintParams() is expected to set (possibly solver-specific)
129 // parameters to ensure the optimization stops after the first feasible
130 // solution (e.g. solution limit of 1) and that this solution is the one
131 // associated to the hint and not the optimal solution with objective
132 // value 7.
133 .parameters = *SingleHintParams(),
134 .model_parameters = model_parameters,
135 .message_callback = PrinterMessageCallback(log)};
136 ASSERT_OK_AND_ASSIGN(const SolveResult result,
137 Solve(model, TestedSolver(), args));
138 EXPECT_THAT(result,
140 /*allow_limit_undetermined=*/true));
142 result,
143 HasSolution(PrimalSolution{
144 .variable_values = {{x1, 1.0}, {x2, 0.0}, {x3, 1.0}, {x4, 0.0}},
145 .objective_value = 3.0,
146 .feasibility_status = SolutionStatus::kFeasible}));
147 EXPECT_THAT(log.str(), testing::ContainsRegex(HintAcceptedMessageRegex()));
148}
149
150TEST_P(MipSolutionHintTest, TwoHintTest) {
151 if (!TwoHintParams().has_value()) {
152 GTEST_SKIP() << "Multiple hints not supported. Ignoring this test.";
153 }
154
155 ModelSolveParameters model_parameters;
156
157 Model model("Solution Hint MIP");
158
159 Variable x1 = model.AddBinaryVariable("x1");
160 Variable x2 = model.AddBinaryVariable("x2");
161 model.AddLinearConstraint(x1 + x2 == 1);
162
163 Variable x3 = model.AddBinaryVariable("x3");
164 Variable x4 = model.AddBinaryVariable("x4");
165 model.AddLinearConstraint(x3 + x4 == 1);
166
167 Variable x5 = model.AddBinaryVariable("x5");
168 Variable x6 = model.AddBinaryVariable("x6");
169 model.AddLinearConstraint(x5 + x6 == 1);
170
171 model.Maximize(x1 + 3 * x2 + 2 * x3 + 4 * x4 + x5 + 2 * x6);
172
173 // Only feasible completion of this hint has
174 // (x1, x2, x3, x4, x5, x6) = (1, 0, 1, 0, 1, 0)
175 // with objective value equal to 4.
176 ModelSolveParameters::SolutionHint first_hint;
177 first_hint.variable_values = {{x1, 1.0}, {x4, 0.0}, {x5, 1.0}};
178 model_parameters.solution_hints.emplace_back(first_hint);
179 const Solution first_solution{
180 .primal_solution = {{.variable_values = {{x1, 1.0},
181 {x2, 0.0},
182 {x3, 1.0},
183 {x4, 0.0},
184 {x5, 1.0},
185 {x6, 0.0}},
186 .objective_value = 4,
187 .feasibility_status = SolutionStatus::kFeasible}}};
188
189 // Only feasible completion of this hint has
190 // (x1, x2, x3, x4, x5, x6) = (1, 0, 1, 0, 0, 1)
191 // with objective value equal to 5.
192 ModelSolveParameters::SolutionHint second_hint;
193 second_hint.variable_values = {{x1, 1.0}, {x4, 0.0}, {x6, 1.0}};
194 model_parameters.solution_hints.emplace_back(second_hint);
195 const Solution second_solution{
196 .primal_solution =
197 PrimalSolution{.variable_values = {{x1, 1.0},
198 {x2, 0.0},
199 {x3, 1.0},
200 {x4, 0.0},
201 {x5, 0.0},
202 {x6, 1.0}},
203 .objective_value = 5,
204 .feasibility_status = SolutionStatus::kFeasible}};
205 std::ostringstream log;
206 const SolveArguments args = {
207 // TwoHintParams() is expected to set (possibly solver-specific)
208 // parameters to ensure the optimization stops after the second feasible
209 // solution (e.g. solution limit of 2) and that these solutions are the
210 // ones associated to the hints and not the optimal solution with
211 // objective value 9.
212 .parameters = *TwoHintParams(),
213 .model_parameters = model_parameters,
214 .message_callback = PrinterMessageCallback(log)};
215 ASSERT_OK_AND_ASSIGN(const SolveResult result,
216 Solve(model, TestedSolver(), args));
218 // Solutions should be objective-ordered and not hint-ordered.
219 // Gurobi does not guarantee that all solution pool entries are feasible, so
220 // we also accept undetermined feasibility status.
222 result.solutions,
223 ElementsAre(IsNear(second_solution),
224 IsNear(first_solution, {.allow_undetermined = true})));
225 EXPECT_THAT(log.str(), testing::ContainsRegex(HintAcceptedMessageRegex()));
226}
227
228TEST_P(BranchPrioritiesTest, PrioritiesAreSetProperly) {
229 // We solve min{ |x| : x in {-2, -1, 1}} = 1 through the following simple
230 // MIP formulation.
231 Model model("Solution Hint MIP");
232 Variable x = model.AddContinuousVariable(-3.0, 1.0, "x");
233 Variable y = model.AddContinuousVariable(0.0, 3.0, "y");
234 Variable zminus2 = model.AddBinaryVariable("zminus2");
235 Variable zminus1 = model.AddBinaryVariable("zminus1");
236 Variable zplus1 = model.AddBinaryVariable("zplus1");
237 model.AddLinearConstraint(zminus2 + zminus1 + zplus1 == 1);
238 model.AddLinearConstraint(-2 * zminus2 - zminus1 + zplus1 == x);
239 model.AddLinearConstraint(x <= y);
240 model.AddLinearConstraint(-x <= y);
241 model.Minimize(y);
242 // The optimal value of the LP relaxation of this formulation is zero and (in
243 // the absence of cuts and preprocessing) the best bound will remain at zero
244 // after branching on variables zminus3 or zminus2. The problem can be solved
245 // by branching on zminus3 and zminus2. However, it can also be solved by
246 // just branching on zplus1. Hence, adding higher branch priority to zplus1
247 // should result in fewer branch-and-bound nodes than adding higher priorities
248 // to zminus3 and zminus2.
249
250 // SolveParams() is expected to set (possibly solver-specific) parameters
251 // to ensure the solver behaves as close as possible to a pure
252 // branch-and-bound solver (e.g. turn presolve, heuristics and cuts off).
253 // Major deviations from this could cause the test to fail.
254 const SolveParameters solve_params = SolveParams();
255
256 // We first solve giving higher branch priority to zplus1
257 // Note: we only store the node count instead of testing its value as this
258 // could be brittle (solvers often differ by one unit on the meaning of node
259 // count).
260 ModelSolveParameters model_parameters;
261 model_parameters.branching_priorities = {
262 {zminus2, 1}, {zminus1, 1}, {zplus1, 2}};
263 const SolveArguments good_args = {.parameters = solve_params,
264 .model_parameters = model_parameters};
265 ASSERT_OK_AND_ASSIGN(const SolveResult good_result,
266 Solve(model, TestedSolver(), good_args));
267 ASSERT_THAT(good_result, IsOptimal());
268 const int good_node_count = good_result.solve_stats.node_count;
269
270 // We then give higher priorities to zminus2 and zminus1 and check it takes
271 // more nodes to solve.
272 model_parameters.branching_priorities = {
273 {zminus2, 2}, {zminus1, 2}, {zplus1, 1}};
274 const SolveArguments bad_args = {.parameters = solve_params,
275 .model_parameters = model_parameters};
276 ASSERT_OK_AND_ASSIGN(const SolveResult bad_result,
277 Solve(model, TestedSolver(), bad_args));
278 ASSERT_THAT(bad_result, IsOptimal());
279 EXPECT_GT(bad_result.solve_stats.node_count, good_node_count);
280}
281
282// See PrioritiesAreSetProperly for details on the model and solve parameters.
283TEST_P(BranchPrioritiesTest, PrioritiesClearedAfterIncrementalSolve) {
284 Model model;
285 Variable x = model.AddContinuousVariable(-3.0, 1.0, "x");
286 Variable y = model.AddContinuousVariable(0.0, 3.0, "y");
287 Variable zminus2 = model.AddBinaryVariable("zminus2");
288 Variable zminus1 = model.AddBinaryVariable("zminus1");
289 Variable zplus1 = model.AddBinaryVariable("zplus1");
290 model.AddLinearConstraint(zminus2 + zminus1 + zplus1 == 1);
291 model.AddLinearConstraint(-2 * zminus2 - zminus1 + zplus1 == x);
292 model.AddLinearConstraint(x <= y);
293 model.AddLinearConstraint(-x <= y);
294 model.Minimize(y);
295
296 // First, we do a static solve with "good" branching priorities as a baseline.
298 const int node_count_good_priorities, ([&]() -> absl::StatusOr<int> {
299 const SolveArguments args = {
300 .parameters = SolveParams(),
301 .model_parameters = {.branching_priorities = {
302 {zminus1, 1}, {zminus2, 1}, {zplus1, 3}}}};
303 ASSIGN_OR_RETURN(const SolveResult result,
304 Solve(model, TestedSolver(), args));
305 RETURN_IF_ERROR(result.termination.EnsureIsOptimal());
306 return result.solve_stats.node_count;
307 }()));
308
309 // Next, we solve incrementally with "good" branching priorities, but a very
310 // tight node limit. We expect the solver to load the priorities, but not to
311 // make any progress towards the optimal solution.
312 ASSERT_OK_AND_ASSIGN(const auto solver,
313 NewIncrementalSolver(&model, TestedSolver()));
314 {
315 SolveParameters params = SolveParams();
316 params.node_limit = 0;
317 const SolveArguments args = {
318 .parameters = params,
319 .model_parameters = {
320 .branching_priorities = {{zminus1, 1}, {zminus2, 1}, {zplus1, 3}}}};
321 ASSERT_OK_AND_ASSIGN(const SolveResult good_result, solver->Solve(args));
323 }
324
325 // Finally, using the same incremental solver we solve with partial branching
326 // priorities, and record the node count. If the previously set branching
327 // priorities are overwritten, these are "good" priorities (zplus1 will be
328 // highest priority); if they were cleared previously, then these are "bad"
329 // priorities (zplus has the lowest priority with a default value of 0).
331 const int node_count_no_priorities, ([&]() -> absl::StatusOr<int> {
332 const SolveArguments args{
333 .parameters = SolveParams(),
334 .model_parameters = {
335 .branching_priorities = {{zminus1, 2}, {zminus2, 2}}}};
336 ASSIGN_OR_RETURN(const SolveResult result, solver->Solve(args));
337 RETURN_IF_ERROR(result.termination.EnsureIsOptimal());
338 return result.solve_stats.node_count;
339 }()));
340
341 // If priorities were properly cleared for the second incremental solve, it
342 // should take more nodes to solve than with the "good" branching priorities.
343 EXPECT_GT(node_count_no_priorities, node_count_good_priorities);
344}
345
346// The problem is:
347// min x
348// s.t. x >= 1 (c)
349// 0 <= x <= 2
350// x integer
351//
352// We mark (c) as a lazy constraint, solve, and verify that the optimal solution
353// returned respects it (i.e., x^* = 1).
354TEST_P(LazyConstraintsTest, LazyConstraintsImposedOnModel) {
355 Model model;
356 Variable x = model.AddIntegerVariable(0, 2, "x");
357 const LinearConstraint c = model.AddLinearConstraint(x >= 1);
358 model.Minimize(x);
359
360 // We intentionally do not use NerfedSolveParams() here: Gurobi produces the
361 // wrong solution with presolve disabled (!), and we only want to test that
362 // the lazy constraint is respected.
363 SolveArguments args = {.model_parameters = {.lazy_linear_constraints = {c}}};
364 args.parameters.enable_output = true;
365 EXPECT_THAT(Solve(model, TestedSolver(), args),
367}
368
369// The problem is:
370// min y
371// s.t. y >= x (c)
372// y >= -x (d)
373// -1 <= x, y <= 1
374// x, y integer
375//
376// With a node limit of 0 and solver parameters set to disable presolve, we
377// expect a dual bound equal to the LP relaxation bound (which is 0). However,
378// if c and d are lazy constraints, they are not included in the LP relaxation,
379// and the bound instead is -1.
380TEST_P(LazyConstraintsTest, AnnotationsAreSetProperly) {
381 Model model;
382 Variable x = model.AddIntegerVariable(-1, 1, "x");
383 Variable y = model.AddIntegerVariable(-1, 1, "y");
384 const LinearConstraint c = model.AddLinearConstraint(y >= x);
385 const LinearConstraint d = model.AddLinearConstraint(y >= -x);
386 model.Minimize(y);
387
388 SolveArguments args = {
389 .parameters = NerfedSolveParams(),
390 .model_parameters = {.lazy_linear_constraints = {c, d}}};
391 args.parameters.node_limit = 0;
392 ASSERT_OK_AND_ASSIGN(const SolveResult result,
393 Solve(model, TestedSolver(), args));
395 EXPECT_THAT(result.best_objective_bound(), DoubleNear(-1, 1.0e-5));
396}
397
398// Same setting as in AnnotationsAreSetProperly above, but we solve twice with
399// an incremental solver: first with the lazy constraint annotations, and then
400// without. If the annotations are cleared after the first, then we expect the
401// second to solve the entire LP (including c and d), giving a dual bound of 0.
402TEST_P(LazyConstraintsTest, AnnotationsAreClearedAfterSolve) {
403 Model model;
404 Variable x = model.AddIntegerVariable(-1, 1, "x");
405 Variable y = model.AddIntegerVariable(-1, 1, "y");
406 const LinearConstraint c = model.AddLinearConstraint(y >= x);
407 const LinearConstraint d = model.AddLinearConstraint(y >= -x);
408 model.Minimize(y);
409 ASSERT_OK_AND_ASSIGN(const auto solver,
410 NewIncrementalSolver(&model, TestedSolver()));
411
412 SolveArguments args = {
413 .parameters = NerfedSolveParams(),
414 .model_parameters = {.lazy_linear_constraints = {c, d}}};
415 args.parameters.node_limit = 0;
416 ASSERT_OK_AND_ASSIGN(const SolveResult bad_result, solver->Solve(args));
418 ASSERT_THAT(bad_result.best_objective_bound(), DoubleNear(-1, 1.0e-5));
419
420 args.model_parameters.lazy_linear_constraints.clear();
421 ASSERT_OK_AND_ASSIGN(const SolveResult good_result, solver->Solve(args));
423 EXPECT_THAT(good_result.best_objective_bound(), DoubleNear(0, 1.0e-5));
424}
425
426} // namespace
427} // namespace math_opt
428} // namespace operations_research
IntegerValue y
#define ASSIGN_OR_RETURN(lhs, rexpr)
#define RETURN_IF_ERROR(expr)
GRBmodel * model
const Variable x2
const Variable x1
std::optional< ModelSolveParameters::SolutionHint > hint
Matcher< SolveResult > IsOptimalWithSolution(const double expected_objective, const VariableMap< double > expected_variable_values, const double tolerance)
Definition matchers.cc:777
EXPECT_THAT(ComputeInfeasibleSubsystem(model, GetParam().solver_type), IsOkAndHolds(IsInfeasible(true, ModelSubset{ .variable_bounds={{x, ModelSubset::Bounds{.lower=false,.upper=true}}},.linear_constraints={ {c, ModelSubset::Bounds{.lower=true,.upper=false}}}})))
TEST_P(InfeasibleSubsystemTest, CanComputeInfeasibleSubsystem)
<=x<=1 IncrementalMipTest::IncrementalMipTest() :model_("incremental_solve_test"), x_(model_.AddContinuousVariable(0.0, 1.0, "x")), y_(model_.AddIntegerVariable(0.0, 2.0, "y")), c_(model_.AddLinearConstraint(0<=x_+y_<=1.5, "c")) { model_.Maximize(3.0 *x_+2.0 *y_+0.1);solver_=NewIncrementalSolver(&model_, TestedSolver()).value();const SolveResult first_solve=solver_->Solve().value();CHECK(first_solve.has_primal_feasible_solution());CHECK_LE(std::abs(first_solve.objective_value() - 3.6), kTolerance)<< first_solve.objective_value();} namespace { TEST_P(SimpleMipTest, OneVarMax) { Model model;const Variable x=model.AddVariable(0.0, 4.0, false, "x");model.Maximize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(8.0));EXPECT_THAT(result.variable_values(), IsNear({{x, 4.0}}));} TEST_P(SimpleMipTest, OneVarMin) { Model model;const Variable x=model.AddVariable(-2.4, 4.0, false, "x");model.Minimize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(-4.8));EXPECT_THAT(result.variable_values(), IsNear({{x, -2.4}}));} TEST_P(SimpleMipTest, OneIntegerVar) { Model model;const Variable x=model.AddVariable(0.0, 4.5, true, "x");model.Maximize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(8.0));EXPECT_THAT(result.variable_values(), IsNear({{x, 4.0}}));} TEST_P(SimpleMipTest, SimpleLinearConstraint) { Model model;const Variable x=model.AddBinaryVariable("x");const Variable y=model.AddBinaryVariable("y");model.Maximize(2.0 *x+y);model.AddLinearConstraint(0.0<=x+y<=1.5, "c");ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(2.0));EXPECT_THAT(result.variable_values(), IsNear({{x, 1}, {y, 0}}));} TEST_P(SimpleMipTest, Unbounded) { Model model;const Variable x=model.AddVariable(0.0, kInf, true, "x");model.Maximize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));if(GetParam().report_unboundness_correctly) { ASSERT_THAT(result, TerminatesWithOneOf({TerminationReason::kUnbounded, TerminationReason::kInfeasibleOrUnbounded}));} else { ASSERT_THAT(result, TerminatesWith(TerminationReason::kOtherError));} } TEST_P(SimpleMipTest, Infeasible) { Model model;const Variable x=model.AddVariable(0.0, 3.0, true, "x");model.Maximize(2.0 *x);model.AddLinearConstraint(x >=4.0);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, TerminatesWith(TerminationReason::kInfeasible));} TEST_P(SimpleMipTest, FractionalBoundsContainNoInteger) { if(GetParam().solver_type==SolverType::kGurobi) { GTEST_SKIP()<< "TODO(b/272298816): Gurobi bindings are broken here.";} Model model;const Variable x=model.AddIntegerVariable(0.5, 0.6, "x");model.Maximize(x);EXPECT_THAT(Solve(model, GetParam().solver_type), IsOkAndHolds(TerminatesWith(TerminationReason::kInfeasible)));} TEST_P(IncrementalMipTest, EmptyUpdate) { ASSERT_THAT(solver_->Update(), IsOkAndHolds(DidUpdate()));ASSERT_OK_AND_ASSIGN(const SolveResult result, solver_->SolveWithoutUpdate());ASSERT_THAT(result, IsOptimal(3.6));EXPECT_THAT(result.variable_values(), IsNear({{x_, 0.5}, {y_, 1.0}}));} TEST_P(IncrementalMipTest, MakeContinuous) { model_.set_continuous(y_);ASSERT_THAT(solver_->Update(), IsOkAndHolds(DidUpdate()));ASSERT_OK_AND_ASSIGN(const SolveResult result, solver_->SolveWithoutUpdate());ASSERT_THAT(result, IsOptimal(4.1));EXPECT_THAT(result.variable_values(), IsNear({{x_, 1.0}, {y_, 0.5}}));} TEST_P(IncrementalMipTest, DISABLED_MakeContinuousWithNonIntegralBounds) { solver_.reset();Model model("bounds");const Variable x=model.AddIntegerVariable(0.5, 1.5, "x");model.Maximize(x);ASSERT_OK_AND_ASSIGN(const auto solver, NewIncrementalSolver(&model, TestedSolver()));ASSERT_THAT(solver->Solve(), IsOkAndHolds(IsOptimal(1.0)));model.set_continuous(x);ASSERT_THAT(solver->Update(), IsOkAndHolds(DidUpdate()));ASSERT_THAT(solver-> IsOkAndHolds(IsOptimal(1.5)))
ASSERT_THAT(solver->Update(), IsOkAndHolds(DidUpdate()))
absl::StatusOr< SolveResult > Solve(const Model &model, const SolverType solver_type, const SolveArguments &solve_args, const SolverInitArguments &init_args)
Definition solve.cc:62
std::ostream & operator<<(std::ostream &ostr, const IndicatorConstraint &constraint)
absl::StatusOr< std::unique_ptr< IncrementalSolver > > NewIncrementalSolver(Model *model, SolverType solver_type, SolverInitArguments arguments)
Definition solve.cc:82
Matcher< SolveResult > HasSolution(PrimalSolution expected, const double tolerance)
SolveResult has a primal solution matching expected within tolerance.
Definition matchers.cc:823
@ kFeasible
Solver claims the solution is feasible.
testing::Matcher< SolveResult > TerminatesWithReasonFeasible(const Limit expected, const bool allow_limit_undetermined)
Definition matchers.cc:657
MessageCallback PrinterMessageCallback(std::ostream &output_stream, const absl::string_view prefix)
testing::Matcher< SolveResult > TerminatesWithLimit(const Limit expected, const bool allow_limit_undetermined)
Definition matchers.cc:648
Matcher< VariableMap< double > > IsNear(VariableMap< double > expected, const double tolerance)
Definition matchers.cc:221
Matcher< SolveResult > IsOptimal(const std::optional< double > expected_primal_objective, const double tolerance)
Definition matchers.cc:762
testing::Matcher< SolveResult > TerminatesWithReasonNoSolutionFound(const Limit expected, const bool allow_limit_undetermined)
Definition matchers.cc:665
In SWIG mode, we don't want anything besides these top-level includes.
std::string ProtobufShortDebugString(const P &message)
Definition proto_utils.h:41
#define ASSERT_OK_AND_ASSIGN(lhs, rexpr)
Parameters for the BranchPrioritiesTest suite below.
Parameters for the LazyConstraintsTest suite below.
static ModelSolveParameters OnlySomePrimalVariables(const Collection &variables)
Parameters for the MipSolutionHintTest suite below.