Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How to call an external program from OPL ?

    Posted 12/15/17 06:54 AM

    Hi,

    I often got the question : how can we call an external program from OPL ?

    ( In order to launch some visualization, reporting, or any other program)

    Up to CPLEX 12.7.1 my answer was :

    Use an external java call. See IloOplCallJava

    But some people do not use java but C# or simply need to call a program and that's it.

    In CPLEX 12.8, we have IloOplExec

    And this is very useful.

    Let me share a small example:

    I use Windows but this works for all platforms.

    In C: you have volsay.mod

    dvar float+ Gas;
    dvar float+ Chloride;


    maximize
      40 * Gas + 50 * Chloride;
    subject to {
      ctMaxTotal:     
        Gas + Chloride <= 50;
      ctMaxTotal2:    
        3 * Gas + 4 * Chloride <= 180;
      ctMaxChloride:  
        Chloride <= 40;
    }

    tuple SolutionT{
        float Gas;
        float Chloride;
    };
    {SolutionT} Solution = {<Gas,Chloride>};
    execute{
    var o=new IloOplOutputFile("output.txt");
        o.writeln(Solution);
    o.close();
    }

    and then you may call example.mod

    execute
    {
    // call notepad

    IloOplExec("c:\\Windows\\System32\\notepad.exe");

    // call OPL
    IloOplExec("C:\\ILOG\\CPLEX_Studio128\\opl\\bin\\x64_win64\\oplrun.exe c:/volsay.mod",true);

    // display the result by importing output.txt
    writeln("result");
    var f=new IloOplInputFile("c:/output.txt");
    while (!f.eof) {
          s=f.readline();
          writeln(s);
         }

    f.close();
    }

    which will open notepad and then give

    result
     {<20 30>}

    regards

     

    Alex Fleischer

    PS:

    Many how to with OPL at https://www.linkedin.com/pulse/how-opl-alex-fleischer/

    Many examples from a very good book : https://www.linkedin.com/pulse/model-building-oplcplex-alex-fleischer/

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

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: How to call an external program from OPL ?

    Posted 01/28/18 12:07 PM

    Originally posted by: AMM1


    hello mr Alex,

    how to call  an external program from OPL CPLEX 12.7 OPL model ?

    because its giving me an error that  IloOplExec does not exist on OPL model

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: How to call an external program from OPL ?

    Posted 01/28/18 01:24 PM

    Hi,

    indeed IloOplExec is a new feature in CPLEX 12.8

    regards
     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: How to call an external program from OPL ?

    Posted 01/28/18 04:21 PM

    Originally posted by: AMM1


    hi mr alex

    thank you for your reply but how to call an external program on CPLEX 12.7


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: How to call an external program from OPL ?

    Posted 01/28/18 04:46 PM

    Hi

    have a look at IloOplCallJava

    But do not hesitate to try 12.8

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: How to call an external program from OPL ?

    Posted 04/09/19 07:14 PM

    Originally posted by: K__U


    Hi Alex,

    I tried the IloOplExec, and it is great specifically running parallel or multiple serial instances. 

    However, I have a problem when I run the code. I don't see any command screen displaying anything from the current running -oplrun.

    (Nothing like an engine output to see the progress of the model). I can only use the task manager to see if the model is still running or not.

    (and also the post process outputs csv or txt)

     

    Is there a way to access the command prompt to see the model progress if we use IloOplExec ?

    Thanks,


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: How to call an external program from OPL ?

    Posted 04/10/19 05:29 AM

    Hi,

    instead of calling a model you could call a project

    IloOplExec("C:\\ILOG\\CPLEX_Studio129\\opl\\bin\\x64_win64\\oplrun.exe  -p c:/volsay ",true);

    and in that project you may use a .ops file (settings) with a set engine log

    or you may rely on https://www.ibm.com/developerworks/community/forums/html/topic?id=e1e2e964-93cb-440e-842b-5c360aa3450e&ps=25

    regards

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: How to call an external program from OPL ?

    Posted 11/21/19 01:01 AM

    Originally posted by: k_ka


    Hi Alex,

    Is this possible with CPLEX12.9?
    You can run it on CPLEX12.8 installed on the same PC,
    IloOplExec does not work properly with CPLEX12.9.

     

    For example
    If you write as follows, "notepad.exe" is executed only once.
    (In CPLEX12.8, it is executed twice.)
    Once executed, the process does not stop and must be stopped manually.

     

    execute {
      IloOplExec ("C: \\ Windows \\ System32 \\ notepad.exe");
      IloOplExec ("C: \\ Windows \\ System32 \\ notepad.exe");
      }

     

    Please tell me if you know the cause.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: How to call an external program from OPL ?

    Posted 11/21/19 02:32 AM


  • 10.  Re: How to call an external program from OPL ?

    Posted 11/22/19 12:00 AM

    Originally posted by: k_ka


    hi

    Thank you for your reply.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer