根据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));
}