0
我想通过列明智建模来解决cplex中的一个简单问题。 这是问题所在,使用Java在Cplex中进行列明智建模
maximize 2x + 3y
subject to x<= 5
y<=2
x,y >=0
这里是我不得不写来解决它的代码:
public static void Model_1() {
try {
//create new model
IloCplex cplex = new IloCplex();
//define variables
IloNumVar x;
IloNumVar y;
IloObjective objective;
objective = cplex.addMaximize();
IloRange cons01;
IloRange cons02;
cons01 = cplex.addRange(0, 5, "c1");
cons02 = cplex.addRange(0, 2, "c1");
IloColumn new_col = cplex.column(objective, 2);
IloColumn new_col2 = cplex.column(objective,3);
new_col = new_col.and(cplex.column(cons01,1));
new_col2 = new_col2.and(cplex.column(cons02,1));
x = cplex.numVar(new_col, 0, Double.MAX_VALUE);
y = cplex.numVar(new_col, 0, Double.MAX_VALUE);
//solve model
if (cplex.solve()) {
System.out.println("obj = "+cplex.getObjValue());
System.out.println("x = "+cplex.getValue(x));
System.out.println("y = "+cplex.getValue(y));
}
else {
System.out.println("Model not solved");
}
cplex.end();
}
catch (IloException exc) {
exc.printStackTrace();
}
}
但我没有得到正确的解决方案。我在编写代码时犯了什么错误?
感谢很多:) – Dipta
嗨@rkersh我不知道我还可以导出偶问题的模型从的Cplex? – Dipta
@Dipta,如果通过Cplex,你的意思是互动,答案是肯定的。 – rkersh