ILOG CPLEX 11.0 Getting Started > Tutorials > Concert Technology Tutorial for C++ Users > Building and Solving a Small LP Model in C++ > Modeling by Columns

Function populatebycolumn can be viewed as the transpose of populatebyrow. While for simple examples like this one population by rows may seem the most straightforward and natural approach, there are some models where modeling by column is a more natural or more efficient approach.

When modeling by columns, range objects are created with their lower and upper bound only. No expression is given since the variables are not yet created. Similarly, the objective function is created with only its intended optimization sense, and without any expression. Next the variables are created and installed in the already existing ranges and objective.

The description of how the newly created variables are to be installed in the ranges and objective is by means of column expressions, which are represented by the class IloNumColumn. Column expressions consist of objects of class IloAddNumVar linked together with operator +. These IloAddNumVar objects are created using operator() of the classes IloObjective and IloRange. They define how to install a new variable to the invoking objective or range objects. For example, obj(1.0) creates an IloAddNumVar capable of adding a new modeling variable with a linear coefficient of 1.0 to the expression in obj. Column expressions can be built in loops using operator +=.

Column expressions (objects of class IloNumColumn) are handle objects, like most other Concert Technology objects. The method end must therefore be called to delete the associated implementation object when it is no longer needed. However, for implicit column expressions, where no IloNumColumn object is explicitly created, such as the ones used in this example, the method end should not be called.

The column expression is passed as an argument to the constructor of class IloNumVar. For example the constructor IloNumVar(obj(1.0) + c[0](-1.0) + c[1]( 1.0), 0.0, 40.0) creates a new modeling variable with lower bound 0.0, upper bound 40.0 and, by default, type ILOFLOAT, and adds it to the objective obj with a linear coefficient of 1.0, to the range c[0] with a linear coefficient of -1.0 and to c[1] with a linear coefficient of 1.0. Column expressions can be used directly to construct numerical variables with default bounds [0, IloInfinity] and type ILOFLOAT, as in the following statement:

x.add(obj(2.0) + c[0]( 1.0) + c[1](-3.0));

where IloNumVar does not need to be explicitly written. Here, the C++ compiler recognizes that an IloNumVar object needs to be passed to the add method and therefore automatically calls the constructor IloNumVar(IloNumColumn) in order to create the variable from the column expression.