Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Opl extraction error

    Posted 07/20/19 10:44 PM

    Originally posted by: guvenc


    Hi all,

    I have a mathematical model. You can see a small section from it below. This section leads to some interesting behavioral difference when I write a constraint in two different ways. 

    Could you please enlighten me about the behavioural difference of seemingly same constraints?

     

    tuple rjt { string r; string j; float t; }

    tuple rpjt { string r; string p; string j; float t; }

    {rjt} RJT = ...;
    {rpjt} RPJT = ...;

    float Y[RPJT] = ...;

    dvar float+ X[RJT];

    minimize X;

    //Alternative 1

    subject to

    {

    forall (rjt in RJT)

    X[rjt] == sum(rpjt in RPJT) Y[<rjt.r,rpjt.p,rjt.j,rjt.t>];

    }

    //Alternative 2

    subject to

    {

    forall (rjt in RJT)

    X[rjt] == sum(rpjt in RPJT: rpjt.r == rjt.r && rpjt.j == rjt.j && rpjt.t == rjt.t) Y[rpjt];

    }

    Alternative 1 leads to an "CPLEX cannot extract expression" error.

    Alternative 2 works and lead to an optimal solution.

    What am I missing? Are those alternatives not the same thing?

     

    Thank you in advance.

    Guvenc

     

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Opl extraction error

    Posted 07/21/19 02:38 AM

    Hi,

    for alternative 1 I would write

    forall (<r,j,t> in RJT)

    X[<r,j,t>] == sum(<r,p,j,t> in RPJT) Y[<r,p,j,t>];

    because with your way you do a full Euclidian product and you could get errors

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Opl extraction error

    Posted 07/21/19 03:36 AM

    Originally posted by: guvenc


    Hi Alex,

    I tested your suggestion for Alternative 1 and gives the same result as Alternative 2.

    What do you mean by a full Euclidian Product? (the length of RJT and RPJT is not equal.)

    I am confused how the following expressions affect the calculations.

    forall (rjt in RJT)

    forall (<r,j,t> in RJT)

     

    Another question:

    forall (<r,j,t> in RJT) // How does the equality of r,j,t here

    X[<r,j,t>]

    == sum(<r,p,j,t> in RPJT) Y[<r,p,j,t>]; // and r,j,t here is ensured? 

    Should not it be written like 

    forall (<r1,j1,t1> in RJT)
    X[<r1,j1,t1>] == sum(<r2,p,j2,t2> in RPJT: r1 ==r2 && j1==j2 && t1==t2) Y[<r1,p,j1,t1>];

     

    Are those all the same as Alternative 2? Is Alternative 2 a good way to deal with tuples as well?

     

    Thank you for your first anser. It is very usefull. 

    Regards

    Guvenc

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Opl extraction error

    Posted 07/21/19 03:53 AM

    Hi

    see explicit vs implicit slicing at https://www.ibm.com/support/knowledgecenter/SSSA5P_12.9.0/ilog.odms.ide.help/OPL_Studio/opllangref/topics/opl_langref_formalParams_filtering.html

    Alternative 1 and 2 should behave the same. Some prefer alternative 1, others prefer alternative 2

    In

    forall (rjt in RJT)

    X[rjt] == sum(rpjt in RPJT) Y[<rjt.r,rpjt.p,rjt.j,rjt.t>];

    you could have some rjt in RJT with some p with <rjt.r,rpjt.p,rjt.j,rjt.t> not in the set.

    If you changed that into

    forall (rjt in RJT)

    X[rjt] == sum(rpjt in RPJT:<rjt.r,rpjt.p,rjt.j,rjt.t> in RPJT) Y[<rjt.r,rpjt.p,rjt.j,rjt.t>];

    you would not get that error.

    regards

     

    https://medium.com/@alexfleischer_84755/optimization-simply-do-more-with-less-zoo-buses-and-kids-66940178db6

     

     

     

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Opl extraction error

    Posted 07/21/19 04:09 AM

    Originally posted by: guvenc


    Thank you. Great help Alex

    Regards.


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Opl extraction error

    Posted 07/21/19 04:54 AM

    Originally posted by: guvenc


    Hi Alex,

     

    The following:

          forall (rjt in RJT)

              X[rjt] == sum(rpjt in RPJT:<rjt.r,rpjt.p,rjt.j,rjt.t> in RPJT) Y[<rjt.r,rpjt.p,rjt.j,rjt.t>];

    does not give an objective value that I expect. It gives like a 10 times larger objective function value weirdly. 

    I also tried 

          forall (rjt in RJT)
              X[rjt] == sum(rpjt in RPJT: <rjt.r,rpjt.p,rjt.j,rjt.t> in RPJT) Y[rpjt]; 

    too, just to see what happens, and this one gives approx 4 times large objective function value as well. Both wrong ofcourse.

    If you are still keen to help me out, I wonder your input about wrong equations.

     

    Nonetheless, I think I will stick to one of the following


        forall (rjt in RJT)
           
    X[rjt] == sum(rpjt in RPJT: rpjt.r == rjt.r && rpjt.j == rjt.j && rpjt.t == rjt.t) Y[rpjt]; //Alternative 2


        forall (<r,j,t> in RJT)
            X[<r,j,t>] == sum(<r,p,j,t> in RPJT) Y[<r,p,j,t>];// Your reply behaving correctly

        forall (<r1,j1,t1> in RJT)
            X[<r1,j1,t1>] == sum(<r2,p,j2,t2> in RPJT: r1 ==r2 && j1==j2 && t1==t2) Y[<r1,p,j1,t1>];// Thank you once again for direction "Implicit and Explicit   

                  Slicing https://www.ibm.com/support/knowledgecenter/SSSA5P_12.9.0/ilog.odms.ide.help/OPL_Studio/opllangref/topics/opl_langref_formalParams_filtering.html"

    Regards,

    Guvenc


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Opl extraction error

    Posted 07/21/19 05:02 AM

    Hi,

    forall (rjt in RJT)

    X[rjt] == sum(rpjt in RPJT:<rjt.r,rpjt.p,rjt.j,rjt.t> in RPJT) Y[<rjt.r,rpjt.p,rjt.j,rjt.t>];

     

    I provided you was not a fix but a way to show you what your previous formula led to an error. You count too many elements that way. That s why you need slicing. What I gave you is not slicing but a protection against errors.

    forall (<r,j,t> in RJT)

    X[<r,j,t>] == sum(<r,p,j,t> in RPJT) Y[<r,p,j,t>];

     

    is what you should write

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Opl extraction error

    Posted 07/21/19 06:25 AM

    Originally posted by: guvenc


    Hi

    Yes one of following works fine.

        forall (rjt in RJT)
           
    X[rjt] == sum(rpjt in RPJT: rpjt.r == rjt.r && rpjt.j == rjt.j && rpjt.t == rjt.t) Y[rpjt];


        forall (<r,j,t> in RJT)
            X[<r,j,t>] == sum(<r,p,j,t> in RPJT) Y[<r,p,j,t>];

        forall (<r1,j1,t1> in RJT)
            X[<r1,j1,t1>] == sum(<r2,p,j2,t2> in RPJT: r1 ==r2 && j1==j2 && t1==t2) Y[<r1,p,j1,t1>];

     

    Thank you Alex,

    Regards


    #CPLEXOptimizers
    #DecisionOptimization