Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

timing of argument availability when using -D with oplrun

  • 1.  timing of argument availability when using -D with oplrun

    Posted Mon April 13, 2009 09:48 PM

    Originally posted by: SystemAdmin


    [skroyer said:]

    Hello,

    I am using oplrun to invoke a model until we have elaborated the model sufficiently to warrant developing an automated API-based solution.  In the meantime, however, I would like to avoid manually changing certain key values in the model each time I attempt to solve for a new set of data.  We use a dat file that reads all of the necessary data from a database server using a single integer key value which is supplied to each of the queries using the question-mark substitution variable syntax.

    My problem is that when I attempt to supply the key-value for a run as one of the command-line arguments for oplrun (e.g. oplrun -D dbkey=5 -p "projectName"), the key value is available to the model, but does not appear to be available at the time that the queries are being run.  On the other hand, if I set an integer variable at the top of the model code, it works fine.  Is there a way to make sure that the command-line arguments are available at the time that the query statements are being prepared?

    Thanks!
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: timing of argument availability when using -D with oplrun

    Posted Tue April 28, 2009 05:03 PM

    Originally posted by: SystemAdmin


    [afleischer said:]

    Hello,

    to get what you need you could use a main block.

    Let me give you an example.
    In the file oil.mod you add


    string s=...;


    in the file oilSheet.dat from the OPL distribution in examples\opl\oil you replace the SheetConnection line by


    SheetConnection sheet(s);


    then

    oplrun -Ds="oilSheet.xls" callOilSheet.mod will call the example with the file name as parameter

    In the model callOilSheet.mod we have


    string s=...;

    main {
    thisOplModel.generate();
      var source = new IloOplModelSource("oil.mod");
      var cplex = new IloCplex();
      var def = new IloOplModelDefinition(source);
      var opl = new IloOplModel(def,cplex);
      var data0= new IloOplDataElements();
     
      var data = new IloOplDataSource("oilSheet.dat");
      data0.s=thisOplModel.s;
      opl.addDataSource(data0);
      opl.addDataSource(data);
      opl.generate();
      if (cplex.solve()) {
          writeln("OBJ = " + cplex.getObjValue());
      } else {
          writeln("No solution");
      }
     
      opl.end();
     
     
    }



    #CPLEXOptimizers
    #DecisionOptimization