IBM ILOG Scheduler User's Manual > Getting Started with Scheduler > Adding Integral and Functional Constraints > Define the Problem, Design a Model > Budget

After an activity has started, each worked day costs a decreasing amount of money. Days 0 to 2 are charged $1000 each, days 3 to 6 are charged $900 each, and all days including or after day 7 cost $700 each. The actual cost of an activity is then a function of its duration.

  /* CREATE COST CURVE */
  IloNum dailyCost = 0;
  IloNum overallCost = 0;
  IloGranularFunction costFunction(env, 0, horizon);
  for(day=0; day<horizon; day+=1) {
    costFunction.setValue(day, day+1, overallCost);
    if (day<3) dailyCost = 1000.0;
    else if (day<7) dailyCost = 900.0;
    else dailyCost = 700.0;
    overallCost += dailyCost;
  }

Once the granular function is built, we constrain each activity's external variable to be equal to the total cost incurred due to the activity's duration, and add this constraint to the model.

  model.add( IloResourceFunctionalConstraint(worker,
                                             IloExternalVariable,
                                             costFunction,
                                             IloDurationVariable) );