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