Originally posted by: JorisK
Given an integer linear program which is constructed by adding variables and constraints directly to an IloCplex instance. What is the most convenient way to extract an IloLPMatrix instance from the IloCplex instance containing all the constraints?
Something like this works:
IloCplex cplex=...;
//Add variables and constaints
...
//Write model to file and re-import
cplex.exportModel("model.lp");
cplex.readModel("model.lp");
IloLPMatrix lpMatrix=(IloLPMatrix)cplex.LPMatrixIterator().next();
From the documentation of IloCplex.readModel:
When CPLEX reads a file, the existing active model is first cleaned out and then new modeling objects, as specified by the input file, are added to it. In particular, one IloObjectiveobject and one IloLPMatrix object are always added to the active model.
This method is not very clean, as the original model (and variable references) is lost when re-importing the model.
#CPLEXOptimizers#DecisionOptimization