/**
  * filters test based on given filterKey/filterValue. If the any of the filter key/value pairs
  * found from data object, then returns true.
  *
  * @param data test data
  * @return true if test is selected after applying filter, false otherwise
  */
 private boolean checkAgainstFilterProperties(
     HierarchicalConfiguration data, HierarchicalConfiguration context) {
   boolean included = true;
   String filterKeys[] = null;
   String filterValues[] = null;
   if (context.containsKey(ARG_FILTER_KEY)
       && !context.getString(ARG_FILTER_KEY).trim().equals("")) {
     filterKeys = context.getStringArray(ARG_FILTER_KEY);
     filterValues = context.getStringArray(ARG_FILTER_VALUE);
   } else if (DDConfig.getSingleton().getData().containsKey(ARG_FILTER_KEY)
       && !DDConfig.getSingleton().getData().getString(ARG_FILTER_KEY).trim().equals("")) {
     filterKeys = DDConfig.getSingleton().getData().getStringArray(ARG_FILTER_KEY);
     filterValues = DDConfig.getSingleton().getData().getStringArray(ARG_FILTER_VALUE);
   }
   if (filterKeys != null && filterValues != null) {
     included = false;
     for (int index = 0; index < filterKeys.length; index++) {
       String filterKey = filterKeys[index];
       String filterValue = null;
       if (index >= filterValues.length) {
         filterValue = "";
       } else {
         filterValue = filterValues[index];
       }
       if (data.containsKey(filterKey) && data.getString(filterKey, "").equals(filterValue)) {
         included = true;
         break;
       }
     }
   }
   return included;
 }
  private boolean isDeprecated(String key) {
    final String pathToDeprecatedAttribute = key + "/deprecated";
    if (!keysConfig.containsKey(pathToDeprecatedAttribute)) {
      return false;
    }

    final List list = keysConfig.getList(pathToDeprecatedAttribute);
    if (list.size() != 1) {
      throw new IllegalArgumentException(
          "Configuration error; Key \"" + key + "\" has ambiguous definition.");
    }

    final Object value = list.iterator().next();
    try {
      return Boolean.parseBoolean((String) value);
    } catch (ClassCastException e) {
      throw new IllegalArgumentException(
          "Configuration error;"
              + " Key \""
              + key
              + "\" should be either 'true' or 'false'. Value '"
              + value
              + "' is not valid.");
    }
  }
