java批量加入约束_java-求解带约束的多元方程-Choco

我想用这样的离散值求解非线性多变量方程:

x*y + z + t - 10 = 0

有约束:

10 < x < 100

等等..

我正在尝试使用Choco库来做,但是我有点迷茫.

我发现此代码:

// 1. Create a Solver

Solver solver = new Solver("my first problem");

// 2. Create variables through the variable factory

IntVar x = VariableFactory.bounded("X", 0, 5, solver);

IntVar y = VariableFactory.bounded("Y", 0, 5, solver);

// 3. Create and post constraints by using constraint factories

solver.post(IntConstraintFactory.arithm(x, "+", y, "

// 4. Define the search strategy

solver.set(IntStrategyFactory.lexico_LB(x, y));

// 5. Launch the resolution process

solver.findSolution();

//6. Print search statistics

Chatterbox.printStatistics(solver);

但我不明白我将方程式放在哪里.

解决方法:

是的,更准确地说,您应该将方程分解为几个约束:

10 < x < 100

变成

solver.post(ICF.arithm(x,">",10));

solver.post(ICF.arithm(x,"

x*y + z + t - 10 = 0

变成

// x*y = a

IntVar a = VF.bounded("x*y",-25,25,solver);

solver.post(ICF.times(x,y,a);

// a+z+t=10

IntVar cst = VF.fixed(10,solver);

solver.post(ICF.sum(new IntVar[]{a,z,t},cst));

最好,

请与我们联系以获取有关Choco Solver的更多支持:www.cosling.com

标签:equation-solving,java,choco

来源: https://codeday.me/bug/20191119/2034220.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值