Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Assumption - Assert

    Posted 12/10/18 06:38 PM

    Originally posted by: 88Simon88


    Hello everybody,

     

    I want to add some assumption to my model according to the below article, but it doesn't work for me

    https://www.ibm.com/support/knowledgecenter/SSSA5P_12.8.0/ilog.odms.ide.help/OPL_Studio/opllang_quickref/topics/tlr_opl_assert.html

     

    How can I fix it?

     

    Best


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Assumption - Assert

    Posted 12/11/18 01:35 AM

    Hi

    you seem to mix OPL modeling and OPL scripting

    assert should be  in the modeling part but you wrote that in a scripting block

    regards

    PS: https://www.linkedin.com/pulse/making-decision-optimization-simple-alex-fleischer/


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Assumption - Assert

    Posted 12/11/18 10:15 AM

    Originally posted by: 88Simon88


    Hi,

    Thanks for your help, but how can I use "if-else" in the OPL modeling?

    Best


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Assumption - Assert

    Posted 12/11/18 10:42 AM

    Hi

    int a=1;
    execute
    {
    if (a==2) writeln(2);
    else writeln("Not 2");
    }

    string res=(a==2)?"2":"Not 2";

    execute
    {
    writeln(res);
    }

    gives

    Not 2
    Not 2

    regards

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Assumption - Assert

    Posted 12/11/18 11:23 AM

    Originally posted by: 88Simon88


    Hi,

    It still does not work :(

    Let me explain the assumption one more time:

    According to my data, I have to use an assumption in a conditional method. If the demand for all time periods is less than the "min_volume", the AAC in the data should be greater than the "min_volume". On the other hand, if the demand is not less than the "min_volume" for all time periods, the AAC should be greater than two times of the "min_volume".

    I wrote the above execute for assert but it doesn't work for me. 

    Best


    #DecisionOptimization


  • 6.  Re: Assumption - Assert

    Posted 12/11/18 11:29 AM

    Hi,

    you mix scripting and modeling.

    Let me give you an example

    range r=1..2;

    int a[i in r]=i;

    assert sum(i in r) i<=10;

    execute
    {
    var s=0;
    for(var i in r) s+=a[i];
    if (s>10) fail();
    }

    works fine

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Assumption - Assert

    Posted 12/11/18 12:15 PM

    Originally posted by: 88Simon88


    Thanks Alex for the time you spent.

    I understood what you mean. You said the assert is related to the OPL modeling and not OPL scripting, but how can I write an "if-else" statement in the OPL modeling? Because I have a condition for my assumptions?

    Best


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Assumption - Assert

    Posted 12/11/18 02:02 PM

    You may use the ternary operator in the modeling part

    See

    string res=(a==2)?"2":"Not 2";

    I shared with you previously

     

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Assumption - Assert

    Posted 12/12/18 11:09 AM

    Originally posted by: 88Simon88


    I even tried that and I couldn't do it :(

     


    #DecisionOptimization


  • 10.  Re: Assumption - Assert

    Posted 12/12/18 11:24 AM

    Hi,

    again let me share a tiny example

    range r=1..2;

    int a[i in r]=i;

    assert forall(i in r) as:a[i]<=3;

    and

    range r=1..2;

    int a[i in r]=i;

    assert forall(i in r) as:  if (i<=1) (a[i]<=1); else a[i]>=2;;

    best regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Assumption - Assert

    Posted 12/12/18 11:43 AM

    Originally posted by: 88Simon88


    Thank you so much Alex


    #CPLEXOptimizers
    #DecisionOptimization