Esempio n. 3
0
  @SuppressWarnings("deprecation")
  public static InsertionStrategy createInsertion(
      VehicleRoutingProblem vrp,
      HierarchicalConfiguration config,
      VehicleFleetManager vehicleFleetManager,
      StateManager stateManager,
      List<PrioritizedVRAListener> algorithmListeners,
      ExecutorService executorService,
      int nuOfThreads,
      ConstraintManager constraintManager,
      boolean addDefaultCostCalculators) {

    if (config.containsKey("[@name]")) {
      String insertionName = config.getString("[@name]");
      if (!insertionName.equals("bestInsertion")
          && !insertionName.equals("regretInsertion")
          && !insertionName.equals("fixedBestInsertion")
          && !insertionName.equals("firstFixedBestInsertion")
          && !insertionName.equals("fixedRegretInsertion")) {
        throw new IllegalStateException(
            insertionName
                + " is not supported. use either \"bestInsertion\" or \"regretInsertion\"");
      }

      InsertionBuilder iBuilder =
          new InsertionBuilder(vrp, vehicleFleetManager, stateManager, constraintManager);

      if (executorService != null) {
        iBuilder.setConcurrentMode(executorService, nuOfThreads);
      }

      if (config.containsKey("level")) {
        String level = config.getString("level");
        if (level.equals("local")) {
          iBuilder.setLocalLevel(addDefaultCostCalculators);
        } else if (level.equals("route")) {
          int forwardLooking = 0;
          int memory = 1;
          String forward = config.getString("level[@forwardLooking]");
          String mem = config.getString("level[@memory]");
          if (forward != null) forwardLooking = Integer.parseInt(forward);
          else
            log.warn(
                "parameter route[@forwardLooking] is missing. by default it is 0 which equals to local level");
          if (mem != null) memory = Integer.parseInt(mem);
          else log.warn("parameter route[@memory] is missing. by default it is 1");
          iBuilder.setRouteLevel(forwardLooking, memory, addDefaultCostCalculators);
        } else
          throw new IllegalStateException(
              "level " + level + " is not known. currently it only knows \"local\" or \"route\"");
      } else iBuilder.setLocalLevel(addDefaultCostCalculators);

      if (config.containsKey("considerFixedCosts") || config.containsKey("considerFixedCost")) {
        if (addDefaultCostCalculators) {
          String val = config.getString("considerFixedCosts");
          if (val == null) val = config.getString("considerFixedCost");
          if (val.equals("true")) {
            double fixedCostWeight = 0.5;
            String weight = config.getString("considerFixedCosts[@weight]");
            if (weight == null) weight = config.getString("considerFixedCost[@weight]");
            if (weight != null) fixedCostWeight = Double.parseDouble(weight);
            else
              throw new IllegalStateException(
                  "fixedCostsParameter 'weight' must be set, e.g. <considerFixedCosts weight=1.0>true</considerFixedCosts>.\n"
                      + "this has to be changed in algorithm-config-xml-file.");
            iBuilder.considerFixedCosts(fixedCostWeight);
          } else if (val.equals("false")) {

          } else
            throw new IllegalStateException(
                "considerFixedCosts must either be true or false, i.e. <considerFixedCosts weight=1.0>true</considerFixedCosts> or \n<considerFixedCosts weight=1.0>false</considerFixedCosts>. "
                    + "if latter, you can also omit the tag. this has to be changed in algorithm-config-xml-file");
        }
      }
      String timeSliceString = config.getString("experimental[@timeSlice]");
      String neighbors = config.getString("experimental[@neighboringSlices]");
      if (timeSliceString != null && neighbors != null) {
        iBuilder.experimentalTimeScheduler(
            Double.parseDouble(timeSliceString), Integer.parseInt(neighbors));
      }
      String allowVehicleSwitch = config.getString("allowVehicleSwitch");
      if (allowVehicleSwitch != null) {
        iBuilder.setAllowVehicleSwitch(Boolean.parseBoolean(allowVehicleSwitch));
      }

      if (insertionName.equals("regretInsertion")) {
        iBuilder.setInsertionStrategy(InsertionBuilder.Strategy.REGRET);
      } else if (insertionName.equals("fixedBestInsertion")) {
        iBuilder.setInsertionStrategy(InsertionBuilder.Strategy.FIXEDBEST);
      } else if (insertionName.equals("firstFixedBestInsertion")) {
        iBuilder.setInsertionStrategy(InsertionBuilder.Strategy.FIRSTFIXEDBEST);
      } else if (insertionName.equals("fixedRegretInsertion")) {
        iBuilder.setInsertionStrategy(InsertionBuilder.Strategy.FIXEDREGRET);
      }
      return iBuilder.build();
    } else
      throw new IllegalStateException("cannot create insertionStrategy, since it has no name.");
  }
