IBM ILOG Dispatcher User's Manual > The Basics > Minimizing the Number of Vehicles > Model > Define the createVisits function

You create visits in the same way you did in Chapter 2, Modeling a Vehicle Routing Problem, except that you set a penalty cost for not performing a visit. You use csv reader functionality to input visit data from a csv file. A visit must be associated to a node, its location. A visit also has a quantity--the amount of goods delivered to the location. A visit can have a minimum time and a maximum time during which it can be performed--a time window. Additionally, visits have a drop time--the amount time required to perform the visit. These side constraints are modeled using the dimensions _time and _weight and the delay, transit, and cumulative variables associated with the visit.

You use the member function IloVisit::setPenaltyCost to set the cost of not performing a visit to 1000 cost units. This allows the visit to not be performed. During the solution improvement phase of problem solving, you will want to be able to allow some visits to be temporarily unperformed. The penalty cost allows you to do this. See the section "Solve" for more information.

Step 7   -  

Set the penalty cost on unperformed visits

Add the following code after the comment
//Set the penalty cost on unperformed visits

    visit.setPenaltyCost(1000);

Here is the complete code defining the createVisits function:

void RoutingModel::createVisits(char* visitsFileName) {
  IloCsvReader csvVisitReader(_env, visitsFileName);
  IloCsvReader::LineIterator  it(csvVisitReader);
  while(it.ok()){
    IloCsvLine line = *it;
    //read visit data from files
    char * visitName =  line.getStringByHeader("name");
    char * nodeName = line.getStringByHeader("node");
    IloNum quantity = line.getFloatByHeader("quantity");
    IloNum minTime  = line.getFloatByHeader("minTime");
    IloNum maxTime  = line.getFloatByHeader("maxTime");
    IloNum dropTime = line.getFloatByHeader("dropTime");
    IloNode node = IloNode::Find(_env, nodeName);
    IloVisit visit(node, visitName);
    _mdl.add(visit.getDelayVar(_time) == dropTime);
    _mdl.add(visit.getTransitVar(_weight) == quantity);
    _mdl.add(minTime <= visit.getCumulVar(_time) <= maxTime);
    _mdl.add(visit);

    visit.setPenaltyCost(1000);

    ++it;
  }
  csvVisitReader.end();
}