> Discrete Optimization > Cutting Stock: Column Generation > Developing the Model: Building and Modifying > Adding Extractable Objects: Both Ways

In a Concert Technology application, there are two ways of adding extractable objects to a model: by means of a template function (IloAdd) or by means of a method of the model (IloModel::add or IloArray::add). In this example, you see both ways.

Using a Template to Add Objects

When an objective is added to the model, the application needs to keep a handle to the objective RollsUsed because it is needed when the application generates columns. For that purpose, the application relies on the template function IloAdd, like this:

IloObjective   RollsUsed = IloAdd(cutOpt, IloMinimize(env));

Apart from the fact that it preserves type information, that single line is equivalent to these lines:

IloObjective RollsUsed = IloMinimize(env);
cutOpt.add(RollsUsed);

Likewise, the application adds an array of constraints to the model. These constraints are needed later in column generation as well, so the application again uses IloAdd again to add the array Fill to the model.

IloRangeArray  Fill = IloAdd(cutOpt,
                             IloRangeArray(env, amount, IloInfinity));

That statement creates amount.getSize range constraints. Constraint Fill[i] has a lower bound of amount[i] and an upper bound of IloInfinity.

Using a Method to Add Objects

It is also possible to add objects to your model by means of the method IloModel::add. This example uses that approach in these lines:

patGen.add(IloScalProd(size, Use) <= rollWidth);

In contrast, to create Cut, an array of decision variables, the application uses the add method of IloArray within a loop, like this:

    IloInt nWdth = size.getSize();
    for (j = 0; j < nWdth; j++)
      Cut.add(IloNumVar(RollsUsed(1) + Fill[j](int(rollWidth / size[j]))));

In that loop, the variable Cut[j] is created with an objective coefficient of 1 (one), and all its pattern coefficients are initially 0 (zero) except for the one in Fill[j]. That one is set to (int(rollWidth / size[j])). By default, the type of each variable is IloFloat, so it is not explicitly mentioned in the loop.