Flow control

Flow control scripting enables you to control how models are instantiated and solved.

Flow control scripting enables you to control how models are instantiated and solved. You can use it in addition to pre- and postprocessing. More specifically, it enables you to use several models with different data, to run multiple “solve” on a model, and to modify the model data between one solve and the next. It is particularly useful when you want to solve a model with modified data several times, or if you want to use different models to solve your problem (model decomposition).

Examples

Mathematical programming (CPLEX® engine)

A main block in an MP model:

 model.generate(); if (cplex.solve()) { var
obj=cplex.getObjValue(); opl.postProcess(); } 

Constraint programming (CP Optimizer engine)

Two different main blocks in a CP model:

 model.generate(); if (cp.solve()) { var obj=cp.getObjValue()
model.postProcess(); } 

Or, to find all solutions:

 model.generate(); cp.startNewSearch(); while
(cp.next()) {  model.postProcess(); } 

For more information

The design of the OPL extensions to IBM® ILOG® Script available for flow control is close to that of OPL Interfaces in C++. See Working with OPL interfaces in the Interfaces User’s Manual for details.

The IBM ILOG Script API available for solving is very limited compared to IloCplex and IloCP in C++,. NET, or Java™. See the Reference Manual of IBM ILOG Script Extensions for OPL for a complete list of available properties and methods.

In Tutorial: Flow control and multiple searches, you will work from the mulprod_main example to learn how to solve several times the same model with modified data.

In Tutorial: Flow control and column generation, you will work from the cutstock example to learn how to solve two different models one after the other by using the output from the first one as data to the second one.

See OPL language options in IDE Reference for performance aspects.