Accessing model elements

Shows how to access the elements of your model.

To access any model element by its name

Use the method getElement.

C++


IloOplElement supply = oplModel.getElement("supply");

Java


IloOplElement supply = oplModel.getElement("supply");

.NET


OplElement supply = oplModel.GetElement("supply");

The IloOplElement interface offers accessors for all possible element types. It is the user’s responsibility to pick the right accessor for the type of the elements he has declared.

To access a decision variable

For decision variables, there are two different types of accessors:

  • one to obtain the Concert object itself for this decision variable

  • the other to get the values of decision variables within a solution. The latter is available only if a solution has been found.

The subsequent procedures give examples of each for a supply model element.

To get the supplyVar1 decision variable within a model, write the following code.

C++


IloNumVarMap supplyVarMap = supply.asNumVarMap();
IloNumVar supplyVar1 = supplyVarMap.get(1);

Java


IloNumVarMap supplyVarMap = supply.asNumVarMap();
IloNumVar supplyVar1 = supplyVarMap.get(1);

.NET


INumVarMap supplyVarMap = supply.AsNumVarMap();
INumVar supplyVar1 = supplyVarMap.Get(1);

To access the values of a decision variable

To get the values of the supply1 decision variable within a solution, write the following code.

C++


IloNumMap supplyMap = supply.asNumMap();
double supply1 = supplyMap.get(1);

Java


IloNumMap supplyMap = supply.asNumMap();
double supply1 = supplyMap.get(1);

.NET


INumMap supplyMap = supply.AsNumMap();
double supply1 = supplyMap.Get(1);