Originally posted by: Ashalor
Hi Alexander
thank you very much for your help. Thanks to you (and also a bit to some websites giving basics about javascript) I managed to solve the problem.
The model is now solved multiple times.
A decision(i[2]) variable aquired in iteration x-1 is now used in iteration x
A parameter array (sp([t]) is substituted each iteration with a new array.
Just in case anyone encounters the same problem and has as much experience as me, i add my code. Even if I assume, that there are much more elegant solutions.
main{
var source = new IloOplModelSource("test.mod");
var cplex = new IloCplex();
var def = new IloOplModelDefinition(source);
var globalValue = 0;
var curr = Infinity;
var subSupplyCost1 = new Array (0, 1.2, 1.3, 1.4, 1.5, 1.6);
var subSupplyCost2 = new Array (0, 1, 1, 1, 1, 1);
var subSupplyCost3 = new Array (0, 1.3, 1.3, 1.3, 1.3, 1.3);
var SupplyCost = new Array (0, subSupplyCost1, subSupplyCost2, subSupplyCost3);
for(var counter=1; counter<=3; counter++){
var opl = new IloOplModel(def, cplex);
var data = new IloOplDataSource("test.dat");
opl.addDataSource(data);
var data2= new IloOplDataElements();
data2.StartInv=globalValue;
data2.sp=thisOplModel.tArray;
for(var time=1; time<=5; time++){
data2.sp[time]=SupplyCost[counter][time];
}
opl.addDataSource(data2);
opl.generate();
if (cplex.solve()) {
writeln ("StartInv=", globalValue);
curr= cplex.getObjValue();
writeln("Objective=", curr);
globalValue=opl.m;
writeln ("new StarInv=",globalValue);
writeln("i[2]=", opl.c);
writeln("i[3]=", opl.d2);
writeln("sp=", opl.sp);
}
else{
writeln("Error");
break;
}
}
opl.end();
data.end();
def.end();
cplex.end();
source.end();
}
int maxT= ...;
range T = 1..maxT;
/*Parameters*/
int D[T]=...;
int Cap = ...;
float ci = ...;
float sp[T] = ...;
float pd[T] = ...;
float StartInv=...;
float tArray[T];
/*dec variables*/
dvar int+ x[T];
dvar int+ i[0..maxT];
dvar int+ d[T];
/*constraints*/
constraint ctDemand[T];
constraint ctCapacity[T];
dexpr float Profit = sum(t in T)d[t]*pd[t] - sum(t in T) i[t]*ci - sum(t in T) x[t]*sp[t];
maximize Profit;
subject to{
forall (t in T)
ctDemand[t]:
d[t]<=D[t];
forall (t in T)
ctCapacity[t]:
x[t]<=Cap;
forall (t in T)
ctInvBalance:
i[t]+d[t] == i[t-1]+x[t];
ctInventory1:
i[0] == StartInv;
}
float m = i[1];
float a = i[0];
float b = i[1];
float c = i[2];
test.dat:
maxT = 5;
Cap = 100;
ci = 0.1;
SheetConnection Data ("testExcel.xlsx");
pd from SheetRead (Data, "testpd"); //contains pd=2 for all t
D = [50, 90, 120, 110, 120];
test2.dat:
StartInv = 0;
sp = [1.2, 1.2, 1.2, 1.2, 1.2];
#DecisionOptimization#OPLusingCPLEXOptimizer