IBM ILOG Dispatcher User's Manual > The Basics > Modeling a Vehicle Routing Problem > Model > Define the addDimensions function |
Define the addDimensions function |
INDEX
![]() |
The member function addDimensions
is used to create the three dimensions--weight, time, and distance--and add them to the model. You must explicitly add the dimensions to the model or Solver will not be able to use them in the search for a solution.
The following code is provided for you:
void RoutingModel::addDimensions() { |
Next, you create the weight dimension.
Step 3 - | Create the weight dimension and add to model |
Add the following code after the comment //Create the weight dimension and add to model
_weight =IloDimension1 (_env, "weight"); _mdl.add(_weight); |
The dimension _weight
is an instance of the subclass IloDimension1
. Weight is a dimension that is intrinsic to an object and depends only on that object. For example, a vehicle can carry a certain amount of weight or a visit can require a vehicle to drop off or pick up a certain amount of weight. The constructor for IloDimension1
used in this lesson takes two parameters: the environment and a name used for debug and trace purposes.
Now, you create the time and distance dimensions.
Step 4 - | Create the time and distance dimensions and add to model |
Add the following code after the comment //Create the time and distance dimensions and add to model
_time =IloDimension2 (_env, IloEuclidean, "time"); _mdl.add(_time); _distance =IloDimension2 (_env, IloEuclidean, "distance"); _mdl.add(_distance); } |
The dimensions _time
and _distance
are instances of the subclass IloDimension2
. Time and distance are both extrinsic to an object--they depend on something outside the object itself. For example, the time to travel from one visit to another depends on both those visits. The constructor for IloDimension2
used in this lesson takes three parameters: the environment, a distance function, and a name used for debug and trace purposes. The distance function used is IloEuclidean
, a predefined distance function that returns the Euclidean distance between two locations. You can also use the predefined distance function IloManhattan
, which computes the grid distance between locations. You can obtain distances from a graph using IloDispatcherGraph
functionality (more on this in Chapter 4, Minimizing the Number of Vehicles) or define your own distance functions.
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |