IBM ILOG Dispatcher User's Manual > The Basics > Minimizing the Number of Vehicles > Model > Define the addDimensions function

The member function addDimensions is used to create the two dimensions, _weight and _time, and add them to the model. The weight dimension is created in the same way as in Chapter 2, Modeling a Vehicle Routing Problem. This code is provided for you:

void RoutingModel::addDimensions() {
  _weight =IloDimension1 (_env, "weight");
  _mdl.add(_weight);

The time is computed from the road network graph. The dimension _time is an instance of the subclass IloDimension2. The constructor for IloDimension2 takes three parameters: the environment, a distance function, and a name used for debug and trace purposes. In this lesson, the distance function is SP_time. This is the shortest path in time computed from the road network graph. To create SP_time, you use the function IloGraphDistance, which returns an instance of IloDistance for which the distance--or time--between two nodes for a specified vehicle is the value of the shortest path between the two nodes using the specified vehicle.

Step 5   -  

Create the time dimension and add to model

Add the following code after the comment
//Create the time dimension and add to model

  IloDistance SP_time =   IloGraphDistance (_graph);
  _time  =IloDimension2 (_env, SP_time, "time");
  _mdl.add(_time);
}

In this example, you could also use the predefined distance functions IloEuclidean or IloManhattan or define your own distance function.