Originally posted by: Srihitha Reddy
Hi,
I understood your example well. Now I tried my code as follows. But in the if loop, in which I was inserting the condition as x[i][j] ==1, can I use simply as if(x[i][j] ==1) or should I use UB and LB as if (x[i][j].UB ==1 && x[i][j].LB ==1).
Also for the given data files, all the values of e[j] should not be equal to 1.
And when am trying to print the values of x[i][j], am encountered an error saying "IloNumVar." What does it mean? How should I overcome it?
/*********************************************
* OPL 12.8.0.0 Model
* Author: SRIHITHA
* Creation Date: Feb 2, 2018 at 9:30:39 AM
*********************************************/
//parameters
int n=...; //no. of requested VMs
int m=...; //no. of servers
range VMs=1..n;
range servers=1..m;
float maxpower=...; //max power consumed by server
float power[VMs]=...;
float currentpower[servers]=...;
//variables
dvar boolean x[VMs][servers];
dvar boolean e[servers];
int count;
execute
{
for(var j=1;j<=m;j=j+1)
{
count=0;
writeln("Value:",count);
for(var i=1;i<=n;i=i+1)
{
if(x[i][j]==1) //SHOULD I INCLUDE UB AND LB ADDRESSING x[i][j].
count=count+1;
}
writeln("Value of count:",count); //THE VALUE IS NOT CHANGING. I GUESS IF CONDITION IS NOT GETTING EXECUTED.
if(count==0)
{
e[j].UB=0;
e[j].LB=0;
}
else
{
e[j].UB=1;
e[j].LB=1;
}
}
}
//expression
dexpr float z=sum(j in servers) e[j];
minimize z;
//constraints
subject to{
forall (j in servers)
cons1:
sum(i in VMs) power[i]*x[i][j] <= maxpower*e[j] - currentpower[j];
forall(i in VMs)
cons2:
sum(j in servers) x[i][j] == 1;
cons3:
sum(j in servers) e[j] >= ceil ((sum(j in servers) currentpower[j])/maxpower);
}
Thanks in advance.
#DecisionOptimization#OPLusingCPLEXOptimizer