IBM ILOG Dispatcher User's Manual > The Basics > IBM ILOG Dispatcher Concepts > Model > Modeling costs and the objective

The total cost of a routing plan is determined by summing the total costs for all vehicles and adding any costs related to unperformed visits. The objective is usually to minimize the cost of the routing plan, though sometimes the objective may also include other goals, such as minimizing the number of vehicles (see Chapter 4, Minimizing the Number of Vehicles).

The cost variable of the entire routing plan can be obtained with IloDispatcher::getCostVar().

Costs associated with visits

Visits can have a penalty cost associated with them, which represents the cost of not performing the visit. Penalty costs can be expressed by the member function IloVisit::setPenaltyCost(penaltyCost). By default, this cost is set to IloInfinity, which means that the visit must be performed.

Costs associated with vehicles

The total cost of a vehicle is determined by summing the cost for each dimension specified for the vehicle and adding any fixed costs for that vehicle. If a fixed cost is specified, it is added to the cost of the vehicle if the vehicle is in use (that is, if the vehicle performs any visits other than its first and last visits). The cost variable of a vehicle can be obtained with the member function IloVehicle::getCostVar().

Cost can vary with many different dimensions: the distance traveled, the time spent, or the number of stops. Costs in Dispatcher are attached to vehicles via IloVehicle::setCost(IloDimension dim, IloNum unitCost). Fixed costs are expressed by the member function IloVehicle::setCost(fixedCost).

The following code shows how to express a cost in terms of distance.

IloEnv env;
IloModel mdl(env);
IloDimension2 distance(env, IloEuclidean); // in mi.
mdl.add(distance);
IloVehicle vehicle(env);
vehicle.setCost(distance, 3.2); // $ 3.2 per mile

The statement vehicle.setCost(distance, 3.2) means that for each unit of distance that the vehicle travels, 3.2 units of cost are accrued. Cost for the vehicle is computed by multiplying the usage variable of the dimension (in this case, distance) by the coefficient (3.2 in this case). If cost is specified in more than one dimension (for instance, time and distance), the cost for each dimension specified for the vehicle is computed in the same fashion.

Vehicle cost is bound as follows: the transit variables of all visits performed by the vehicle (including the first and last visits representing the start and end points of the vehicle), are added together to give the usage of the dimension for the vehicle. This usage is also reinforced by bounds computed from the cumulative variable at the last visit plus the transit variable at the last visit, minus the cumulative variable at the first visit, as follows. Suppose time is an IloDimension2:

IloVisit first = vehicle.getFirstVisit();
IloVisit last = vehicle.getLastVisit();
IloNumVar usage = last.getCumulVar(time) + last.getTransitVar(time) -
                    first.getCumulVar(time);

For more information on modeling costs, see Modeling Complex Costs.