简体   繁体   中英

Choco Solver setObjective maximize polynominal equation

I'm currently trying out Choco Solver (4.0.8) and I'm trying to solve this equations:

Maximize 8x_1 + 11x_2 + 6x_3 + 4x_4
subject to 5 * x_1 + 7 * x_2 + 4 * x_3 + 3 * x_4≤14
xj∈{0,1} j = 1,... 4。

I'm stuck on maximising the first equation. I guess I just need a hint which subtype of Varaible EQUATION should be.

Model model = new Model("my first problem");

BoolVar x1 = model.boolVar("x1");
BoolVar x2 = model.boolVar("x2");
BoolVar x3 = model.boolVar("x3");
BoolVar x4 = model.boolVar("x4");

BoolVar[] bools = {x1, x2, x3, x4};
int[] c = {5, 7, 4, 3};
int[] c2 = {8, 11, 6, 4};

Variable EQUATION = new Variable();

model.scalar(bools, c, "<=", 14).post();      // 5x1 + 7x2 + 4x3 + 3x4 ≤ 14
model.setObjective(Model.MAXIMIZE, EQUATION); // 8x1 + 11x2 + 6x3 + 4x4

model.getSolver().solve();

System.out.println(x1);
System.out.println(x2);
System.out.println(x3);
System.out.println(x4);

It seems I have found a solution like this:

Variable EQUATION = new ScaleView(x1, 8)
               .add(new ScaleView(x2, 11),
                    new ScaleView(x3, 6),
                    new ScaleView(x4, 4)).intVar();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM