ILOG CPLEX 11.0 User's Manual > Discrete Optimization > Using Piecewise Linear Functions in Optimization: a Transport Example > Developing a Model > Adding Constraints

According to the description of the problem, the supply of cars from the factories must meet the demand of the showrooms. At the same time, it is important not to ship cars that are not in demand; in terms of this model, the demand should meet the supply as well. Those ideas are represented as constraints added to the model, like this:

    for(i = 0; i < nbSupply; i++) {      // supply must meet demand
         model.add(IloSum(x[i]) == supply[i]);
    }
    for(j = 0; j < nbDemand; j++) {      // demand must meet supply
         IloExpr v(env);
         for(i = 0; i < nbSupply; i++)
            v += x[i][j];
         model.add(v == demand[j]);
         v.end();
    }