Topic
  • No replies
AlexFleischer
AlexFleischer
3322 Posts

Pinned topic Very simple OPL : arrays and sets

‏2018-05-18T12:17:01Z | arrays opl simple

Hi,

let us continue https://www.ibm.com/developerworks/community/forums/html/topic?id=0b787c15-f0a0-4157-ac2d-a63f0f0a48ee

Suppose we want to be able to deal with more than 2 categories. For this, let us move from scalar to arrays.

.mod

int nbKids=...;

{int} seats=...; // how many seats, {} means this is a set
float costBus[seats]=...;

 
dvar int+ nbBus[seats];

 minimize
 sum(b in seats) costBus[b]*nbBus[b];
 
subject to
{
 sum(b in seats) b*nbBus[b]>=nbKids;
}

.dat

nbKids=300;
seats={40,30};
costBus=[500,400];

Of course, we get the same solution as before.

We used sum and forall which are very powerful OPL keywords.

 

regards

 

Updated on 2018-05-22T15:14:27Z at 2018-05-22T15:14:27Z by AlexFleischer