OR-Tools / SCIP - 如何使用 MIP 问题的指标约束?
OR-Tools / SCIP - How to use Indicator Constraints for MIP problems?
MiniZinc 站点 (https://www.minizinc.org/doc-2.5.5/en/solvers.html#indicator-constraints) 指出 MIP SCIP 求解器支持指标约束。
我在 http://google.github.io/or-tools/javadoc/com/google/ortools/linearsolver/MPIndicatorConstraint.html 找到了 MPIndicatorConstraint 文档,但没有与之相关的示例。
C++ 文档还介绍了一个 MPSolverInterface,它有一个 AddIndicatorConstraint 方法,我在 Java 文档 (https://developers.google.com/optimization/reference/linear_solver/linear_solver/MPSolverInterface?hl=en)
中没有找到类似的方法
https://github.com/google/or-tools/blob/master/ortools/sat/doc/channeling.md#java-code 提供了 CP 模型的一些示例,但我找不到任何与 MIP 相关的类似应用程序。
是否记录了任何示例?如果没有,是否可以在此线程上分享一个?
根据此 test case,应该可以通过使用原型接口构建模型来使用指标约束。是否有将其移植到 MPSolver 的路线图?
@Test
public void shouldSolveLPWithIndicatorConstraint() {
final MPModelProto.Builder mpModelProto = this.getLinearObjective();
final MPVariableProto k = this.getIntVar("k").setUpperBound(1.0d).build();
mpModelProto
.addVariable(2, k)
.removeConstraint(0);
// x + 7y <= 17.5
final MPConstraintProto c0_0 = this.getFirstConstraint(17.5d);
// x + 7y <= 24.5
final MPConstraintProto c0_1 = this.getFirstConstraint(24.5d);
final MPIndicatorConstraint ic0 = MPIndicatorConstraint.newBuilder()
.setVarIndex(2)
.setVarValue(0)
.setConstraint(c0_0)
.build();
final MPIndicatorConstraint ic1 = MPIndicatorConstraint.newBuilder()
.setVarIndex(2)
.setVarValue(1)
.setConstraint(c0_1)
.build();
mpModelProto
.addGeneralConstraint(MPGeneralConstraintProto.newBuilder().setIndicatorConstraint(ic0).build())
.addGeneralConstraint(MPGeneralConstraintProto.newBuilder().setIndicatorConstraint(ic1).build());
final MPSolutionResponse mpSolutionResponse = this.solve(mpModelProto);
assertEquals(MPSOLVER_OPTIMAL, mpSolutionResponse.getStatus());
assertEquals(33.0d, mpSolutionResponse.getObjectiveValue());
assertEquals(3.0d, mpSolutionResponse.getVariableValue(0));
assertEquals(3.0d, mpSolutionResponse.getVariableValue(1));
assertEquals(1.0d, mpSolutionResponse.getVariableValue(2));
}
MiniZinc 站点 (https://www.minizinc.org/doc-2.5.5/en/solvers.html#indicator-constraints) 指出 MIP SCIP 求解器支持指标约束。
我在 http://google.github.io/or-tools/javadoc/com/google/ortools/linearsolver/MPIndicatorConstraint.html 找到了 MPIndicatorConstraint 文档,但没有与之相关的示例。
C++ 文档还介绍了一个 MPSolverInterface,它有一个 AddIndicatorConstraint 方法,我在 Java 文档 (https://developers.google.com/optimization/reference/linear_solver/linear_solver/MPSolverInterface?hl=en)
中没有找到类似的方法https://github.com/google/or-tools/blob/master/ortools/sat/doc/channeling.md#java-code 提供了 CP 模型的一些示例,但我找不到任何与 MIP 相关的类似应用程序。
是否记录了任何示例?如果没有,是否可以在此线程上分享一个?
根据此 test case,应该可以通过使用原型接口构建模型来使用指标约束。是否有将其移植到 MPSolver 的路线图?
@Test
public void shouldSolveLPWithIndicatorConstraint() {
final MPModelProto.Builder mpModelProto = this.getLinearObjective();
final MPVariableProto k = this.getIntVar("k").setUpperBound(1.0d).build();
mpModelProto
.addVariable(2, k)
.removeConstraint(0);
// x + 7y <= 17.5
final MPConstraintProto c0_0 = this.getFirstConstraint(17.5d);
// x + 7y <= 24.5
final MPConstraintProto c0_1 = this.getFirstConstraint(24.5d);
final MPIndicatorConstraint ic0 = MPIndicatorConstraint.newBuilder()
.setVarIndex(2)
.setVarValue(0)
.setConstraint(c0_0)
.build();
final MPIndicatorConstraint ic1 = MPIndicatorConstraint.newBuilder()
.setVarIndex(2)
.setVarValue(1)
.setConstraint(c0_1)
.build();
mpModelProto
.addGeneralConstraint(MPGeneralConstraintProto.newBuilder().setIndicatorConstraint(ic0).build())
.addGeneralConstraint(MPGeneralConstraintProto.newBuilder().setIndicatorConstraint(ic1).build());
final MPSolutionResponse mpSolutionResponse = this.solve(mpModelProto);
assertEquals(MPSOLVER_OPTIMAL, mpSolutionResponse.getStatus());
assertEquals(33.0d, mpSolutionResponse.getObjectiveValue());
assertEquals(3.0d, mpSolutionResponse.getVariableValue(0));
assertEquals(3.0d, mpSolutionResponse.getVariableValue(1));
assertEquals(1.0d, mpSolutionResponse.getVariableValue(2));
}