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

You use csv reader functionality to input depot data from csv files. For each of the depots, you get the number of trucks per depot (nbOfTrucks), its coordinates (x and y), and its opening and closing times (openTime and closeTime). An array of pointers to class type Depot are created. This array is then populated by a loop that creates the depots. For each depot, the function Depot::createVehicles is called to create the vehicles associated with each depot and the model containing all dimensions _dimModel is added to the depot model. Finally, each depot model is added to the model of the whole problem _mdl.

Step 10   -  

Create the depot

Add the following code after the comment //Create the depot

void RoutingModel::createDepots(const char* depotPath) {
  IloCsvReader depotReader(_env, depotPath);
  _nbOfDepots = depotReader.getNumberOfItems();
  _depots = new (_env) Depot* [ _nbOfDepots ];

  IloInt depotIndex = 0;
  for (IloCsvReader::LineIterator it(depotReader); it.ok(); ++it, ++depotIndex) 
{
    IloCsvLine line = *it;
    const char* name = line.getStringByHeader("name");
    IloNum x = line.getFloatByHeader("x");
    IloNum y = line.getFloatByHeader("y");
    IloNum openTime   = line.getFloatByHeader("openTime");
    IloNum closeTime  = line.getFloatByHeader("closeTime");
    IloInt nbOfTrucks = line.getIntByHeader("nbOfTrucks");
    IloInt capacity   = line.getIntByHeader("capacity");

    Depot* depot =
      new (_env) Depot(_env, name, x, y, nbOfTrucks, capacity, openTime, 
closeTime);
    _depots[ depotIndex ] = depot;
  }
  depotReader.end();
  IloInt d;
  for (d=0; d < _nbOfDepots; ++d) {
    Depot* depot = _depots[d];
    depot->createVehicles(_time, _length, _weight);
    depot->add(_dimModel);
    _mdl.add(depot->getModel());
  }

}