0

我遇到了流控制问题,无法从给定的 CPLEX 示例中找到出路。我想解决16次优化问题,唯一不同的是需求的输入。(因为我们在服务器中运行“SheetConnection”代码时遇到问题,所以我想构建从 dat 文件中读取原始数据的模型)。

我有 16 个不同时期的 16 个需求。对于第一次运行,我希望模型的需求是需求数组的第一个数字。对于第 n 次运行,模型的需求是需求数组的第 n 个数字。

我已经从 CPLEX 示例“mulprod”修改了模型,但我发现该示例越来越多地改变面粉的容量(每次添加 1 个单位)。所以,它没有提到如何按顺序读取数据。我想问题在于如果我想在开始时将 Demand 设置为一个范围,那么我调用第 n 个数字的代码就有问题。

/*mod.file*/
{string} Units_ = ...;
int NbUnits = ...;
range Units = 1..NbUnits;
int NbLoops = ...;

float Demand[1..16] = ...;
float MaxGen [Units] = ...; 
float MinGen [Units] = ...; 
float MarginalC [Units] = ...; 

dvar boolean Opr [u in Units];
dvar float+ Gen [u in Units] in 0..MaxGen [u];

execute {
  writeln("* This OPL model is not compliant with cloud execution");
}

minimize 
  sum(u in Units) (Gen[u] * MarginalC[u]);

subject to {
//Meet demand       
      ctPowerBalance: 
        sum(u in Units) Gen[u] == Demand;  
//Max/Min Unit Constraints           
    forall(u in Units)
      ctMaxGeneration:
        Gen[u] <= MaxGen[u]*Opr[u];
    forall(u in Units)
      ctMinGeneration:
        Gen[u] >= MinGen[u]*Opr[u];
}

tuple plan {
  float Operation;
  float Generation;
}

plan Plan[u in Units] = 
  <Opr[u], Gen[u]>;



main {
  thisOplModel.generate();

  var produce = thisOplModel;
  var Demandt = produce.Demand_[NbLoops];

  var best;
  var curr = Infinity;
  var ofile = new IloOplOutputFile("BAU_T2030.txt");
  while ( 1 ) {
    best = curr;
    writeln("Solve with Demand[", NbLoops, "] is ", Demandt);
    if ( cplex.solve() ) {
      curr = cplex.getObjValue();
      writeln();
      writeln("OBJECTIVE: ",curr);
      ofile.writeln("Objective with Demand[", NbLoops, "] is ", curr);
      ofile.writeln("plan = ",produce.Plan);      
} 
    else {
      writeln("No solution!");
      break;
    }
    if ( best==curr ) break;

NbLoops ++;
    for(var Demand in thisOplModel.Demand)          
      thisOplModel.ctPowerBalance[Demand].UB = Demandt;
  }

  ofile.close();

  0;
}

/*dat.file*/
Units_ = {G11, G12, G13, G14, G15};
NbUnits = 5;
NbLoops = 1;
Demand = [1133.16, 1826.47, 1304.79, 1330.03, 1556.02, 1952.19, 1124.82, 1622.05, 1567.69, 1499.43, 1315.01, 1135.05, 1029.67, 1949.19, 1972.64, 1812.24];
MaxGen = [519.2, 665.6, 46.5, 212, 464];
MarginalC = [55.21, 36.32, 41.62, 34.16, 36.71]; 
4

1 回答 1

0

这是https://www.linkedin.com/pulse/making-decision-optimization-simple-alex-fleischer/中的增量流控制

.mod

{string} Units_ = ...;
int NbUnits = ...;
range Units = 1..NbUnits;
int NbLoops = ...;

float Demand[1..16] = ...;
float MaxGen [Units] = ...; 
float MinGen [Units] = ...; 
float MarginalC [Units] = ...; 

dvar boolean Opr [u in Units];
dvar float+ Gen [u in Units] in 0..MaxGen [u];

dvar float currentDemand;

execute {
  writeln("* This OPL model is not compliant with cloud execution");
}

minimize 
  sum(u in Units) (Gen[u] * MarginalC[u]);

subject to {
//Meet demand       
      ctPowerBalance: 
        sum(u in Units) Gen[u] == currentDemand;  
//Max/Min Unit Constraints           
    forall(u in Units)
      ctMaxGeneration:
        Gen[u] <= MaxGen[u]*Opr[u];
    forall(u in Units)
      ctMinGeneration:
        Gen[u] >= MinGen[u]*Opr[u];
}

tuple plan {
  float Operation;
  float Generation;
}

plan Plan[u in Units] = 
  <Opr[u], Gen[u]>;



main {
  thisOplModel.generate();
 var NbLoops=1;
  var produce = thisOplModel;


  var best;
  //var curr = Infinity;
  var ofile = new IloOplOutputFile("BAU_T2030.txt");
  while ( NbLoops<=16 ) {
    var Demandt = produce.Demand[NbLoops];
    //best = curr;
    writeln("Solve with Demand[", NbLoops, "] is ", Demandt);
    if ( cplex.solve() ) {
      curr = cplex.getObjValue();
      writeln();
      writeln("OBJECTIVE: ",curr);
      ofile.writeln("Objective with Demand[", NbLoops, "] is ", curr);
      ofile.writeln("plan = ",produce.Plan);      
} 
    else {
      writeln("No solution!");
      //break;
    }
    //if ( best==curr ) break;

NbLoops ++;
    //for(var Demand in thisOplModel.Demand)          
      thisOplModel.currentDemand.UB = Demandt;
      thisOplModel.currentDemand.LB = Demandt;
  }

  ofile.close();

  0;
}

.dat

Units_ = {G11, G12, G13, G14, G15};
NbUnits = 5;
NbLoops = 16;
Demand = [1133.16, 1826.47, 1304.79, 1330.03, 1556.02, 1952.19, 1124.82, 1622.05, 1567.69, 1499.43, 1315.01, 1135.05, 1029.67, 1949.19, 1972.64, 1812.24];
MaxGen = [519.2, 665.6, 46.5, 212, 464];
MinGen = [];
MarginalC = [55.21, 36.32, 41.62, 34.16, 36.71]; 

效果更好

于 2020-05-24T08:35:15.280 回答