IBM ILOG Dispatcher User's Manual > Transportation Industry Solutions > Adding Early and Late Costs > Model

Once you have written a description of your problem, you can use Dispatcher classes to model it.

Step 2   -  

Open the example file

Open the example file YourDispatcherHome/examples/src/tutorial/earlytardy_partial.cpp in your development environment.

The problem in this lesson is the same as the PDP problem in Chapter 8 that you have already worked with, except that costs are added for early and late deliveries.

The early and tardy costs are added in the function createVisits.

Step 3   -  

Add the early and tardy costs

Add the following code after the comment //Add the early and tardy costs.

  IloInt earlyCost = 5;
  IloInt tardyCost = 10;

The integer variables earlyCost and tardyCost are used later by IloEarlinessFunction and IloTardinessFunction to compute the cost of the delivery schedules.

Step 4   -  

Add the earliness and tardiness functions

l

Add the following code after the comment
//Add the earliness and tardiness functions.

    pickup.setStartCost(time,
                        IloEarlinessFunction(_env,
                                             pickupMinTime, earlyCost)
                        + IloTardinessFunction(_env,
                                               pickupMaxTime, tardyCost));

IloEarlinessFunction is used to compute the total cost of an early pickup time from the earlyCost variable and the amount of time that the delivery is early. IloTardinessFunction similarily computes the tardy cost. The output of these two functions is added together to compute the cost of the pickup visit. The total cost is then assigned to the pickup visit with the member function setStartCost. setStartCost is used (as opposed to setEndCost) to express the fact that the cost will be a function of the cumul variable (as opposed to the endCumul variable).

This process is also performed for every delivery visit.

    delivery.setStartCost(time,
                          IloEarlinessFunction(_env,
                                               deliveryMinTime, earlyCost)
                          + IloTardinessFunction(_env,
                                                 deliveryMaxTime, tardyCost));

The remainder of the modeling code is the same or similar to pdp.cpp, presented in Chapter 7, Pickup and Delivery Problems.