Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  adding and deleting constraints after importing a model

    Posted 03/30/18 05:34 AM

    Originally posted by: srinit34


    Hi

    I import a model like this:

    cplex = new IloCplex ();
            cplex.importModel(MIP_FILENAME);

     

    if I delete constraints using delete, it works, but not with remove

    IloLPMatrix lpMatrix = (IloLPMatrix)cplex.LPMatrixIterator().next();
            IloRange[] constraints = lpMatrix.getRanges();
            for (IloRange constr: constraints ){
                cplex.delete(constr)   ;
            }

     

    Here is my problem:

    If I try to add a constraint it does not add it to the cplex object, although the return value is okay.

    IloRange  addedConstr =  cplex.addLe(constarintExpression,  bound);   

     

    I recall reading somewhere about editing an imported model (not sure if my usage is correct).

    Please clarify.

     

    I am trying to avoid the effort of creating all the variables by myself and adding them, the objective, and the constraints. I just want to import the model and edit it as I desire.
           


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: adding and deleting constraints after importing a model

    Posted 04/01/18 01:27 PM

    A constraint (a row) in an IloLPMatrix is not directly registered with the IloCplex instance. It is owned by the IloLPMatrix instance. So you should delete it from the IloLPMatrix rather than from the IloCplex instance. Use IloLPMatrix.removeRow() or one of its overloads.

    Using IloCplex.addLe() should work no matter whether you imported a model before or not. How do you determine that it does not work? One easy way to check this is

    1. Assign a name to the constraint (use an overload of addLe() that takes a name argument).
    2. Use IloCplex.exportModel() to export the model to an LP file: cplex.exportModel("model.lp")
    3. Check the LP file (model.lp) to make sure the constraint with the respective name is there.

    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: adding and deleting constraints after importing a model

    Posted 04/01/18 03:16 PM

    Originally posted by: srinit34


    Thank you for comment.

    I did not export the file to verify.

    I believe I was repeating the procedure of getting the LPMatrixIterator, and trying to iterate through the constraints in the cplex object after adding the constraint.

    Note that before adding the constraint I was deleting every other constraint from the cplex object.

    I have changed my code so to verify , I  will have to try it again later.

    Right now I am just editing the constraint in place, instead of deleting it and adding in a new expression .


    #CPLEXOptimizers
    #DecisionOptimization