Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Why does accessing dexpr take so long in OPL script ?

    Posted 09/16/15 04:30 AM

    Originally posted by: ouaigooo


    Hi

    After solving my model, I want to export some results using OPL script.

    I noticed that it takes damned long to process some expressions (dexpr).

    It looks like OPL has to recalculate the expression value.

    Wasn't it already done before (when solving model, since this expression is used by constraints) ?

    Is there a way to accelerate ?

    to force calculating this stuff before ?

     

    You'll find an example below.

    Thanks in advance for your help !

     

    Example:

    ...

    dvar float+ flow1[X1][I][T];
    dexpr float flow[f in X][i in I][o in T] =  (f in X1) ? flow1[f,i,o] :
        sum(x in D: (x.name == f) && (x.field == i) && (x.start < o.stop) && (x.stop > o.start)) x.value*(minl(o.stop, x.stop) - maxl(o.start, x.start)) / (o.stop - o.start);
    ...

    execute {

    for (var t in T) for (i in I) for (x in X) s = s +";"+1000*flow[x][i][t]; // takes really long

    for (var t in T) for (i in I) for (x in X1) s = s +";"+1000*flow1[x][i][t]; // very quick

    ...


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Why does accessing dexpr take so long in OPL script ?

    Posted 09/16/15 11:21 AM

    Hi,

    which cplex version do you use ? (There was some improvement in 12.6.2 on this)

    Can you also try to use flow2 with flow2 defined after the subject to block as

     float flow2[f in X][i in I][o in T] = flow[f][i][o];

    ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Why does accessing dexpr take so long in OPL script ?

    Posted 09/16/15 11:41 AM

    Originally posted by: ouaigooo


    Hi Alex,

    Thanks for your answer.

    12.6.2 (with the hot fix just released)

    It is faster with flow2, indeed.

    There are many workarounds.

    My point is: why is it like this ?

    It is disappointing, annoying, and makes the code ugly.

    What is the rule to observe to avoid this problem ?

    More generally, since the 'ultimate' goal here is to export results in csv files, is there a nice-and-fast way of doing it ?

    i.e. without iterating through all indices

    Thanks a lot


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Why does accessing dexpr take so long in OPL script ?

    Posted 09/16/15 11:54 AM

    Hi,

    dexpr are expressions they are not stored but computed each time you use them.

    So you should either use a dvar or a data array like flow2.

    Have you tried to use a SheetWrite in the .dat to do the data export ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Why does accessing dexpr take so long in OPL script ?

    Posted 09/17/15 02:14 AM

    Originally posted by: ouaigooo


    Not possible to export .xls in this case. Just .csv

    What's more, I experienced slow performance with SheetWrite.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Why does accessing dexpr take so long in OPL script ?

    Posted 09/17/15 05:04 AM

    Hi,

    do you use

    dexpr float flow[f in X][i in I][o in T] =  (f in X1) ? flow1[f,i,o] :
        sum(x in D: (x.name == f) && (x.field == i) && (x.start < o.stop) && (x.stop > o.start)) x.value*(minl(o.stop, x.stop) - maxl(o.start, x.start)) / (o.stop - o.start);

    in your objective or constraints ?

    And why the work around

    float flow2[f in X][i in I][o in T] = flow[f][i][o];

    is not enough for you ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Why does accessing dexpr take so long in OPL script ?

    Posted 09/17/15 05:10 AM

    Originally posted by: ouaigooo


    Hi,

    constraints.

    I mean, it does work with this workaround (actually, I found another one). But I'm getting a little bit sad of workarounds all the time with CPLEX ...

    Anyway, thanks for your help and have a nice day !

    kind regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer