コード例 #1
0
ファイル: ServiceTest.java プロジェクト: aflanagan/jsprit
 @Test
 public void whenSettingTimeWindow_itShouldBeSetCorrectly() {
   Service s =
       Service.Builder.newInstance("s")
           .setLocationId("loc")
           .setTimeWindow(TimeWindow.newInstance(1.0, 2.0))
           .build();
   assertEquals(1.0, s.getTimeWindow().getStart(), 0.01);
   assertEquals(2.0, s.getTimeWindow().getEnd(), 0.01);
 }
コード例 #2
0
ファイル: VrpXMLReader.java プロジェクト: heerad/jsprit
  private void readServices(XMLConfiguration vrpProblem) {
    List<HierarchicalConfiguration> serviceConfigs =
        vrpProblem.configurationsAt("services.service");
    for (HierarchicalConfiguration serviceConfig : serviceConfigs) {
      String id = serviceConfig.getString("[@id]");
      if (id == null) throw new IllegalStateException("service[@id] is missing.");
      String type = serviceConfig.getString("[@type]");
      if (type == null) type = "service";

      String capacityString = serviceConfig.getString("capacity-demand");
      boolean capacityDimensionsExist =
          serviceConfig.containsKey("capacity-dimensions.dimension(0)");
      if (capacityString == null && !capacityDimensionsExist) {
        throw new IllegalStateException(
            "capacity of service is not set. use 'capacity-dimensions'");
      }
      if (capacityString != null && capacityDimensionsExist) {
        throw new IllegalStateException(
            "either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'.");
      }

      Service.Builder builder;
      if (capacityString != null) {
        builder = serviceBuilderFactory.createBuilder(type, id, Integer.parseInt(capacityString));
      } else {
        builder = serviceBuilderFactory.createBuilder(type, id, null);
        List<HierarchicalConfiguration> dimensionConfigs =
            serviceConfig.configurationsAt("capacity-dimensions.dimension");
        for (HierarchicalConfiguration dimension : dimensionConfigs) {
          Integer index = dimension.getInt("[@index]");
          Integer value = dimension.getInt("");
          builder.addSizeDimension(index, value);
        }
      }
      String serviceLocationId = serviceConfig.getString("locationId");
      if (serviceLocationId != null) builder.setLocationId(serviceLocationId);
      Coordinate serviceCoord = getCoord(serviceConfig, "");
      if (serviceCoord != null) {
        builder.setCoord(serviceCoord);
        if (serviceLocationId != null) {
          //					vrpBuilder.addLocation(serviceLocationId,serviceCoord);
        } else {
          //					vrpBuilder.addLocation(serviceCoord.toString(),serviceCoord);
          builder.setLocationId(serviceCoord.toString());
        }
      }
      if (serviceConfig.containsKey("duration")) {
        builder.setServiceTime(serviceConfig.getDouble("duration"));
      }
      List<HierarchicalConfiguration> deliveryTWConfigs =
          serviceConfig.configurationsAt("timeWindows.timeWindow");
      if (!deliveryTWConfigs.isEmpty()) {
        for (HierarchicalConfiguration twConfig : deliveryTWConfigs) {
          builder.setTimeWindow(
              TimeWindow.newInstance(twConfig.getDouble("start"), twConfig.getDouble("end")));
        }
      }
      Service service = builder.build();
      serviceMap.put(service.getId(), service);
      //			vrpBuilder.addJob(service);

    }
  }
