如何使用Google或工具在约束条件中设置差距

时间:2019-12-25 07:54:32

标签: java optimization or-tools mixed-integer-programming

我正在尝试使用Google或工具解决以下问题

minimize f = x1 + x2

有约束条件

x1 = 0 or 100 <= x1 <= 2000
x2 = 0 or 100 <= x2 <= 2000
x1 + 4 * x2 >= 650

哪种求解器最适合此问题?

如何定义这些约束? (我在Java中使用)

我可以用每个变量3个约束来建模(如sascha指出的那样)

x1 >= a1 * 100
x1 <= a1 * 2000
a1 = 0, 1 (binary)

x2 >= a2 * 100
x2 <= a2 * 2000
a2 = 0, 1 (binary)

但是,Solver.makeConstraint()要求约束形式为

L <= c1*x1 + c2*x2
...
MPConstraint ct = solver.makeConstraint(L, infinity);
ct.setCoefficient(x1, c1);
ct.setCoefficient(x2, c2);
...
L,c1和c2必须是数字,而不是其他变量。 就我而言,我想做类似的事情

...
// x1 >= a1 * 100
MPConstraint ct = solver.makeConstraint(a1 * 100, infinity);
ct.setCoefficient(x1, 1);
...

0 个答案:

没有答案