Decision Optimization

Decision Optimization

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


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

How to Create different file name in OPL regenerative function

  • 1.  How to Create different file name in OPL regenerative function

    Posted 02/19/17 08:48 PM

    Originally posted by: ShafiAhad


    Hello,

     

    I am trying to generate several solution of a model varying a set of data every time. And I want to generate a .txt file for every iteration with a different file name where I'll export the solution. Can anyone suggest me any way of doing that??

     

    Thanks in advance..!!

     

    Regards,

    Khan


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: How to Create different file name in OPL regenerative function

    Posted 02/20/17 02:54 AM

    Hi,

    an example is more clear than a long answer:

    sub.mod

    float maxOfx = ...;
        dvar float x;

        maximize x;
        subject to {
          x<=maxOfx;
        }

        execute
        {
        writeln("x= ",x);
        }
     

    then

    main {
          var source = new IloOplModelSource("sub.mod");
          var cplex = new IloCplex();
          var def = new IloOplModelDefinition(source);
         
         
         
          for(var k=1;k<=10;k++)
          {
          var opl = new IloOplModel(def,cplex);
            
          var data2= new IloOplDataElements();
          data2.maxOfx=k;
          opl.addDataSource(data2);
          opl.generate();

          if (cplex.solve()) {  
             opl.postProcess();
             writeln("OBJ = " + cplex.getObjValue());
             var f=new IloOplOutputFile("res"+k+".txt");
             f.writeln("OBJ = " + cplex.getObjValue());
             f.close();
          } else {
             writeln("No solution");
          }
         opl.end();
        }  
         
        }

     

    will generate 10 files with results

    regards

    PS:

    many useful links at https://www.ibm.com/developerworks/community/forums/html/threadTopic?id=0d0b2396-3b48-4638-b032-3b9ea74f1a11&ps=25


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: How to Create different file name in OPL regenerative function

    Posted 02/20/17 11:17 AM

    Originally posted by: ShafiAhad


    Thank you very much. It was a big help


    #DecisionOptimization
    #OPLusingCPLEXOptimizer