IBM ILOG Dispatcher User's Manual > Transportation Industry Solutions > Modeling Complex Costs > Model cost2

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/cost2_partial.cpp in your development environment.

In this example, the cost function is added as an IloNumToNumSegmentFunction in the createVehicles function.

Step 3   -  

Add the vehicle cost function

Add the following code after the comment //Add the vehicle cost function.

    vehicle.setCost(distance, 1);
    IloNumToNumSegmentFunction costFunction(_env);
    costFunction.setSlope(75, 100, 37.5, 0.5);
    costFunction.setSlope(100, IloInfinity, 100, 1);
    vehicle.setCost(distance, costFunction);

First, a standard proportional cost is applied on the distance traveled (cost per unit distance is 1). Then, costFunction is created with a default value of 0. The member function setSlope is then used to change the value of the function, depending on the range given.