【问题标题】:Choco Solver setObjective maximize polynominal equationChoco Solver set Objective 最大化多项式方程
【发布时间】:2019-06-06 00:47:18
【问题描述】:

我目前正在试用 Choco Solver (4.0.8),我正在尝试求解这个方程:

最大化

为准

我坚持最大化第一个方程。我想我只需要提示 Varaible EQUATION 应该是哪个子类型。

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);

【问题讨论】:

    标签: java choco


    【解决方案1】:

    我好像找到了这样的解决方案:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多