[英]How can i put an experiession to minimize using choco solver?
我使用 choco 求解器 2.1.5 版,我想体验一下以最小化我的变量总和。 我怎么能这样做?
也许你从 sourceforge 下载了那个版本:在那里,我们建议访问http://choco-solver.org ,我们可以在那里下载更多最新版本。
With the more recent version 4.10.7, released on Oct 11 2021,
you may experiment with something like this:
Model model = new Model();
IntVar x = model.intVar("x", 3, 10, false);
IntVar y = model.intVar("y", 2, 20, false);
IntVar sum = model.intVar("sum", 1, 50, false);
model.arithm(x, "+", y, "=", sum).post();
Solver solver = model.getSolver();
model.setObjective(Model.MINIMIZE, sum);
while (solver.solve()) {
System.out.println(" x = " + x.getValue());
System.out.println(" y = " + y.getValue());
System.out.println(" sum = " + sum.getValue());
}
It will print:
x = 3
y = 2
sum = 5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.