Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Static vs. dynamic .dat files

    Posted 07/25/17 12:20 PM

    Originally posted by: ALessin


    Is there a way to set some .dat files as static, while changing just a few .dat files across looped problem instances?

    For example, I would like to add and change several .dat files using a loop process similar to the example below. However, I also have numerous additional .dat files that remain static across all iterations. If I add all the .dat files in the manner shown below, the solution time is greatly increased. If there's a way to initialize the static .dat files before the dynamic .dat file loop, I think the solution time would decrease significantly.  

    Take the small model sub.mod

    float maxOfx = ...;
    dvar float x;

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

     

    You can use in some other .mod

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

      if (cplex.solve()) {
         writeln("OBJ = " + cplex.getObjValue());
      } else {
         writeln("No solution");
      }
     opl.end();
     
    }   
    }

    Thank you for your help!

    -Aaron


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Static vs. dynamic .dat files

    Posted 07/25/17 01:32 PM

    Hi,

    you can mix static data file, dynamic data file and in memory data file.

    Let me give you an example:

    sub.mod

    float maxOfx = ...; // memory
    float maxOfy = ...; // static .dat
    float maxOfz = ...; // dynamic .dat


    dvar float x;
    dvar float y;
    dvar float z;

    maximize x+y+z;
    subject to {
      x<=maxOfx;
      y<=maxOfy;
      z<=maxOfz;
    }

    sub.dat

    maxOfy=5;

    and then the main model

    main {
      var source = new IloOplModelSource("sub.mod");
      var cplex = new IloCplex();
      var def = new IloOplModelDefinition(source);
      var opl = new IloOplModel(def,cplex);
     
      for(var k=11;k<=20;k++)
      {
      var opl = new IloOplModel(def,cplex);
        
      var data2= new IloOplDataElements();
      data2.maxOfx=k;
      opl.addDataSource(data2);
     
      var data3=new IloOplDataSource("sub.dat");
      opl.addDataSource(data3);
     
      var dynamicFile=new IloOplOutputFile("sub2.dat");
      dynamicFile.writeln("maxOfz=",k,";");
      dynamicFile.close();
     
      var data4=new IloOplDataSource("sub2.dat");
      opl.addDataSource(data4);
     
      opl.generate();

      if (cplex.solve()) {
         writeln("OBJ = " + cplex.getObjValue());
      } else {
         writeln("No solution");
      }
     opl.end();
     
    }   
    }

    will give

    OBJ = 27
    OBJ = 29
    OBJ = 31
    OBJ = 33
    OBJ = 35
    OBJ = 37
    OBJ = 39
    OBJ = 41
    OBJ = 43
    OBJ = 45

    regards

     

    PS:

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


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Static vs. dynamic .dat files

    Posted 07/25/17 04:39 PM

    Originally posted by: ALessin


    That's a lot of help. Thank you, Alex! As always, I appreciate your timely response!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer