冲突优化程序首选项复合

时间:2018-07-11 19:19:47

标签: java preferences linear-programming cplex

据我了解,在CPLEX的ConflictRefiner中,首选项数组应指导该方法找到更理想的冲突集。但是在下面的代码中,无论我如何修改pref数组,每次都将相同的约束(C1,C3)作为冲突集返回,尽管另一个冲突集(C2,C3)对我来说更理想。您能帮助我如何设置首选项以将(C2)和(C3)设置为冲突集吗?

        IloCplex cplex = new IloCplex();
        IloNumVar x = cplex.numVar(0, Double.MAX_VALUE, "x");
        IloNumVar y = cplex.numVar(0, Double.MAX_VALUE, "y");

        IloLinearNumExpr objective = cplex.linearNumExpr();

        objective.addTerm(16 , x);
        objective.addTerm(9, y);

        // Define objective function
        cplex.addMinimize(objective);

        IloRange[] constrtaints = new IloRange[3];
        constrtaints[0] = cplex.addGe(cplex.sum(x,y), 5, "C1");
        constrtaints[1] = cplex.addGe(cplex.sum(x,y), 2, "C2");
        constrtaints[2] = cplex.addLe(cplex.sum(x,y), 1, "C3");

        System.out.println(cplex.toString());

        if (!cplex.solve()) {
            double[] pref = new double[3];
            pref[0] = 2;
            pref[1] = 10;
            pref[2] = 9;

            if (cplex.refineConflict(constrtaints , pref)) {
                IloCplex.ConflictStatus[] conflict = cplex.getConflict(constrtaints);
                for (int c2 = 0; c2 < constrtaints.length; c2++)
                    if (conflict[c2] == IloCplex.ConflictStatus.Member)
                        System.out.println(constrtaints[c2]);
            }
        }   

0 个答案:

没有答案