IBM ILOG Dispatcher User's Manual > Transportation Industry Solutions > Modeling Complex Costs > Model cost1 |
Model cost1 |
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/cost1_partial.cpp
in your development environment.
This problem is modeled as for a PDP, with only the creation and addition of a cost coefficient function.
Step 3 - | Create the LastVisitCostCoef function |
Add the following code after the comment //Create the LastVisitCostCoef function
IloNum LastVisitCostCoef(IloVisit visit) { IloNode node = visit.getNode(); return ((IloInt)(node.getX()) % 5) + 1; } |
The LastVisitCostCoef
is a function of the type IloSimpleVisitToNumFunction
, and it creates the cost coefficient from the x-coordinate of visit
.
Next, you set the vehicle cost in the createVehicles
function.
Step 4 - | Add the cost function |
Add the following code after the comment //Add the cost function
.
IloVisitToNumFunction coefFunction(_env, LastVisitCostCoef); vehicle.setCost(distance, coefFunction, vehicle.getLastVisit().getPrevVar()); |
These lines in createVehicles
create the vehicle cost. coefFunction
is created as an IloVisitToNumFunction
which allows you to associate IloNum
values with visits.
The member function IloVehicle::setCost
is used here to associate a visit-dependent proportional cost with vehicle
. The parameter vehicle.getLastVisit().getPrevVar()
returns the location variable with which coefFunction
calculates the cost applied to distance
. Note that the visit returned by vehicle.getLastVisit().getPrevVar()
corresponds to the last customer visit performed before returning to the depot.
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |