main

OPL keyword for a flow control script

Purpose

OPL keyword to introduce a scripting block for flow control.

context
Model files (.mod)

Syntax

Scripting: "execute" Id_opt "(execute-block)"
         | "main" "(execute-block)"

Description

A flow control is performed using a main execution block. This keyword introduces a flow control.

A return value >=0 means that the execution was correct. A return value <0 means that an error occurred during the execution.

Example

range r=0..20;

dvar int x in r; // x products A
dvar int y in r; // y products B

maximize 40*x+30*y; // outcome

subject to
{
 x+y<=20; // max products  
}

main
{
   thisOplModel.generate();
   for (var k in thisOplModel.r) 
   {
      thisOplModel.x.UB=k;
      thisOplModel.y.UB=k;
      cplex.solve();
      write("if productions between 0 and ",k);
      write(" then we maximize outcome with the");
      write(" constraint is nbA = ",thisOplModel.x.solutionValue);
      writeln(" and nbB =",thisOplModel.y.solutionValue);   
   }
}