Topic
  • No replies
AlexFleischer
AlexFleischer
3627 Posts

Pinned topic Very simple OPL : dat files

‏2018-05-18T12:02:15Z | data file opl simple

Hi,

let me try a new way to help the OPL users : very basic examples to show a concept.

Let us use the example from https://www.linkedin.com/pulse/what-optimization-how-can-help-you-do-more-less-zoo-buses-fleischer/

int nbKids=300;
float costBus40=500;
float costBus30=400;
 
dvar int+ nbBus40;
dvar int+ nbBus30;
 
minimize
 costBus40*nbBus40  +nbBus30*costBus30;
 
subject to
{
 40*nbBus40+nbBus30*30>=nbKids;
}

This file is a .mod and in the IDE we get

 

Now suppose you need to have some more abstraction and you want to be able to have the model and the values not together.

You write a .mod and a .dat

.mod

int nbKids=...;
float costBus40=...;
float costBus30=...;
 
dvar int+ nbBus40;
dvar int+ nbBus30;
 
minimize
 costBus40*nbBus40  +nbBus30*costBus30;
 
subject to
{
 40*nbBus40+nbBus30*30>=nbKids;
}

.dat

nbKids=300;
costBus40=50;
costBus30=40;

and you will get the same result as before

NB: "..." means not defined here but later on.

regards

 

Updated on 2018-05-22T15:13:58Z at 2018-05-22T15:13:58Z by AlexFleischer