Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Tips & Tricks for Effective and Efficient ILOG Script Code

    Posted 6 days ago

    I have some questions on the best and most efficient way to produce an optimization problem in the ILOG Script programming language, invoking CP Optimizer:

    The structure of the example model is:

    • c = variable1 + variable2
    • d = variable3 + variable4
    • p = c - d
    • p - variable5 = variable6
    • variable2 + variable5 = variable7

    where:

    • variable1 is a model parameter (user-defined value).
    • variable2, variable3, variable4, and variable5 are decision variables.
    • variable2 and variable3 take on values defined in lists of allowable values.
    • variable6 is required to take on one user-defined value.
    • variable7 is the sum of variable2 and variable3, which also needs to equal a value defined in a list of allowable values.

    What is the best way to write these using ILOG Script (eg use of constraints, expr int, dvar int, int)?

    Also, should variable6 be expressed as a constraint or defined as a model parameter?



    ------------------------------
    Stevie Turkington
    ------------------------------


  • 2.  RE: Tips & Tricks for Effective and Efficient ILOG Script Code

    Posted 5 days ago

    Hi,

    no need of ILOG script, you can do that with OPL only:

     using CP;
     int variable1=2;
     int variable6=3;
     dvar int variable2;
     dvar int variable3 ;
     dvar int variable4;
     dvar int variable5;
     dexpr int variable7=variable2+variable3;
     
     dvar int c;
     dvar int d;
     dvar int p;
     
     subject to
     {
       variable2 in {1,2,3,8,10};
        variable3  in {1,2,3,8,10,12};;
     
        c == variable1 + variable2;
        d == variable3 + variable4;
        p == c - d;
        p - variable5 == variable6;
        variable2 + variable5 == variable7;
        
      }    

    works fine

    See some scripting examples I shared to see what OPL scripting is good for



    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------



  • 3.  RE: Tips & Tricks for Effective and Efficient ILOG Script Code

    Posted 4 days ago
    Edited by Stevie Turkington 4 days ago

    Thank you.

    Unfortunately, I am still encountering issues with the validity of calculations.

    I split a long equation into smaller parts, which for some reason gives me more solutions than when it was one big equation (constraints in both instances). This is despite nothing in the objective function changing.

    In fact, I get completely different values for the DVs - and they don't satisfy the (as an eg) int variable6 = 3 parameter.

    The one long equation does, but at the expense of other calculations not actually being what they say they are.

    Is this some kind of bug within the software?

    I double check everything now, given all the problems I've experienced with a solution purporting to be feasible, when in fact it isn't.



    ------------------------------
    Stevie Turkington
    ------------------------------



  • 4.  RE: Tips & Tricks for Effective and Efficient ILOG Script Code

    Posted 4 days ago

    Note: I'm only splitting a long equation into smaller parts to see if I can pinpoint if my double-checking is leading me astray somewhere.

    I ensure even though the equation is over more lines, the result of the previous part merges with the next part. The necessary new variables are declared as decision variables, and aren't added to the objective function. The objective function remains exactly the same between long equations vs split-a-long-equation.



    ------------------------------
    Stevie Turkington
    ------------------------------



  • 5.  RE: Tips & Tricks for Effective and Efficient ILOG Script Code

    Posted 4 days ago

    Hi,

    have you set bounds on all your decision variables ?

    This is quite good to avoid numerical problems with very large values.

    using CP;
    
    dvar int x in 0..10;
    dvar int y in 0..10;
    
    subject to
    {
      ct1:x<=y-2;
      ct2:y<=x-2;
    }

    gives

    infeasible whereas if you remove the bounds you could get some nonsense.

    Can you share the entire model you get issues with ?

    regards



    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------



  • 6.  RE: Tips & Tricks for Effective and Efficient ILOG Script Code

    Posted yesterday

    Hi,

    again if you want other users to have a look, you could share your rentire model and data so that other users could try

    regards



    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------



  • 7.  RE: Tips & Tricks for Effective and Efficient ILOG Script Code

    Posted yesterday
    Edited by Stevie Turkington yesterday

    Hi Alex

    Expanding on my earlier example, is this the most effective and efficient way to code the following optimization problem:

    using CP;
    
    int variable1 = #; 
    int variable6 = #;
    int variable8 = #;
    
    dvar int variable2;
    dvar int variable3;
    dvar int variable4;
    dvar int variable5;
    dvar int d;
    dvar int b;
    dvar int c;
    dvar int p;
    
    dexpr int variable7 = variable4 + variable5;
    
    subject to {
    variable2 in {set of #'s};
    variable3 in {set of #'s};
    variable7 in {set of #'s};
    d in {set of #'s};
    
    b == variable8 + variable7;
    c == variable1 + variable2;
    d == variable3 - variable4;      
    p == c - d;
    p - variable5 == variable6;
    }

    I had accidentally written both variable2 + variable5 = variable7 and variable2 + variable3 = variable7 in my first example.
    The only equation which should apply in that is variable2 + variable3variable7. I have, nonetheless, expanded on the example in this post.



    ------------------------------
    Stevie Turkington
    ------------------------------



  • 8.  RE: Tips & Tricks for Effective and Efficient ILOG Script Code

    Posted 20 hours ago

    Unfortunately, I continue to face difficulties. It is not a matter of "large numbers", the calculations match when I check them apart from one.

    It seems an optimal solution is the values already provided for PLUS whatever number is necessary to "make one line work". However, there is no variable to factor in this "number to make it work". It is not accounted for but is being calculated as if there is that additional variable. This shouldn't be occuring so why is it happening?

    If there is a solution, it should satisfy the constraints. The software should not be adding adhoc numbers to "make it work" and purport to display feasible solutions, because a calculated value isn't what it says it is when you don't factor in whatever the software has decided to add (eg in one line a variable is valued x, but the same variable in another line is calculated on the basis x + "adhoc number").



    ------------------------------
    Stevie Turkington
    ------------------------------