コード例 #3
0
ファイル: VrpXMLReader.java プロジェクト: heerad/jsprit
  private void readShipments(XMLConfiguration config) {
    List<HierarchicalConfiguration> shipmentConfigs = config.configurationsAt("shipments.shipment");
    for (HierarchicalConfiguration shipmentConfig : shipmentConfigs) {
      String id = shipmentConfig.getString("[@id]");
      if (id == null) throw new IllegalStateException("shipment[@id] is missing.");

      String capacityString = shipmentConfig.getString("capacity-demand");
      boolean capacityDimensionsExist =
          shipmentConfig.containsKey("capacity-dimensions.dimension(0)");
      if (capacityString == null && !capacityDimensionsExist) {
        throw new IllegalStateException(
            "capacity of shipment is not set. use 'capacity-dimensions'");
      }
      if (capacityString != null && capacityDimensionsExist) {
        throw new IllegalStateException(
            "either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'.");
      }

      Shipment.Builder builder;
      if (capacityString != null) {
        builder =
            Shipment.Builder.newInstance(id).addSizeDimension(0, Integer.parseInt(capacityString));
      } else {
        builder = Shipment.Builder.newInstance(id);
        List<HierarchicalConfiguration> dimensionConfigs =
            shipmentConfig.configurationsAt("capacity-dimensions.dimension");
        for (HierarchicalConfiguration dimension : dimensionConfigs) {
          Integer index = dimension.getInt("[@index]");
          Integer value = dimension.getInt("");
          builder.addSizeDimension(index, value);
        }
      }

      // pickup-locationId
      String pickupLocationId = shipmentConfig.getString("pickup.locationId");
      if (pickupLocationId != null) {
        builder.setPickupLocation(pickupLocationId);
      }

      // pickup-coord
      Coordinate pickupCoord = getCoord(shipmentConfig, "pickup.");
      if (pickupCoord != null) {
        builder.setPickupCoord(pickupCoord);
        if (pickupLocationId != null) {
          //					vrpBuilder.addLocation(pickupLocationId,pickupCoord);
        } else {
          //					vrpBuilder.addLocation(pickupCoord.toString(),pickupCoord);
          builder.setPickupLocation(pickupCoord.toString());
        }
      }
      // pickup-serviceTime
      String pickupServiceTime = shipmentConfig.getString("pickup.duration");
      if (pickupServiceTime != null)
        builder.setPickupServiceTime(Double.parseDouble(pickupServiceTime));

      // pickup-tw
      String pickupTWStart = shipmentConfig.getString("pickup.timeWindows.timeWindow(0).start");
      String pickupTWEnd = shipmentConfig.getString("pickup.timeWindows.timeWindow(0).end");
      if (pickupTWStart != null && pickupTWEnd != null) {
        TimeWindow pickupTW =
            TimeWindow.newInstance(
                Double.parseDouble(pickupTWStart), Double.parseDouble(pickupTWEnd));
        builder.setPickupTimeWindow(pickupTW);
      }

      // delivery-locationId
      String deliveryLocationId = shipmentConfig.getString("delivery.locationId");
      if (deliveryLocationId != null) {
        builder.setDeliveryLocation(deliveryLocationId);
      }

      // delivery-coord
      Coordinate deliveryCoord = getCoord(shipmentConfig, "delivery.");
      if (deliveryCoord != null) {
        builder.setDeliveryCoord(deliveryCoord);
        if (deliveryLocationId != null) {
          //					vrpBuilder.addLocation(deliveryLocationId,deliveryCoord);
        } else {
          //					vrpBuilder.addLocation(deliveryCoord.toString(),deliveryCoord);
          builder.setDeliveryLocation(deliveryCoord.toString());
        }
      }
      // delivery-serviceTime
      String deliveryServiceTime = shipmentConfig.getString("delivery.duration");
      if (deliveryServiceTime != null)
        builder.setDeliveryServiceTime(Double.parseDouble(deliveryServiceTime));

      // delivery-tw
      String delTWStart = shipmentConfig.getString("delivery.timeWindows.timeWindow(0).start");
      String delTWEnd = shipmentConfig.getString("delivery.timeWindows.timeWindow(0).end");
      if (delTWStart != null && delTWEnd != null) {
        TimeWindow delTW =
            TimeWindow.newInstance(Double.parseDouble(delTWStart), Double.parseDouble(delTWEnd));
        builder.setDeliveryTimeWindow(delTW);
      }

      Shipment shipment = builder.build();
      //			vrpBuilder.addJob(shipment);
      shipmentMap.put(shipment.getId(), shipment);
    }
  }