Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Values in .lp export and model differ from the specified values

    Posted Wed June 10, 2020 03:40 AM
    Hello,

    I am using cplex 12.10 to create and solve a model in Java. The problem is a large MIP. In this model I create a constraint of the following form:

    (-10.0E7*bin(A,B) + 1.0*x(A) - 1.0*x(B)) <= 21.609175078904347​

    bin(A,B) is a binary variable (cplex.boolVar()), while x(A) ad x(B) are numVars (cplex.numVar()). The intention is that either
    • the difference x(A)-x(B) is smaller than 21.609175078904347​ OR
    • bin(A,B) is forced to be set to one, thereby fulfilling this constraint trivially. The sum over all binary variables is minimized, i.e., I want the binary variable to be 0.

    This constraint is created as follows in a class which extends IloCplex:
    IloRange constraint = le(sum(sum(sum(prod(-1, x_b), x_a), -21.609175078904347​), prod(-100000000, bin_a_b)), 0);
    
    System.out.println(constraint);
    add(constraint);

    The System output prints the following line
    IloRange  : -infinity <= (-10.0E7*bin(A,B) + 1.0*x(A) - 1.0*x(B)) <= 21.609175078904347​

    Then I export the model to an .lp file format with the following command (outside of the class, in the class which has access to the IloCplex object):
    my_cplex.exportModel(/path/to/file/location);​


    This creates a file called exported_model.lp. In that file I find the following constraint
    c1789: - x(B) + x(A) - 100000000 bin(A,B) <= 32.1204280114237​

    As you can see the model has changed the number on the right hand side of the constraint from 21.609175078904347 to 32.1204280114237​. This leads to the situation where solutions with a too big difference between x(A) and x(B) are counted as valid solutions.
    I have no explanation for this behavior and am pretty lost, after looking for an error in my model. Is there any cplex behavior which could explain the difference between the console output and the immediately following export of the model?

    Thank you for your help.

                                                                                                                                                                                                                              

    Here is some additional information, which I have gathered in the process of finding an error in this program.

    Between creating the constraint and adding the constraint to the program there are no additional steps.  Further you can see that there is a large number of other constraints in the model, some of which also access x(A) and x(B).

    Between creating the constraint and exporting the model there are also no additional steps. Specifically nothing which changes a constraint. The solving process of the model is not started yet. Cplex does not produce any console output up to the export process. In the export process the following output is created:
    Warning:  Output names have been modified due to duplicate names or characters invalid in LP format.
    Default row names c1, c2 ... being created.​


    When solving the model, it produces the following output:

    Version identifier: 12.10.0.0 | 2019-11-26 | 843d4de
    CPXPARAM_Threads                                 1
    Tried aggregator 4 times.
    MIP Presolve eliminated 407 rows and 11 columns.
    MIP Presolve modified 407 coefficients.
    Aggregator did 231 substitutions.
    Reduced MIP has 22748 rows, 7425 columns, and 59455 nonzeros.
    Reduced MIP has 3608 binaries, 0 generals, 0 SOSs, and 0 indicators.
    Presolve time = 0.05 sec. (40.90 ticks)
    Probing time = 0.01 sec. (1.07 ticks)
    Tried aggregator 1 time.
    Detecting symmetries...
    Reduced MIP has 22748 rows, 7425 columns, and 59455 nonzeros.
    Reduced MIP has 3608 binaries, 0 generals, 0 SOSs, and 0 indicators.
    Presolve time = 0.04 sec. (23.18 ticks)
    Probing time = 0.00 sec. (1.06 ticks)
    MIP emphasis: balance optimality and feasibility.
    MIP search method: dynamic search.
    Parallel mode: none, using 1 thread.
    Root relaxation solution time = 1.14 sec. (1370.27 ticks)
    
            Nodes                                         Cuts/
       Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap
    
    *     0     0      integral     0       22.0008       22.0008    18591   -0.00%
    Elapsed time = 1.40 sec. (1541.95 ticks, tree = 0.00 MB, solutions = 1)
    
    Root node processing (before b&c):
      Real time             =    1.40 sec. (1542.17 ticks)
    Sequential b&c:
      Real time             =    0.00 sec. (0.00 ticks)
                              ------------
    Total (root+branch&cut) =    1.40 sec. (1542.17 ticks)
    Solution for model found!
    


    ------------------------------
    Soeren Nickel
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Values in .lp export and model differ from the specified values

    Posted Wed June 10, 2020 03:59 AM
    I wonder whether you are looking at the right constraint in the generated LP file. I extracted your code and the following produces the expected results:
    import ilog.cplex.IloCplex;
    import ilog.concert.IloRange;
    import ilog.concert.IloException;
    import ilog.concert.IloNumVar;
    
    public final class Wrong {
       public static void main(String[] args) throws IloException {
          final IloCplex cplex = new IloCplex();
          try {
             IloNumVar x_a = cplex.numVar(0.0, Double.POSITIVE_INFINITY, "x(A)");
             IloNumVar x_b = cplex.numVar(0.0, Double.POSITIVE_INFINITY, "x(B)");
             IloNumVar bin_a_b = cplex.boolVar("bin(A,B)");
             IloRange r = cplex.le(
                                   cplex.sum(
                                             cplex.sum(
                                                       cplex.sum(
                                                                 cplex.prod(-1, x_b), x_a),
                                                       -21.609175078904347),
                                             cplex.prod(-100000000, bin_a_b)), 0);
             r.setName("constraint");
             System.out.println(r);
             cplex.add(r);
             cplex.exportModel("wrong.lp");
          }
          finally {
             cplex.end();
          }
       }
    }

    The exported LP file is
    Minimize
    obj1:
    Subject To
    constraint: - 100000000 bin(A,B) - x(B) + x(A) <= 21.6091750789043
    Bounds
    0 <= bin(A,B) <= 1
    Binaries
    bin(A,B)
    End

    Can you try to explicitly name your constraints in the Java code (using setName()) and double check that you are looking at the correct constraint. If the problem persists, can you extract a minimal code to reproduce the issue and post that here?

    In any case, these big-M constraints are asking for trouble. You may be better off using logical/indicator constraints, see the IloCplex.ifThen() function.

    ------------------------------
    Daniel Junglas
    ------------------------------



  • 3.  RE: Values in .lp export and model differ from the specified values

    Posted Wed June 10, 2020 12:41 PM
    I was looking at the correct constraint, however I could not figure out what has changed the value there in after all. This specific problem did not persist after resetting my code to an older version, which means it must have been a change somewhere in the code which had some side effects.

    However: Your suggestion to switch from big-M constraints to IloCplex.ifThen() constraints fixed another problem in my project and made the code more legible at the same time. Thank you for this suggestion and your quick answer!

    ------------------------------
    Soeren Nickel
    ------------------------------