Using run configuration and projects

Shows how to use run configurations to create the project and access the run configuration and the model using Concert.

Sometimes, it is not necessary to create intermediate objects for the model definition or the data sources as explained in Creating an OPL model. This is the case, for example, when you do not plan to use the data source object for various different OPL models. You can then use the classes IloOplProject and IloOplRunConfiguration to create the IloOplModel instance directly.

This section demonstrates this feature using the oplrun example which exists in three languages at the following locations:

<Install_dir>\opl\examples\opl_interfaces\cpp\src\oplrunsample.cpp

<Install_dir>\opl\examples\opl_interfaces\java\oplrunsample\src\oplrunsample\OplRunSample.java

<Install_dir>\opl\examples\opl_interfaces\dotnet\x64_windows_msvc14\CSharp\OplRunSample\OplRunSample.cs

where <Install_dir> is your installation directory.

Creating the project

You can create an IloOplProject instance directly using a project path.

C++


IloOplProject prj(_env,_cl.getProjectPath());

Java


IloOplProject prj = oplF.createOplProject(_cl.getProjectPath());

.NET (Visual Basic)


Dim prj As OplProject = oplF.CreateOplProject(_cl.ProjectPath)

Accessing a run configuration

From that project, you can access one of the included run configurations. If you pass no argument, you get the default run configuration.

C++


rc = prj.makeRunConfiguration(_cl.getRunConfigurationName());

Java


rc = prj.makeRunConfiguration(_cl.getRunConfigurationName());

.NET (Visual Basic)


rc = prj.MakeRunConfiguration(_cl.RunConfigurationName)

OPL creates the IloOplModel instance from the run configuration automatically.

Accessing the model

You can access the model with the following code.

C++


IloOplModel opl = rc.getOplModel();

Java


IloOplModel opl = rc.getOplModel();

.NET (Visual Basic)


Dim opl As OplModel = rc.GetOplModel()

You can then use the IloOplModel instance as usual.

Using the IloOplProject and IloOplRunConfiguration API brings more than one benefit:

  • It is easier to use when intermediate structures are not necessary.

  • It enables you to use settings files (.ops ).

  • All the advantages of run configurations remain available. In particular, it is possible to easily run the same model with different setting files or with different data sets.