IBM ILOG Solver User's Manual > Extending the Library > Extraction Concepts > Main rule of extraction: 1 to 1 correspondence > The case of goals

IloGoals are not extractables and they are not added to the model. Instead, they are used directly by the instance of IloSolver. Goals are not extracted, even though there is a pseudo-extraction mechanism; the virtual method IlcGoal IloGoalI::extract(IloSolver) is called to create a corresponding IlcGoal.

The consequence of the fact that goals are not extractables is quite simple. A goal does not extract its subextractables. They must be extracted as a consequence of the extraction of the model.

For instance, the following code is incorrect:

IloEnv env;
IloIntVar x(env, 0, 10);
IloIntVar y(env, 0, 10);
IloIntVar z(env, 0, 10);
IloModel model(env);
model.add(x < y);
IloSolver solver(model);
solver.solver(IloInstantiate(env, z));

In the last line, the extraction of the IloInstantiate goal will raise an exception because z will not be extracted in the model. A simple way to ensure that this problem does not occur is to add subextractables directly to the model.

The following code is correct:

IloEnv env;
IloIntVar x(env, 0, 10);
IloIntVar y(env, 0, 10);
IloIntVar z(env, 0, 10);
IloModel model(env);
model.add(x < y);
model.add(z);
IloSolver solver(model);
solver.solver(IloInstantiate(env, z));