Exemplo n.º 1
0
  public void read(String solomonFile) {
    vrpBuilder.setFleetSize(FleetSize.INFINITE);
    BufferedReader reader = getReader(solomonFile);
    int vehicleCapacity = 0;

    int counter = 0;
    String line;
    while ((line = readLine(reader)) != null) {
      line = line.replace("\r", "");
      line = line.trim();
      String[] tokens = line.split(" +");
      counter++;
      if (counter == 5) {
        vehicleCapacity = Integer.parseInt(tokens[1]);
        continue;
      }
      if (counter > 9) {
        if (tokens.length < 7) continue;
        Coordinate coord = makeCoord(tokens[1], tokens[2]);
        String customerId = tokens[0];
        int demand = Integer.parseInt(tokens[3]);
        double start = Double.parseDouble(tokens[4]) * timeProjectionFactor;
        double end = Double.parseDouble(tokens[5]) * timeProjectionFactor;
        double serviceTime = Double.parseDouble(tokens[6]) * timeProjectionFactor;
        if (counter == 10) {
          VehicleTypeImpl.Builder typeBuilder =
              VehicleTypeImpl.Builder.newInstance("solomonType")
                  .addCapacityDimension(0, vehicleCapacity);
          typeBuilder
              .setCostPerDistance(1.0 * variableCostProjectionFactor)
              .setFixedCost(fixedCostPerVehicle);
          VehicleTypeImpl vehicleType = typeBuilder.build();

          VehicleImpl vehicle =
              VehicleImpl.Builder.newInstance("solomonVehicle")
                  .setEarliestStart(start)
                  .setLatestArrival(end)
                  .setStartLocation(
                      Location.Builder.newInstance().setId(customerId).setCoordinate(coord).build())
                  .setType(vehicleType)
                  .build();
          vrpBuilder.addVehicle(vehicle);

        } else {
          Service service =
              new Service.Builder(customerId)
                  .addSizeDimension(0, demand)
                  .setLocation(
                      Location.Builder.newInstance().setCoordinate(coord).setId(customerId).build())
                  .setServiceTime(serviceTime)
                  .setTimeWindow(TimeWindow.newInstance(start, end))
                  .build();
          vrpBuilder.addJob(service);
        }
      }
    }
    close(reader);
  }
Exemplo n.º 2
0
 private void buildShipments() {
   Integer counter = 0;
   for (Relation rel : relations) {
     counter++;
     String from = rel.from;
     String to = rel.to;
     int demand = rel.demand;
     Shipment s =
         Shipment.Builder.newInstance(counter.toString())
             .addSizeDimension(0, demand)
             .setPickupLocation(
                 Location.Builder.newInstance().setCoordinate(customers.get(from).coord).build())
             .setPickupServiceTime(customers.get(from).serviceTime)
             .setPickupTimeWindow(
                 TimeWindow.newInstance(customers.get(from).start, customers.get(from).end))
             .setDeliveryLocation(
                 Location.Builder.newInstance().setCoordinate(customers.get(to).coord).build())
             .setDeliveryServiceTime(customers.get(to).serviceTime)
             .setDeliveryTimeWindow(
                 TimeWindow.newInstance(customers.get(to).start, customers.get(to).end))
             .build();
     vrpBuilder.addJob(s);
   }
 }
Exemplo n.º 3
0
 public void read(String filename) {
   readShipments(filename);
   buildShipments();
   VehicleTypeImpl type =
       VehicleTypeImpl.Builder.newInstance("type")
           .addCapacityDimension(0, vehicleCapacity)
           .setCostPerDistance(1.0)
           .setFixedCost(fixCosts)
           .build();
   VehicleImpl vehicle =
       VehicleImpl.Builder.newInstance("vehicle")
           .setEarliestStart(depotOpeningTime)
           .setLatestArrival(depotClosingTime)
           .setStartLocation(
               Location.Builder.newInstance().setCoordinate(customers.get(depotId).coord).build())
           .setType(type)
           .build();
   vrpBuilder.addVehicle(vehicle);
 }
 private static Location loc(Coordinate coordinate) {
   return Location.Builder.newInstance().setCoordinate(coordinate).build();
 }