我正在使用SCPSolver在 Java 中制定线性问题。
玩具线性问题:
min x + y
x + 2y >= -1
x - 2y >= -1
可以用java写成:
LinearProgram lp = new LinearProgram(new double[] { 1.0, 1.0 });
lp.addConstraint(new LinearBiggerThanEqualsConstraint(new double[] { 1.0, 2.0 }, -1.0, "c1"));
lp.addConstraint(new LinearBiggerThanEqualsConstraint(new double[] { 1.0, -2.0 }, -1.0, "c2"));
lp.setMinProblem(true);
LinearProgramSolver solver = SolverFactory.newDefault();
double[] sol = solver.solve(lp);
现在添加非负约束x
,y
我可以添加:
lp.addConstraint(new LinearBiggerThanEqualsConstraint(new double[] { 1.0, 0.0 }, 0.0, "c3"));
lp.addConstraint(new LinearBiggerThanEqualsConstraint(new double[] { 0.0, 1.0 }, 0.0, "c4"));
但是是否有一个函数调用来为所有变量添加非负约束?像lp.addAllNonNegativityConstraints()
什么?