IBM ILOG Dispatcher User's Manual > Transportation Industry Solutions > Pickup and Delivery by Multiple Vehicles from Multiple Depots > Model > Define the Depot::createOneVehicle function

You add a function to create a vehicle associated to the depot. The vehicles have first and last visits at their associated depot. You add side constraints that the vehicles must leave the depot after it opens and return to the depot before it closes. You set the capacity of the vehicle. The cost of each vehicle is set to be directly proportional to the dimension length.

Step 6   -  

Create one vehicle associated to the depot

Ad the following code after the comment
//Create one vehicle associated to the depot

IloVehicle Depot::createOneVehicle(IloInt vehicleIndex,
                                   IloDimension2 time,
                                   IloDimension2 length,
                                   IloDimension1 weight) {
  char namebuf[128];
  const char* depotName = getName();

  sprintf(namebuf, "Truck %ld leaving %s", vehicleIndex, depotName);
  IloVisit first(_node, namebuf);
  sprintf(namebuf, "Truck %ld returning to %s", vehicleIndex, depotName);
  IloVisit last (_node, namebuf);
  sprintf(namebuf, "Vehicle %ld of Depot %s", vehicleIndex, getName());
  IloVehicle vehicle(first, last, namebuf);
  vehicle.setCost(length, 1.0);
  vehicle.setCapacity(weight, _capacity);
  add(vehicle);
  add(first.getCumulVar(time) >= _openTime);
  add(last.getCumulVar(time)  <= _closeTime);
  last.getCumulVar(weight).setBounds(0,0);
  first.getCumulVar(length).setBounds(0,0);
  first.getDelayVar(length).setBounds(0,0);
  first.getWaitVar(length).setBounds(0,0);
  last.getDelayVar(length).setBounds(0,0);
  last.getWaitVar(length).setBounds(0,0);

  vehicle.setObject(this);
  return vehicle;
}