Originally posted by: Rym
It doesn't work because :
I don't know the value of p in the beginning, it is depends on the number of px
int p=...;
range P=1..p;
int PMx[P];
int Qcpu=192;
int cpu[i in 3]=[96,80,64];
execute Qc
{
var x;
var c=1;
var px=0;
var Q=0
while(Q<(Qcpu))
{
x=1+Opl.rand(3-1);
Q=Q+cpu[x];
px=px+1;
if (c<=p)
PMx[c]=(x);
c++
}
p=px;
writeln("Qcpu=",Qcpu);
writeln("Q=",Q);
writeln("p=",p);
}
I tried the followng and the result is
execute Qc
{var x;
var RS=new Array();
for (var j in 10)
{
RS[j]=0;
}
var c=1;
var px=0;
var Q=0
while(Q<(Qcpu))
{
x=1+Opl.rand(3-1);
writeln("x=",x);
Q=Q+cpu[x];
px=px+1;
RS["c"]=(x);
c++
}
p=px;
for (var df in p)
{
PMx[df]=parseInt(RS[df]);
}
writeln("Qcpu=",Qcpu);
writeln("Q=",Q);
writeln("p=",p);
writeln(PMx);
}
Result
p=3
PMx=["NaN" "NaN" "NaN"]; //instead of [1,1,1] for example
Regards
#DecisionOptimization#OPLusingCPLEXOptimizer