Originally posted by: nr83
I don't think the problem is the extraction, because is actually the extraction that makes the program working properly.
The problem is that if I don't extract the model in a text file and then import it in a IloCplex object, the program seems to work as a different one, i.e., as it would not have all the constraints I generated before calling model.slve().
The constraints are generated with the methods IloCplex.Ge(), IloCplex.Le() and IloCplex.Eq().
I tried to solve a very simple linear program and it works, but with big programs I need to do the trick "export and import" otherwise it does not work as expected.
below part of the code I use to build objective function and constraints
final IloCplex cplex = new IloCplex();
IloIntVar xVar;
IloIntVar zVar;
IloIntVar qVar;
final IloLinearIntExpr objective = cplex.linearIntExpr();
final List<IloIntExpr> sumXvars18 = new ArrayList<IloIntExpr>();
final List<IloIntExpr> sumZvars17_bs = new ArrayList<IloIntExpr>();
for(final Resource r : resources)
{
final String id = r.getId();
xVar = cplex.boolVar("x"+id);
objective.addTerm(r.getEC(), xVar);//objective function
sumXvars18.add(cplex.prod(r.getCost(), xVar));//c18 sum
for(final Location l : r.getDom())
{
zVar = cplex.boolVar("z"+l.getId()+id);
cplex.addEq(cplex.diff(zVar, xVar), 0);//c5
sumZvars17_bs.add(zVar);
}
int type = r.getType();
if(type==3 || type==4)
for(final Node n : r.getNodes())
{
qVar = cplex.boolVar("q"+n.getLocation().getId());
zVar = cplex.boolVar("z"+n.getLocation().getId()+r.getId());
cplex.addLe(cplex.sum(zVar, qVar), 1);//c16
}
}
//convert the List<IloIntExpr> into an array IloIntExpr[]
IloIntExpr[] sumZvarsArray_bs = sumZvars17_bs.toArray(new IloIntExpr[sumZvars17_bs.size()]);
cplex.addGe(cplex.sum(sumZvarsArray_bs), res.keySet().size());//c17
cplex.addMinimize(objective);//objective function
IloIntExpr[] sumXvarsArray = sumXvars18.toArray(new IloIntExpr[sumXvars18.size()]);
cplex.addLe(cplex.sum(sumXvarsArray), 100);//c18
#CPLEXOptimizers#DecisionOptimization