Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Constructing LPMatrix from existing model

    Posted 07/22/19 04:17 PM

    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


  • 2.  Re: Constructing LPMatrix from existing model

    Posted 07/25/19 05:46 AM

    There is no really easy way to do that. Why do you need to do that?

    I can see these two options:

    1. Construct your model in an IloLPMatrix instance and only add the IloLPMatrix instance in the very end (note that the IloLPMatrix class has an addRows() function that allows adding instances of IloRange, so you don't have to find all the variable indices yourself).
    2. Use IloCplex.iterator() to iterate over the model, collection all the IloNumVar and IloRange instances and construct the matrix that way.

    Note that internally the IloCplex class does not store all constraints/variables in a matrix. The IloLPMatrix is just a "convenience" class that can be used to group a number of linear constraints in a simple way. This is useful when you read files (since you know all constraints at once) but not so useful if you build the model incrementally. Also note that an IloCplex instance can have more than one IloLPMatrix instance.


    #CPLEXOptimizers
    #DecisionOptimization