How to define float variables in non linear problem. That float variable is for every node and total number of node is 13

19 views Asked by At

I have to define float variables such as nbBus40 and nbBus30 for every node in OPL Cplex and the optimization problem is non-linear. I am writing the code and the error with the code.

using CP;

int nbKids=310;
float costBus40=500;
float costBus30=400;
int scale=100;
int num_Node = 13;
range Node = 1..num_Node;

 
dvar int+ scalenbBus40[Node];
dvar int+ scalenbBus30[Node];

*dexpr float nbBus40[Node]=scalenbBus40[Node]/scale;*
*dexpr float nbBus30[Node]=scalenbBus30[Node]/scale;*
 
minimize
 sum (n in Node)(costBus40*nbBus40[n]  + nbBus30*costBus30[n]);
 
subject to
{
forall (n in Node){
40*nbBus40[n]+nbBus30[n]*30>=nbKids;
}     
}

The error with the italic part of the above code is that it Cannot use type range for int.

1

There are 1 answers

0
Alex Fleischer On
dexpr float nbBus40[Node]=scalenbBus40[Node]/scale;

is wrong. You should write:

dexpr float nbBus40[i in Node]=scalenbBus40[i]/scale;

The following model works fine

execute
{
  cp.param.timelimit=10;
}
    
using CP;

int nbKids=310;
float costBus40=500;
float costBus30=400;
int scale=100;
int num_Node = 13;
range Node = 1..num_Node;

 
dvar int+ scalenbBus40[Node];
dvar int+ scalenbBus30[Node];

dexpr float nbBus40[i in Node]=scalenbBus40[i]/scale;
dexpr float nbBus30[i in Node]=scalenbBus30[i]/scale;
 
minimize
 sum (n in Node)(costBus40*nbBus40[n]  + nbBus30[n]*costBus30);
 
subject to
{
forall (n in Node){
40*nbBus40[n]+nbBus30[n]*30>=nbKids;
}     
}