代码之家  ›  专栏  ›  技术社区  ›  DerMolly

COOCO求解器目标最大化多项式方程

  •  0
  • DerMolly  · 技术社区  · 8 年前

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

    最大化
    服从
    我坚持最大化第一个等式。我想我只需要一个提示,Varaible 方程的哪个子类型应该是

    BoolVar x1=型号.BoolVar(“x1”); BoolVar x2=model.BoolVar(“x2”); BoolVar x4=型号.BoolVar(“x4”); int[]c={5,7,4,3}; int[]c2={8,11,6,4}; 变量方程=新变量(); model.scalar(bools,c,“<=”,14).post();//5x1+7x2+4x3+3x4¥14 model.setObjective(model.MAXIMIZE,等式);//8x1+11x2+6x3+4x4 model.getSolver().solve(); 系统输出打印行(x2); 系统输出打印行(x4); 从属于 5*x_1 + 7*x_2 + 4*x_3 + 3*x_4 ≤ 14
    xj ∈ {0, 1} j = 1,... 4.

    我坚持最大化第一个等式。我想我只需要一个提示 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);
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   DerMolly    7 年前

    看来我找到了这样的解决方案:

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