1

I am trying to create a model for production planning in two factories that deliver goods to five different locations.

Each factory has a maximum capacity and a production cost rate. Additionally, the transportation cost between the factory and each location needs to be taken into account.

I have access to historical data for the demand from each location, and I need to incorporate this data into my planning to anticipate the potential demand.

Here is the problem: I am supposed to multiply the historical demand by certain factors (0.8, 0.9, 1.0, 1.1, 1.2) in order to create five different scenarios. However, the code provided only accounts for one forecast multiplier, and I am unsure how to obtain results for the different scenarios, i.e., the various forecast multipliers. Thank you

This my code: I also tried to put iteration in the main function. However the biggest problem so far was to get the value of decision variable from matrix.


 *********************************************/
// Data
range ProductionRegionID = 1..2;
range SalesRegionID = 1..5;

// Maximum capacity for each ProductionRegion
int cap[ProductionRegionID] = ... ;
// Production cost for each ProductionRegion
float cost[ProductionRegionID] = ... ;
// Transportation cost
float Trans[ProductionRegionID][SalesRegionID] = ... ;
// Historical orders
int HistOrder[SalesRegionID] = ... ;
// Forecast multiplier
float ForecastMultiplier = 1 ;

// Decision variables
dvar int+ x[ProductionRegionID][SalesRegionID];

// Objective function
minimize sum (p in ProductionRegionID, s in SalesRegionID) (cost[p]*x[p][s] + Trans[p][s]*x[p][s]);

// Constraints
subject to {
  forall(s in SalesRegionID)
    sum (p in ProductionRegionID) x[p][s] >= ForecastMultiplier*HistOrder[s];
  forall(p in ProductionRegionID)
    sum (s in SalesRegionID) x[p][s] <= cap[p];
}`
Anduliska
  • 11
  • 2

2 Answers2

0

if what you need to do is to run with several values for ForecastMultiplier

then you should have a look at the example https://github.com/AlexFleischerParis/howtowithoplchange/blob/master/changevalue.mod

The main model is

main {
      var source = new IloOplModelSource("subvalue.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());
      } else {
         writeln("No solution");
      }
     opl.end();
    }  
     
    }

and the sub model is

float maxOfx = ...;
    dvar float x;

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

    execute
    {
    writeln("x= ",x);
    }
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
0

I figured it out, the main method is:

main {
  var source = new IloOplModelSource ("CS4.mod");
  var def = new IloOplModelDefinition(source);
  
  
  for (var k = 0.8; k <= 1.3; k += 0.1){
    var modelInstance = new IloOplModel(def, cplex);
    var data = new IloOplDataSource("CS4.dat");
    modelInstance.addDataSource(data);
    var data2= new IloOplDataElements();
      data2.ForecastMultiplier=k;
      modelInstance.addDataSource(data2);
  modelInstance.generate();
   cplex.solve();
     
    writeln("For The scenario:" + k +", Optimal solution: " + modelInstance.x);
    modelInstance.end()
    }
  
  
  }
Anduliska
  • 11
  • 2
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 10 '23 at 10:54