ILOG CPLEX 11.0 User's Manual > Discrete Optimization > Using Piecewise Linear Functions in Optimization: a Transport Example > Developing a Model > Checking Convexity and Concavity

To illustrate the ideas of convex and concave piecewise linear functions, two tables of costs that vary according to the quantity of cars shipped were introduced in the problem description. To accommodate those two tables in the model, the following lines are added.

    if (convex) {
      for(i = 0; i < nbSupply; i++){
        for(j = 0; j < nbDemand; j++){
          model.add(y[i][j] == IloPiecewiseLinear(x[i][j],
                                        IloNumArray(env, 2, 200.0, 400.0),
                                        IloNumArray(env, 3, 30.0, 80.0, 130.0),
                                0.0, 0.0));
        }
      }
    }else{
      for(i = 0; i < nbSupply; i++){
        for(j = 0; j < nbDemand; j++){
          model.add(y[i][j] == IloPiecewiseLinear(x[i][j],
                                        IloNumArray(env, 2, 200.0, 400.0),
                                        IloNumArray(env, 3, 120.0, 80.0, 50.0),
                                0.0, 0.0));
        }
      }
    }