Creating an OPL model

Explains how to create an OPL model that uses the OPL interfaces.

To create the Concert environment

As for any IBM ILOG Concert Technology model, you need an instance of the environment in which to create your model objects.

Write the following code.

C++

   IloEnv env;

Java

   IloOplFactory oplF = new IloOplFactory();

.NET (Visual Basic)

   Dim oplF As OplFactory = New OplFactory

To create the error handler

Create an error handler is necessary in the environment to report errors and warnings during the translation of the model text.

C++

      IloOplErrorHandler handler(env,cout);

Java

      IloOplErrorHandler errHandler = oplF.createOplErrorHandler();

.NET (Visual Basic)

      Dim errorHandler As OplErrorHandler = oplF.CreateOplErrorHandler()

To identify the model source

Pass the model source that provides the text to interpret.

C++

      IloOplModelSource modelSource(env, DATADIR 'mulprod.mod');

Java

      IloOplModelSource modelSource = oplF.createOplModelSource(DATADIR + '/mulprod.mod');

.NET (Visual Basic)

      Dim modelSource As OplModelSource = oplF.CreateOplModelSource(DATADIR + '/mulprod.mod')

To identify the model definition

Use same model definition to instantiate one or more models.

C++

      IloOplSettings settings(env,handler);
      IloOplModelDefinition def(modelSource,settings);

Java

      IloOplModelDefinition def = oplF.createOplModelDefinition(modelSource,settings);

.NET (Visual Basic)

      Dim def As OplModelDefinition = oplF.CreateOplModelDefinition(modelSource, settings)

To create the engine instance

Create the instance of the algorithm to use for this model.

C++

   IloCplex cplex(env);
Note:

If the model is to be solved by CP Optimizer engine, you would instantiate an IloCP object using

IloCP cp(env)

Java

   IloCplex cplex = oplF.createCplex();
Note:

If the model is to be solved by CP Optimizer engine, you would instantiate an IloCP object using

IloCP cp = oplF.createCP()

.NET (Visual Basic)

   Dim cplex As Cplex = oplF.CreateCplex()
Note:

If the model is to be solved by CP Optimizer engine, you would instantiate an IloCP object using

Dim cp As CP = oplF.CreateCP()

To create the OPL model

You can now create the OPL model. The constructor takes a model definition instance and an instance of IloCplex .

C++

      IloOplModel opl(def,cplex);

Java

      IloOplModel opl = oplF.createOplModel(def, cplex);

.NET (Visual Basic)

      Dim opl As OplModel = oplF.CreateOplModel(def, cplex)