Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

OR constraint

  • 1.  OR constraint

    Posted 05/25/11 11:33 AM

    Originally posted by: banun


    Hi,

    Is this the right way to tell the cplex: var_y>=X OR var_y<=Y ??
    model.add(        (var_y >= X) +
     (var_y <= Y)  >= 1 );
    


    It seems that this way causes some problems to my project..
    Is there another way to write an OR constraint ?
    Thanks
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: OR constraint

    Posted 05/25/11 12:01 PM

    Originally posted by: SystemAdmin


    CPLEX will internally create some auxiliary binary variables to model all elements of your constraint, and it could very well be that even after presolve this representation is not the best approach.

    I would model this explicitly using one additional binary variable and two indicator constraints:
    var_z = 1 -> vary >= X
    var_z = 0 -> vary <= Y
    

    Tobias
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: OR constraint

    Posted 05/25/11 02:16 PM

    Originally posted by: banun


    sorry, I don't understand..

    Can I get some more details about your idea ?
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: OR constraint

    Posted 05/25/11 04:15 PM

    Originally posted by: banun


    I did :

    
    IloBoolVar XL((var_x <= X)); IloBoolVar YU((var_y >= Y)); model.add(     YU + XL >=1 );
    


    It compiles, but it seems that without those "OR constraints" my program runs without any exceptions, and when I add those constraints (together other previous constrains) I get an exception
    
    'IloCplex::Exception'
    
    which occures during
    
    solver.getValue(var_id)
    
    ..

    What might be the reason for that ?
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: OR constraint

    Posted 05/26/11 01:57 AM

    Originally posted by: SystemAdmin


    Can you please print out the exception message and post it here:
    try {
       // Code that throws the exception:
       solver.getValue(var_id);
    } catch (IloException& e) {
       std::cerr << "Exception: " << e << std::endl;
    }
    

    There are several potential reasons for this exception, including
    • Variable 'var_id' does not appear in any constraint or the objective function. In this case the solver has no value for that variable and will throw an exception.
    • The model has no solution at all (did solver.solve() return true?). In this case it will throw an exception every time you call solver.getValue().

    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: OR constraint

    Posted 05/26/11 03:33 AM

    Originally posted by: banun


    I got
    Exception: CPLEX Error  1217: No solution exists.
    


    this can happen in, for example, I define :

    model.add(X>10);
    model.add(X<5);

    right ? (so there is something wrong with my constrains)
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: OR constraint

    Posted 05/26/11 03:38 AM

    Originally posted by: SystemAdmin


    First of all, you should use '<=' and '>=' instead of '<'<'.
    If you get "No solution exists" then solver.solve() did return false, correct?
    This means probably means that your problem is infeasible. So either your constraints or your data is wrong. To assess that I would proceed as follows:
    • Before doing solver.solve() do solver.exportModel("model.sav");
    • Use the interactive optimizer to analyze the conflict by typing the following input to the interactive:
    read model.sav
    optimize
    conflict
    display conflict all
    

    This will show you a set of constraints/bounds that render your model infeasible.

    Alternatively, you can export the model to an LP file (solver.exportModel("model.lp")) and look at this file directly.
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: OR constraint

    Posted 05/26/11 04:45 AM

    Originally posted by: banun


    Hoe do I use interactive optimizer ? do I need to install something for that ?

    How can I open *.sav file ?
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: OR constraint

    Posted 05/26/11 08:00 AM

    Originally posted by: SystemAdmin


    The interactive optimizer is installed when you install CPLEX. It is somewhere in the bin-directory of your installation. On Windows it is called cplex.exe, on other platforms just cplex.
    A .sav file is a binary description of a model. It is not human-readable, hence there is no point in "opening" it. You can do
    read model.sav
    display problem all
    

    in the interactive optimizer to read in the model and then show it. Or you can do
    solver.importModel(model, "model.sav");
    

    in C++ to read in a model that is stored in a .sav file.
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: OR constraint

    Posted 05/26/11 08:38 AM

    Originally posted by: banun


    ok, so I got to the interactive optimizer, and got :

    CPLEX> read model.sav
    Problem 'model.sav' read.
    Read time =    0.03 sec.
    CPLEX> optimize
    Presolve time =    0.00 sec.
     
     
    MIP - Integer infeasible.
    Current MIP best bound is infinite.
    Solution time =    0.01 sec.  Iterations = 0  Nodes = 0
     
    CPLEX> conflict
     
    Refine conflict on 787 members...
     
     Iteration  Max Members  Min Members
             1          781            0
             2          780            0
             3          731            0
             4          707            0
             5          701            0
             6          700            0
             7          612            0
             8          591            0
             9          589            0
            10          516            0
            11          480            0
            12          462            0
            13          453            0
            14            6            0
    CPLEX Error  1016: Restricted version.  Problem size limits exceeded.
    Failed to compute conflict.
    CPLEX> display conflict all
    No conflict exists.
    CPLEX>
    


    What does that mean ?
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: OR constraint

    Posted 05/26/11 08:47 AM

    Originally posted by: SystemAdmin


    It means that you are using a license that has a problem size limit installed.
    What kind of license are you using? Is this some kind of eval license?
    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: OR constraint

    Posted 05/26/11 08:59 AM

    Originally posted by: banun


    I don't know how to find the kind of license i'm using,
    but I downloaded cplex from here (i'm a student)

    http://www-01.ibm.com/software/websphere/products/optimization/cplex-studio-preview-edition/
    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: OR constraint

    Posted 05/26/11 09:05 AM

    Originally posted by: SystemAdmin


    OK, seems like you are using a preview/trial edition which has limits for the problem size.
    As a student you probably qualify for an academic license that has no restrictions.
    Please see this announcement in this Forum to find details about the academic initiative.

    If you want to do something with your current license then your only chance is to reduce your problem size. Remove any constraints that do not affect the feasibility of the problem and see if you can get the problem small enough so that the conflict refiner works with the problem.
    #CPLEXOptimizers
    #DecisionOptimization


  • 14.  Re: OR constraint

    Posted 05/26/11 02:03 AM

    Originally posted by: SystemAdmin


    What Tobias meant by
    var_z = 1 -> vary >= X
    var_z = 0 -> vary <= Y
    

    was to create two indicator constraints. One constraint that says "if var_z=1 then vary>=X must hold" and one that says "if var_z=0 then vary<=Y must hold". In the C++ API constraints like this can be formulated using IloIfThen.
    If you use indicator constraints and export the model to an LP file then you will see that they are written in the same way as Tobias specified them.
    #CPLEXOptimizers
    #DecisionOptimization