> Discrete Optimization > Rates: Using Semi-Continuous Variables > Building a Model

After the application creates an environment and a model in that environment, it is ready to populate the model with extractable objects pertinent to the problem.

It represents the production level of each generator as a semi-continuous variable. In that way, with the value 0 (zero), the application can accommodate whether the generator is on or off; with the semi-continuous lower bound of each variable, it can indicate the minimum level of output from each generator; and indicate the maximum level of output for each generator by the upper bound of its semi-continuous variable. The following lines create the array production of semi-continuous variables (one for each generator), like this:

IloNumVarArray production(env);
   for (IloInt j = 0; j < generators; ++j)
        production.add(IloSemiContVar(env, minArray[j], maxArray[j]));

The application adds an objective to the model to minimize production costs in this way:

mdl.add(IloMinimize(env, IloScalProd(cost, production)));

It also adds a constraint to the model: it must meet demand.

mdl.add(IloSum(production) >= demand);

With that model, now the application is ready to create an algorithm (in this case, an instance of IloCplex) and extract the model.