Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Activate part of OPL code

  • 1.  Activate part of OPL code

    Posted 08/23/16 07:20 AM

    Originally posted by: StephenHall


    Hi guys,

     

    What would you recommend to activate part of the preprocessing.

    The "if" statement is only valid for the constraint or in the OPL script". But not in OPL itself.

     

    The problem is the following, For a model i have 2 ways of populating it:

    1. from a Database. The preprocessing is done in OPL. The database connection is defined in the .dat
    2. from Database. The preprocessing is done in OPL. The database connection is defined in the ODMapp
    3. from Java calling OPLrun. There the preprocessing is done in Java because it is faster and more convenient.

    What would be your recommendations to handle multiple model variation from the pre and post processing viewpoint?

     

    my thought:

    • call a "include" statement with different .mod. COuld be to assign a string variable the name of the .mod to call from a OPLScript with "if" statement
    • use a if statement in .dat if possible

    Thank you for your help


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Activate part of OPL code

    Posted 08/23/16 08:17 AM

    Hi,

    as far as I know you cannot do if condition include so what I would do is include .mod files that I would set in order to include one file or another.

    Let me give you an example:

    pre1.mod

    int a=1;

    pre2.mod

    int a=2;

    post1.mod

    execute
    {
    writeln("post1");
    }

    post2.mod

    execute
    {
    writeln("post2");
    }

    then the model main.mod

    execute
    {
    var pre=new IloOplOutputFile("pre.mod");
    pre.writeln("include \"pre2.mod\";");
    pre.close();

    var post=new IloOplOutputFile("post.mod");
    post.writeln("include \"post1.mod\";");
    post.close();
    }


    include "pre.mod";
     
    dvar int x;
    subject to
    {
    x==a;
    }
     
    execute
    {
    writeln("pre",x);
    }

    include "post.mod";

    will give

    pre2
    post1

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer