add test from #2385
This commit is contained in:
@@ -129,6 +129,38 @@ void RunBooleanProgrammingExample(
|
||||
SolveAndPrint(solver, {x, y}, {c0});
|
||||
}
|
||||
|
||||
void MutableObjectiveCrash() {
|
||||
LOG(INFO) << "MutableObjectiveCrash";
|
||||
// Create the linear solver with the GLOP backend.
|
||||
MPSolver* solver = MPSolver::CreateSolver("GLOP");
|
||||
|
||||
// Create the variables x and y.
|
||||
MPVariable* const x = solver->MakeNumVar(0.0, 1, "x");
|
||||
MPVariable* const y = solver->MakeNumVar(0.0, 2, "y");
|
||||
|
||||
LOG(INFO) << "Number of variables = " << solver->NumVariables();
|
||||
|
||||
// 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);
|
||||
|
||||
LOG(INFO) << "Number of constraints = " << solver->NumConstraints();
|
||||
|
||||
// Create the objective function, 3 * x + y.
|
||||
MPObjective* const objective = solver->MutableObjective();
|
||||
objective->SetCoefficient(x, 3);
|
||||
objective->SetCoefficient(y, 1);
|
||||
objective->SetMaximization();
|
||||
|
||||
solver->Solve();
|
||||
|
||||
LOG(INFO) << "Solution:" << std::endl;
|
||||
LOG(INFO) << "Objective value = " << objective->Value();
|
||||
LOG(INFO) << "x = " << x->solution_value();
|
||||
LOG(INFO) << "y = " << y->solution_value();
|
||||
}
|
||||
|
||||
void RunAllExamples() {
|
||||
// Linear programming problems
|
||||
#if defined(USE_CLP)
|
||||
@@ -179,6 +211,8 @@ void RunAllExamples() {
|
||||
LOG(INFO) << "---- Boolean Integer programming example with BOP ----";
|
||||
RunBooleanProgrammingExample(MPSolver::BOP_INTEGER_PROGRAMMING);
|
||||
#endif // USE_BOP
|
||||
|
||||
MutableObjectiveCrash();
|
||||
}
|
||||
} // namespace operations_research
|
||||
|
||||
|
||||
Reference in New Issue
Block a user