Esempio n. 4
0
  private void readVehiclesAndTheirTypes(XMLConfiguration vrpProblem) {

    // read vehicle-types
    Map<String, VehicleType> types = new HashMap<String, VehicleType>();
    List<HierarchicalConfiguration> typeConfigs = vrpProblem.configurationsAt("vehicleTypes.type");
    for (HierarchicalConfiguration typeConfig : typeConfigs) {
      String typeId = typeConfig.getString("id");
      if (typeId == null) throw new IllegalStateException("typeId is missing.");

      String capacityString = typeConfig.getString("capacity");
      boolean capacityDimensionsExist = typeConfig.containsKey("capacity-dimensions.dimension(0)");
      if (capacityString == null && !capacityDimensionsExist) {
        throw new IllegalStateException("capacity of type 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'.");
      }

      VehicleTypeImpl.Builder typeBuilder;
      if (capacityString != null) {
        typeBuilder =
            VehicleTypeImpl.Builder.newInstance(typeId)
                .addCapacityDimension(0, Integer.parseInt(capacityString));
      } else {
        typeBuilder = VehicleTypeImpl.Builder.newInstance(typeId);
        List<HierarchicalConfiguration> dimensionConfigs =
            typeConfig.configurationsAt("capacity-dimensions.dimension");
        for (HierarchicalConfiguration dimension : dimensionConfigs) {
          Integer index = dimension.getInt("[@index]");
          Integer value = dimension.getInt("");
          typeBuilder.addCapacityDimension(index, value);
        }
      }
      Double fix = typeConfig.getDouble("costs.fixed");
      Double timeC = typeConfig.getDouble("costs.time");
      Double distC = typeConfig.getDouble("costs.distance");

      if (fix != null) typeBuilder.setFixedCost(fix);
      if (timeC != null) typeBuilder.setCostPerTime(timeC);
      if (distC != null) typeBuilder.setCostPerDistance(distC);
      VehicleType type = typeBuilder.build();
      String id = type.getTypeId();
      String penalty = typeConfig.getString("[@type]");
      if (penalty != null) {
        if (penalty.equals("penalty")) {
          String penaltyFactor = typeConfig.getString("[@penaltyFactor]");
          if (penaltyFactor != null) {
            type = new PenaltyVehicleType(type, Double.parseDouble(penaltyFactor));
          } else type = new PenaltyVehicleType(type);
          id = id + "_penalty";
        }
      }

      types.put(id, type);
    }

    // read vehicles
    List<HierarchicalConfiguration> vehicleConfigs =
        vrpProblem.configurationsAt("vehicles.vehicle");
    boolean doNotWarnAgain = false;
    for (HierarchicalConfiguration vehicleConfig : vehicleConfigs) {
      String vehicleId = vehicleConfig.getString("id");
      if (vehicleId == null) throw new IllegalStateException("vehicleId is missing.");
      Builder builder = VehicleImpl.Builder.newInstance(vehicleId);
      String typeId = vehicleConfig.getString("typeId");
      if (typeId == null) throw new IllegalStateException("typeId is missing.");
      String vType = vehicleConfig.getString("[@type]");
      if (vType != null) {
        if (vType.equals("penalty")) {
          typeId += "_penalty";
        }
      }
      VehicleType type = types.get(typeId);
      if (type == null)
        throw new IllegalStateException("vehicleType with typeId " + typeId + " is missing.");
      builder.setType(type);
      String locationId = vehicleConfig.getString("location.id");
      if (locationId == null) {
        locationId = vehicleConfig.getString("startLocation.id");
      }
      if (locationId == null) throw new IllegalStateException("location.id is missing.");
      builder.setStartLocationId(locationId);
      String coordX = vehicleConfig.getString("location.coord[@x]");
      String coordY = vehicleConfig.getString("location.coord[@y]");
      if (coordX == null || coordY == null) {
        coordX = vehicleConfig.getString("startLocation.coord[@x]");
        coordY = vehicleConfig.getString("startLocation.coord[@y]");
      }
      if (coordX == null || coordY == null) {
        if (!doNotWarnAgain) {
          logger.warn("location.coord is missing. will not warn you again.");
          doNotWarnAgain = true;
        }
      } else {
        Coordinate coordinate =
            Coordinate.newInstance(Double.parseDouble(coordX), Double.parseDouble(coordY));
        builder.setStartLocationCoordinate(coordinate);
      }

      String endLocationId = vehicleConfig.getString("endLocation.id");
      if (endLocationId != null) builder.setEndLocationId(endLocationId);
      String endCoordX = vehicleConfig.getString("endLocation.coord[@x]");
      String endCoordY = vehicleConfig.getString("endLocation.coord[@y]");
      if (endCoordX == null || endCoordY == null) {
        if (!doNotWarnAgain) {
          logger.warn("endLocation.coord is missing. will not warn you again.");
          doNotWarnAgain = true;
        }
      } else {
        Coordinate coordinate =
            Coordinate.newInstance(Double.parseDouble(endCoordX), Double.parseDouble(endCoordY));
        builder.setEndLocationCoordinate(coordinate);
      }

      String start = vehicleConfig.getString("timeSchedule.start");
      String end = vehicleConfig.getString("timeSchedule.end");
      if (start != null) builder.setEarliestStart(Double.parseDouble(start));
      if (end != null) builder.setLatestArrival(Double.parseDouble(end));
      String returnToDepot = vehicleConfig.getString("returnToDepot");
      if (returnToDepot != null) {
        builder.setReturnToDepot(vehicleConfig.getBoolean("returnToDepot"));
      }
      VehicleImpl vehicle = builder.build();
      vrpBuilder.addVehicle(vehicle);
      vehicleMap.put(vehicleId, vehicle);
    }
  }
Esempio n. 5
0
  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);

    }
  }
Esempio n. 6
0
  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);
    }
  }