【问题标题】:OR-Tools / SCIP - How to use Indicator Constraints for MIP problems?OR-Tools / SCIP - 如何使用指标约束来解决 MIP 问题?
【发布时间】:2021-08-28 00:00:07
【问题描述】:

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 相关的类似应用程序。

是否有任何示例记录在案?如果没有,是否可以在此线程上分享一个?

【问题讨论】:

    标签: java or-tools scip


    【解决方案1】:

    根据test case,应该可以通过使用 proto 接口构建模型来使用指标约束。是否有将其移植到 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));
        }
    

    【讨论】:

    • 同一测试用例包括目标函数的二次项示例
    • 将其移植到 MP 求解器目前不在我们的计划中。
    猜你喜欢
    • 2019-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多