> Discrete Optimization > Food Manufacturing 2: Using Logical Constraints > Developing the Model

First, create the model, like this:

IloModel model(env);

Then use a for-loop to add the constraints for each month (from What Are the Constraints?), like this:

      for (i = 0; i < nbMonths; i++) {
         model.add(use[i][v1] + use[i][v2] <= 200); 
         model.add(use[i][o1] + use[i][o2] + use[i][o3] <= 250); 
         model.add(3 * produce[i] <=
                   8.8 * use[i][v1] + 6.1 * use[i][v2] +
                   2   * use[i][o1] + 4.2 * use[i][o2] + 5 * use[i][o3]);
         model.add(8.8 * use[i][v1] + 6.1 * use[i][v2] +
                   2   * use[i][o1] + 4.2 * use[i][o2] + 5 * use[i][o3]
                   <= 6 * produce[i]);
         model.add(produce[i] == IloSum(use[i]));
         if (i == 0) {
            for (IloInt p = 0; p < nbProducts; p++)
               model.add(500 + buy[i][p] == use[i][p] + store[i][p]);
         }
         else {
            for (IloInt p = 0; p < nbProducts; p++)
              model.add(store[i-1][p] + buy[i][p] == use[i][p] + store[i][p]);
         }
         profit += 150 * produce[i] - IloScalProd(cost[i], buy[i]) -
                   5 * IloSum(store[i]);

         model.add((use[i][v1] == 0) + (use[i][v2] == 0) + (use[i][o1] == 0) +
                   (use[i][o2] == 0) + (use[i][o3] == 0) >= 2);
         for (p = 0; p < nbProducts; p++)
            model.add((use[i][p] == 0) || (use[i][p] >= 20));
         model.add(IloIfThen(env, (use[i][v1] >= 20) || (use[i][v2] >= 20),
           use[i][o3] >= 20));
      }

To consolidate the monthly objectives, add the overall objective to the model, like this:

      model.add(IloMaximize(env, profit));