Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Bug in OPL Script?

    Posted 01/19/11 06:14 PM

    Originally posted by: JamesNeuf


    I seem to get this very strange bug when using OPL script to set the values of an array. Here is the stripped-down code:

    test.dat:

    varIn = [0 0 0];

    test.mod:

    string period[0..3];

    execute setPeriod {
    for(var i=0; i<=3; i++) {
    if (i >= 1) period[i] = "A";
    else period[i] = "B";
    }
    }

    {int} rng1 = union(s in 0..3 : period[s] != "B") {s};
    {int} rng2 = union(s in 0..3 : period[s] != "B") {s};

    int varIn[rng1] = ...;

    execute {

    writeln(period);
    writeln(rng1);
    writeln(rng2);
    writeln(varIn);

    }

    > oplrun test.mod test.dat

    IBM ILOG License Manager: "IBM ILOG Optimization Suite for Academic Initiative" is accessing CPLEX 12 with option(s): "e m b q ".
    ["B" "A" "A" "A"]
    {0 1 2 3}
    {1 2 3}
    [0 0 0 0]
    What that output should look like:
    ["B" "A" "A" "A"]
    {0 1 2}
    {1 2 3}
    [0 0 0]

    What is weird is that the "rng1" set changes elements because it is used when reading in a variable! Any ideas?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Bug in OPL Script?

    Posted 01/19/11 06:24 PM

    Originally posted by: JamesNeuf


    Correction:

    What that output should look like:

    {1 2 3}
    {1 2 3}
    0 0 0
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Bug in OPL Script?

    Posted 01/19/11 09:29 PM

    Originally posted by: SystemAdmin


    This indeed seems like a bug. Workaround would be to initialize "period" as below instead of using a script.
    string period[i in 0..3] = (i > 0) ? "A" : "B";
    


    Alternatively, if 'varIn' is initialized internally then also it would work fine. Issue seems to be that 'setPeriod' script is not getting executed when "external" data 'varIn' is initialized.

    You may also want to check this section in documentation that describes difference between external and internal initializations:
    IDE and OPL > Optimization Programming Language (OPL) > Language Reference Manual > OPL, the modeling language > Data sources > Data initialization

    Regards,
    Faisal
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Bug in OPL Script?

    Posted 01/19/11 11:55 PM

    Originally posted by: JamesNeuf


    Unfortunately that work-around doesn't work for me as I actually have a more complex script which I am using to set the "period" array, and it depends on some other inputs read from the .dat files. I really just need some way to invoke a procedural programming language to set specific variables in OPL, it's clear the javascript was intended to do that, it just doesn't work.

    Right now my work-around is to invoke a half script just to set the period array, then output it to a period.dat file. Then I load in period.dat and use it as I normally would. It's obviously not ideal, but at least it works.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer