Decision Optimization

Decision Optimization

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

 View Only
  • 1.  interactive CPO

    Posted Mon March 09, 2015 02:29 PM

    Originally posted by: DavidGravot


    I find interesting to read/write files with cpo extension. Is it only available through APIs or is there a command line to read / write .cpo files ? (similarly to CPLEX interactive optimizer) ?


    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: interactive CPO

    Posted Tue March 10, 2015 06:01 AM

    Originally posted by: rdumeur


    Dear David,

    There is  no interactive interpreter for CPO so you have to use the API to dump  model from your C++ code.

    The cpoptimizer/examples/src/cpp/cpofileformat.cpo example illustrates this approach :

    const char* Names[] = {"blue", "white", "yellow", "green"};
    
    void createModel(const char* filename) {
      IloEnv env;
      try {
        IloModel model(env);
        // Macros ILOSETLOCATION and ILOADD store current source file location.
        // Thanks to that locations will be included in the generated file.
        IloIntVar Belgium(env, 0, 3, "Belgium");         ILOSETLOCATION(Belgium);
        IloIntVar Denmark(env, 0, 3, "Denmark");         ILOSETLOCATION(Denmark);
        IloIntVar France(env, 0, 3, "France");           ILOSETLOCATION(France);
        IloIntVar Germany(env, 0, 3, "Germany");         ILOSETLOCATION(Germany);
        IloIntVar Luxembourg(env, 0, 3, "Luxembourg");   ILOSETLOCATION(Luxembourg);
        IloIntVar Netherlands(env, 0, 3, "Netherlands"); ILOSETLOCATION(Netherlands);
        ILOADD(model, Belgium != France);
        ILOADD(model, Belgium != Germany);
        ILOADD(model, Belgium != Netherlands);
        ILOADD(model, Belgium != Luxembourg);
        ILOADD(model, Denmark != Germany );
        ILOADD(model, France != Germany);
        ILOADD(model, France != Luxembourg);
        ILOADD(model, Germany != Luxembourg);
        ILOADD(model, Germany != Netherlands);
        IloCP cp(model);
        cp.dumpModel(filename);
      } catch (IloException& ex) {
        env.out() << "Error: " << ex << std::endl;
      }
      env.end();
    }
    
    void solveModel(const char* filename) {
      IloEnv env;
      try {
        IloCP cp(env);
        cp.importModel(filename);
        // Force blue color (zero) for France:
        cp.getIloIntVar("France").setBounds(0, 0);
        if (cp.solve()) {
          cp.out() << std::endl << "Solution:" << std::endl;
          IloIntVarArray vars = cp.getAllIloIntVars();
          for (IloInt i = 0; i < vars.getSize(); i++)
            cp.out() << vars[i].getName() << ": " << Names[cp.getValue(vars[i])] << std::endl;
        }
      } catch (IloException& ex) {
        env.out() << "Error: " << ex << std::endl;
      }
      env.end();
    }
    
    int main(int argc, const char** argv) {
      const char* filename = (argc > 1 ? argv[1] : "cpofileformat.cpo");
      createModel(filename);
      solveModel(filename);
      return 0;
    }
    

    If you are using OPL, you can use scripting to convert your POL models to CPO using a function like:

      function convertModel(model, data, cpo) {
         var rc = new IloOplRunConfiguration(model, data);
        rc.oplModel.generate();
        var engine = rc.cp;
        engine.exportModel(cpo);
        rc.end();
      }      
    

    where  where "model" is the .mod file, "data" the data file and "cpo" the path of the .cpo file to create.

    I hope this helps.

    Cheers,


    #CPOptimizer
    #DecisionOptimization


  • 3.  Re: interactive CPO

    Posted Tue March 10, 2015 07:26 AM

    Originally posted by: rdumeur


    Hi  again,

    In addition you can use oplrun -d:

        -d [dump-file]      dump model, default is 'oplrun.cpo' (CPO only)

    Cheers,

     


    #CPOptimizer
    #DecisionOptimization


  • 4.  Re: interactive CPO

    Posted Tue March 10, 2015 08:59 AM

    Originally posted by: DavidGravot


    is there any plan to read from file in a command line . oplrnu would be ok if we can read / write cpo (then, there would be no specific need for an "interactive" cpo) ?


    #CPOptimizer
    #DecisionOptimization


  • 5.  Re: interactive CPO

    Posted Tue March 10, 2015 09:19 AM

    Originally posted by: rdumeur


    Hi David,

    I am not aware of any plan regarding this feature.

    Cheers,


    #CPOptimizer
    #DecisionOptimization


  • 6.  Re: interactive CPO

    Posted Mon June 15, 2015 04:45 AM

    Hi,

    what you could do is use the function IloCP::importModel an change the oplrun example in

    C:\ILOG\CPLEX_Studio126_32\opl\examples\opl_interfaces\java\oplrunsample\src\oplrunsample

    in order to have a command line tool with the required behaviour

    regards


    #CPOptimizer
    #DecisionOptimization


  • 7.  Re: interactive CPO

    Posted Wed January 11, 2017 04:19 AM

    Originally posted by: PhilippeLaborie


    By the way, as of V12.7 a CP Optimizer interactive is available. Here is an excerpt from the documentation:

    An interactive optimizer is available in <COSDIR>/cpoptimizer/bin/<PLATFORM>, called cpoptimizer or cpoptimizer.exe on Windows operating systems. When invoked, this program lets you load models  in .cpo format, invoke and interrupt a solve or conflict refinement, set parameters, display solutions, and so on. You can type help at the prompt to get more information on how to use the interactive optimizer. The interactive optimizer lets you evaluate the variability in performance of CP Optimizer on a particular model. The runseeds <N> command runs CP Optimizer on your model N times (varying the random seed) and provides statistics on the runs, where the default value of N is 30. This allows you to evaluate the performance variability on your model so that you can better interpret performance changes that result from small changes to data or to the model itself.


    #CPOptimizer
    #DecisionOptimization