IBM ILOG Dispatcher User's Manual > Field Service Solutions > CARP: Visiting Arcs Using Multiple Vehicles > Model |
Model |
INDEX
![]() |
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/carp_partial.cpp
in your development environment.
As in the previous lessons, you will use a RoutingModel
class to call the functions that create the dimensions, nodes, vehicles, and visits. For this example, RoutingModel
also calls a function to create the graph that represents the road network.
Step 3 - | Declare the RoutingModel class |
Add the following code after the comment //Declare the RoutingModel class.
An instance of IloDispatcherGraph
is declared (_graph
); this instance is used to create a road network of nodes. It can then be used to compute and store the cheapest paths between nodes based on the cost functions for any given vehicle.
The function loadGraphInformation
is used to load and create the arcs and the arc costs that are stored in _graph
.
The remaining code of RoutingModel
is provided for you, and it calls a function (modifyGraphArcCost
) that allows you to modify the cost of an arc within the code itself, rather than in a csv data file.
The function RoutingModel:addDimensions
uses a shortest path calculation to represent the dimensions of time and distance in the graph network.
Step 4 - | Create the distance functions |
Add the following code after the comment //Create the distance functions
.
The shortest path time and distance functions (SP_time
and SP_distance
) are defined and added to the model (instead of the predefined functions IloEuclidian
and IloManhatten
that you have used before).
The next function creates the graph containing the arcs.
Step 5 - | Load the graph information |
Add the following code after the comment //Load the graph information
The member function IloDispatcherGraph::createArcsFromFile
loads the road network data from a csv file, and creates the necessary nodes and arcs. The member function IloDispatcherGraph::loadArcDimensionDataFromFile
loads the arc cost data from a csv file.
The function CreateIloNodes
includes a command to associate the IloNodes
to the graph nodes.
Step 6 - | Create the nodes |
Add the following code after the comment //Create the nodes
.
_graph.associateByCoordsInFile (node, coordFileName); |
Instances of IloNode
must be positioned within the graph. This can be done node-by-node with the method IloDispatcherGraph::setLocation
, but this becomes impractical with even modestly sized networks. Instead, in this lesson you use the method associateByCoordsInFile
to look up the coordinates of a given IloNode
in a csv file, and then automatically associate the node to the graph node with matching coordinates.
Next, you create the vehicles with a cost function that uses a cost ratio.
Step 7 - | Set the vehicle costs |
Add the following code after the comment //Set the vehicle costs
.
vehicle.setCost(_time, 100 * costRatio); vehicle.setCost(_distance, 100 * (1- costRatio)); vehicle.setCapacity(_weight, capacity); _mdl.add(vehicle); |
The following line of code appears earlier in the CreateVehicles
function:
IloNum costRatio = line.getFloatByHeader("costRatio"); |
The costRatio
is data from the vehicle csv file, and can be used, for example, to model vehicles that have different operating costs. Using different cost ratios for the different vehicles will change the solution paths; paths depend not only on the distance between nodes, but also on the way vehicle costs are calculated.
Next, the CreateVisits
function adds the actual arc visits to the model.
Step 8 - | Create the visits |
Add the following code after the comment //Create the visits
.
This code is the second part of the createVisits
function. The first part of the iteration reads in the nodes, time and distance values, and quantity
to be delivered per visit.
To create an arc visit rather than a visit to a single node, you provide two node names to the IloVisit
constructor. If the visit to the arc is symmetric
--that is, the cost to visit the arc is the same regardless of which node is visited first--then both possible paths for the arc visit are added to the model with zero penalty cost.
The constraint _mdl.add(visit1.performed() + visit2.performed() == 1)
states that just one of those two visits must be performed.
In problems of this type it may sometimes be desirable to be able to quickly modify the costs of certain paths, due to traffic or road conditions, experimental modeling, or other reasons. You may not want to edit your data files to model these factors; the function modifyGraphArcCost
is used for this purpose.
Step 9 - | Modify graph arc costs |
//Modify graph arc costs.
This function is used to quickly modify the cost of a few particular arcs. This may be appropriate if, for example, conditions merit a temporary increase in the cost of visiting an arc. The impact on the solution cost can be significant.
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |