Example usage for org.apache.commons.configuration HierarchicalConfiguration getInt

List of usage examples for org.apache.commons.configuration HierarchicalConfiguration getInt

Introduction

In this page you can find the example usage for org.apache.commons.configuration HierarchicalConfiguration getInt.

Prototype

public int getInt(String key) 

Source Link

Usage

From source file:com.graphhopper.jsprit.core.problem.io.VrpXMLReader.java

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'");
        }//from   w w  w. j a v  a2  s  .  com
        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);
            }
        }

        //name
        String name = serviceConfig.getString("name");
        if (name != null)
            builder.setName(name);

        //location
        Location.Builder locationBuilder = Location.Builder.newInstance();
        String serviceLocationId = serviceConfig.getString("locationId");
        if (serviceLocationId == null) {
            serviceLocationId = serviceConfig.getString("location.id");
        }
        if (serviceLocationId != null)
            locationBuilder.setId(serviceLocationId);

        Coordinate serviceCoord = getCoord(serviceConfig, "");
        if (serviceCoord == null)
            serviceCoord = getCoord(serviceConfig, "location.");
        if (serviceCoord != null) {
            locationBuilder.setCoordinate(serviceCoord);
        }

        String locationIndex = serviceConfig.getString("location.index");
        if (locationIndex != null)
            locationBuilder.setIndex(Integer.parseInt(locationIndex));
        builder.setLocation(locationBuilder.build());

        if (serviceConfig.containsKey("duration")) {
            builder.setServiceTime(serviceConfig.getDouble("duration"));
        }
        List<HierarchicalConfiguration> deliveryTWConfigs = serviceConfig
                .configurationsAt("timeWindows.timeWindow");
        if (!deliveryTWConfigs.isEmpty()) {
            for (HierarchicalConfiguration twConfig : deliveryTWConfigs) {
                builder.addTimeWindow(
                        TimeWindow.newInstance(twConfig.getDouble("start"), twConfig.getDouble("end")));
            }
        }

        //read skills
        String skillString = serviceConfig.getString("requiredSkills");
        if (skillString != null) {
            String cleaned = skillString.replaceAll("\\s", "");
            String[] skillTokens = cleaned.split("[,;]");
            for (String skill : skillTokens)
                builder.addRequiredSkill(skill.toLowerCase());
        }

        //build service
        Service service = builder.build();
        serviceMap.put(service.getId(), service);
        //         vrpBuilder.addJob(service);

    }
}

From source file:jsprit.core.problem.io.VrpXMLReader.java

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'");
        }/*from w w w  . j  a v a2s. c o  m*/
        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);
            }
        }

        //name
        String name = serviceConfig.getString("name");
        if (name != null)
            builder.setName(name);

        //location
        Location.Builder locationBuilder = Location.Builder.newInstance();
        String serviceLocationId = serviceConfig.getString("locationId");
        if (serviceLocationId == null) {
            serviceLocationId = serviceConfig.getString("location.id");
        }
        if (serviceLocationId != null)
            locationBuilder.setId(serviceLocationId);

        Coordinate serviceCoord = getCoord(serviceConfig, "");
        if (serviceCoord == null)
            serviceCoord = getCoord(serviceConfig, "location.");
        if (serviceCoord != null) {
            locationBuilder.setCoordinate(serviceCoord);
        }

        String locationIndex = serviceConfig.getString("location.index");
        if (locationIndex != null)
            locationBuilder.setIndex(Integer.parseInt(locationIndex));
        builder.setLocation(locationBuilder.build());

        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")));
            }
        }

        //read skills
        String skillString = serviceConfig.getString("requiredSkills");
        if (skillString != null) {
            String cleaned = skillString.replaceAll("\\s", "");
            String[] skillTokens = cleaned.split("[,;]");
            for (String skill : skillTokens)
                builder.addRequiredSkill(skill.toLowerCase());
        }

        //build service
        Service service = builder.build();
        serviceMap.put(service.getId(), service);
        //         vrpBuilder.addJob(service);

    }
}

From source file:com.graphhopper.jsprit.io.problem.VrpXMLReader.java

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 IllegalArgumentException("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 IllegalArgumentException("capacity of service is not set. use 'capacity-dimensions'");
        }/*from   w w w. ja v a  2 s.  co  m*/
        if (capacityString != null && capacityDimensionsExist) {
            throw new IllegalArgumentException(
                    "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);
            }
        }

        //name
        String name = serviceConfig.getString("name");
        if (name != null)
            builder.setName(name);

        //location
        Location.Builder locationBuilder = Location.Builder.newInstance();
        String serviceLocationId = serviceConfig.getString("locationId");
        if (serviceLocationId == null) {
            serviceLocationId = serviceConfig.getString("location.id");
        }
        if (serviceLocationId != null)
            locationBuilder.setId(serviceLocationId);

        Coordinate serviceCoord = getCoord(serviceConfig, "");
        if (serviceCoord == null)
            serviceCoord = getCoord(serviceConfig, "location.");
        if (serviceCoord != null) {
            locationBuilder.setCoordinate(serviceCoord);
        }

        String locationIndex = serviceConfig.getString("location.index");
        if (locationIndex != null)
            locationBuilder.setIndex(Integer.parseInt(locationIndex));
        builder.setLocation(locationBuilder.build());

        if (serviceConfig.containsKey("duration")) {
            builder.setServiceTime(serviceConfig.getDouble("duration"));
        }
        List<HierarchicalConfiguration> deliveryTWConfigs = serviceConfig
                .configurationsAt("timeWindows.timeWindow");
        if (!deliveryTWConfigs.isEmpty()) {
            for (HierarchicalConfiguration twConfig : deliveryTWConfigs) {
                builder.addTimeWindow(
                        TimeWindow.newInstance(twConfig.getDouble("start"), twConfig.getDouble("end")));
            }
        }

        //read skills
        String skillString = serviceConfig.getString("requiredSkills");
        if (skillString != null) {
            String cleaned = skillString.replaceAll("\\s", "");
            String[] skillTokens = cleaned.split("[,;]");
            for (String skill : skillTokens)
                builder.addRequiredSkill(skill.toLowerCase());
        }

        //build service
        Service service = builder.build();
        serviceMap.put(service.getId(), service);
        //         vrpBuilder.addJob(service);

    }
}

From source file:com.graphhopper.jsprit.core.problem.io.VrpXMLReader.java

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'");
        }//  w  ww .j av a2  s .c om
        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);
            }
        }

        //name
        String name = shipmentConfig.getString("name");
        if (name != null)
            builder.setName(name);

        //pickup location
        //pickup-locationId
        Location.Builder pickupLocationBuilder = Location.Builder.newInstance();
        String pickupLocationId = shipmentConfig.getString("pickup.locationId");
        if (pickupLocationId == null)
            pickupLocationId = shipmentConfig.getString("pickup.location.id");
        if (pickupLocationId != null) {
            pickupLocationBuilder.setId(pickupLocationId);
        }

        //pickup-coord
        Coordinate pickupCoord = getCoord(shipmentConfig, "pickup.");
        if (pickupCoord == null)
            pickupCoord = getCoord(shipmentConfig, "pickup.location.");
        if (pickupCoord != null) {
            pickupLocationBuilder.setCoordinate(pickupCoord);
        }

        //pickup.location.index
        String pickupLocationIndex = shipmentConfig.getString("pickup.location.index");
        if (pickupLocationIndex != null)
            pickupLocationBuilder.setIndex(Integer.parseInt(pickupLocationIndex));
        builder.setPickupLocation(pickupLocationBuilder.build());

        //pickup-serviceTime
        String pickupServiceTime = shipmentConfig.getString("pickup.duration");
        if (pickupServiceTime != null)
            builder.setPickupServiceTime(Double.parseDouble(pickupServiceTime));

        //pickup-tw
        List<HierarchicalConfiguration> pickupTWConfigs = shipmentConfig
                .configurationsAt("pickup.timeWindows.timeWindow");
        if (!pickupTWConfigs.isEmpty()) {
            for (HierarchicalConfiguration pu_twConfig : pickupTWConfigs) {
                builder.addPickupTimeWindow(
                        TimeWindow.newInstance(pu_twConfig.getDouble("start"), pu_twConfig.getDouble("end")));
            }
        }

        //delivery location
        //delivery-locationId
        Location.Builder deliveryLocationBuilder = Location.Builder.newInstance();
        String deliveryLocationId = shipmentConfig.getString("delivery.locationId");
        if (deliveryLocationId == null)
            deliveryLocationId = shipmentConfig.getString("delivery.location.id");
        if (deliveryLocationId != null) {
            deliveryLocationBuilder.setId(deliveryLocationId);
            //            builder.setDeliveryLocationId(deliveryLocationId);
        }

        //delivery-coord
        Coordinate deliveryCoord = getCoord(shipmentConfig, "delivery.");
        if (deliveryCoord == null)
            deliveryCoord = getCoord(shipmentConfig, "delivery.location.");
        if (deliveryCoord != null) {
            deliveryLocationBuilder.setCoordinate(deliveryCoord);
        }

        String deliveryLocationIndex = shipmentConfig.getString("delivery.location.index");
        if (deliveryLocationIndex != null)
            deliveryLocationBuilder.setIndex(Integer.parseInt(deliveryLocationIndex));
        builder.setDeliveryLocation(deliveryLocationBuilder.build());

        //delivery-serviceTime
        String deliveryServiceTime = shipmentConfig.getString("delivery.duration");
        if (deliveryServiceTime != null)
            builder.setDeliveryServiceTime(Double.parseDouble(deliveryServiceTime));

        //delivery-tw
        List<HierarchicalConfiguration> deliveryTWConfigs = shipmentConfig
                .configurationsAt("delivery.timeWindows.timeWindow");
        if (!deliveryTWConfigs.isEmpty()) {
            for (HierarchicalConfiguration dl_twConfig : deliveryTWConfigs) {
                builder.addDeliveryTimeWindow(
                        TimeWindow.newInstance(dl_twConfig.getDouble("start"), dl_twConfig.getDouble("end")));
            }
        }

        //read skills
        String skillString = shipmentConfig.getString("requiredSkills");
        if (skillString != null) {
            String cleaned = skillString.replaceAll("\\s", "");
            String[] skillTokens = cleaned.split("[,;]");
            for (String skill : skillTokens)
                builder.addRequiredSkill(skill.toLowerCase());
        }

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

From source file:jsprit.core.problem.io.VrpXMLReader.java

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'");
        }/*  ww w  .ja  v a2s  .co  m*/
        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);
            }
        }

        //name
        String name = shipmentConfig.getString("name");
        if (name != null)
            builder.setName(name);

        //pickup location
        //pickup-locationId
        Location.Builder pickupLocationBuilder = Location.Builder.newInstance();
        String pickupLocationId = shipmentConfig.getString("pickup.locationId");
        if (pickupLocationId == null)
            pickupLocationId = shipmentConfig.getString("pickup.location.id");
        if (pickupLocationId != null) {
            pickupLocationBuilder.setId(pickupLocationId);
        }

        //pickup-coord
        Coordinate pickupCoord = getCoord(shipmentConfig, "pickup.");
        if (pickupCoord == null)
            pickupCoord = getCoord(shipmentConfig, "pickup.location.");
        if (pickupCoord != null) {
            pickupLocationBuilder.setCoordinate(pickupCoord);
        }

        //pickup.location.index
        String pickupLocationIndex = shipmentConfig.getString("pickup.location.index");
        if (pickupLocationIndex != null)
            pickupLocationBuilder.setIndex(Integer.parseInt(pickupLocationIndex));
        builder.setPickupLocation(pickupLocationBuilder.build());

        //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 location
        //delivery-locationId
        Location.Builder deliveryLocationBuilder = Location.Builder.newInstance();
        String deliveryLocationId = shipmentConfig.getString("delivery.locationId");
        if (deliveryLocationId == null)
            deliveryLocationId = shipmentConfig.getString("delivery.location.id");
        if (deliveryLocationId != null) {
            deliveryLocationBuilder.setId(deliveryLocationId);
            //            builder.setDeliveryLocationId(deliveryLocationId);
        }

        //delivery-coord
        Coordinate deliveryCoord = getCoord(shipmentConfig, "delivery.");
        if (deliveryCoord == null)
            deliveryCoord = getCoord(shipmentConfig, "delivery.location.");
        if (deliveryCoord != null) {
            deliveryLocationBuilder.setCoordinate(deliveryCoord);
        }

        String deliveryLocationIndex = shipmentConfig.getString("delivery.location.index");
        if (deliveryLocationIndex != null)
            deliveryLocationBuilder.setIndex(Integer.parseInt(deliveryLocationIndex));
        builder.setDeliveryLocation(deliveryLocationBuilder.build());

        //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);
        }

        //read skills
        String skillString = shipmentConfig.getString("requiredSkills");
        if (skillString != null) {
            String cleaned = skillString.replaceAll("\\s", "");
            String[] skillTokens = cleaned.split("[,;]");
            for (String skill : skillTokens)
                builder.addRequiredSkill(skill.toLowerCase());
        }

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

From source file:com.graphhopper.jsprit.io.problem.VrpXMLReader.java

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 IllegalArgumentException("shipment[@id] is missing.");

        String capacityString = shipmentConfig.getString("capacity-demand");
        boolean capacityDimensionsExist = shipmentConfig.containsKey("capacity-dimensions.dimension(0)");
        if (capacityString == null && !capacityDimensionsExist) {
            throw new IllegalArgumentException("capacity of shipment is not set. use 'capacity-dimensions'");
        }/*  ww  w . j a  v a  2  s  .  c  om*/
        if (capacityString != null && capacityDimensionsExist) {
            throw new IllegalArgumentException(
                    "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);
            }
        }

        //name
        String name = shipmentConfig.getString("name");
        if (name != null)
            builder.setName(name);

        //pickup location
        //pickup-locationId
        Location.Builder pickupLocationBuilder = Location.Builder.newInstance();
        String pickupLocationId = shipmentConfig.getString("pickup.locationId");
        if (pickupLocationId == null)
            pickupLocationId = shipmentConfig.getString("pickup.location.id");
        if (pickupLocationId != null) {
            pickupLocationBuilder.setId(pickupLocationId);
        }

        //pickup-coord
        Coordinate pickupCoord = getCoord(shipmentConfig, "pickup.");
        if (pickupCoord == null)
            pickupCoord = getCoord(shipmentConfig, "pickup.location.");
        if (pickupCoord != null) {
            pickupLocationBuilder.setCoordinate(pickupCoord);
        }

        //pickup.location.index
        String pickupLocationIndex = shipmentConfig.getString("pickup.location.index");
        if (pickupLocationIndex != null)
            pickupLocationBuilder.setIndex(Integer.parseInt(pickupLocationIndex));
        builder.setPickupLocation(pickupLocationBuilder.build());

        //pickup-serviceTime
        String pickupServiceTime = shipmentConfig.getString("pickup.duration");
        if (pickupServiceTime != null)
            builder.setPickupServiceTime(Double.parseDouble(pickupServiceTime));

        //pickup-tw
        List<HierarchicalConfiguration> pickupTWConfigs = shipmentConfig
                .configurationsAt("pickup.timeWindows.timeWindow");
        if (!pickupTWConfigs.isEmpty()) {
            for (HierarchicalConfiguration pu_twConfig : pickupTWConfigs) {
                builder.addPickupTimeWindow(
                        TimeWindow.newInstance(pu_twConfig.getDouble("start"), pu_twConfig.getDouble("end")));
            }
        }

        //delivery location
        //delivery-locationId
        Location.Builder deliveryLocationBuilder = Location.Builder.newInstance();
        String deliveryLocationId = shipmentConfig.getString("delivery.locationId");
        if (deliveryLocationId == null)
            deliveryLocationId = shipmentConfig.getString("delivery.location.id");
        if (deliveryLocationId != null) {
            deliveryLocationBuilder.setId(deliveryLocationId);
            //            builder.setDeliveryLocationId(deliveryLocationId);
        }

        //delivery-coord
        Coordinate deliveryCoord = getCoord(shipmentConfig, "delivery.");
        if (deliveryCoord == null)
            deliveryCoord = getCoord(shipmentConfig, "delivery.location.");
        if (deliveryCoord != null) {
            deliveryLocationBuilder.setCoordinate(deliveryCoord);
        }

        String deliveryLocationIndex = shipmentConfig.getString("delivery.location.index");
        if (deliveryLocationIndex != null)
            deliveryLocationBuilder.setIndex(Integer.parseInt(deliveryLocationIndex));
        builder.setDeliveryLocation(deliveryLocationBuilder.build());

        //delivery-serviceTime
        String deliveryServiceTime = shipmentConfig.getString("delivery.duration");
        if (deliveryServiceTime != null)
            builder.setDeliveryServiceTime(Double.parseDouble(deliveryServiceTime));

        //delivery-tw
        List<HierarchicalConfiguration> deliveryTWConfigs = shipmentConfig
                .configurationsAt("delivery.timeWindows.timeWindow");
        if (!deliveryTWConfigs.isEmpty()) {
            for (HierarchicalConfiguration dl_twConfig : deliveryTWConfigs) {
                builder.addDeliveryTimeWindow(
                        TimeWindow.newInstance(dl_twConfig.getDouble("start"), dl_twConfig.getDouble("end")));
            }
        }

        //read skills
        String skillString = shipmentConfig.getString("requiredSkills");
        if (skillString != null) {
            String cleaned = skillString.replaceAll("\\s", "");
            String[] skillTokens = cleaned.split("[,;]");
            for (String skill : skillTokens)
                builder.addRequiredSkill(skill.toLowerCase());
        }

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

From source file:jsprit.core.problem.io.VrpXMLReader.java

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'");
        }//from  w w  w .j  a  v  a  2s . c o  m
        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();
        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);

        //read startlocation
        Location.Builder startLocationBuilder = Location.Builder.newInstance();
        String locationId = vehicleConfig.getString("location.id");
        if (locationId == null) {
            locationId = vehicleConfig.getString("startLocation.id");
        }
        startLocationBuilder.setId(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.debug("location.coord is missing. will not warn you again.");
                doNotWarnAgain = true;
            }
        } else {
            Coordinate coordinate = Coordinate.newInstance(Double.parseDouble(coordX),
                    Double.parseDouble(coordY));
            startLocationBuilder.setCoordinate(coordinate);
        }
        String index = vehicleConfig.getString("startLocation.index");
        if (index == null)
            index = vehicleConfig.getString("location.index");
        if (index != null) {
            startLocationBuilder.setIndex(Integer.parseInt(index));
        }
        builder.setStartLocation(startLocationBuilder.build());

        //read endlocation
        Location.Builder endLocationBuilder = Location.Builder.newInstance();
        boolean hasEndLocation = false;
        String endLocationId = vehicleConfig.getString("endLocation.id");
        if (endLocationId != null) {
            hasEndLocation = true;
            endLocationBuilder.setId(endLocationId);
        }
        String endCoordX = vehicleConfig.getString("endLocation.coord[@x]");
        String endCoordY = vehicleConfig.getString("endLocation.coord[@y]");
        if (endCoordX == null || endCoordY == null) {
            if (!doNotWarnAgain) {
                logger.debug("endLocation.coord is missing. will not warn you again.");
                doNotWarnAgain = true;
            }
        } else {
            Coordinate coordinate = Coordinate.newInstance(Double.parseDouble(endCoordX),
                    Double.parseDouble(endCoordY));
            hasEndLocation = true;
            endLocationBuilder.setCoordinate(coordinate);
        }
        String endLocationIndex = vehicleConfig.getString("endLocation.index");
        if (endLocationIndex != null) {
            hasEndLocation = true;
            endLocationBuilder.setIndex(Integer.parseInt(endLocationIndex));
        }
        if (hasEndLocation)
            builder.setEndLocation(endLocationBuilder.build());

        //read timeSchedule
        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));

        //read return2depot
        String returnToDepot = vehicleConfig.getString("returnToDepot");
        if (returnToDepot != null) {
            builder.setReturnToDepot(vehicleConfig.getBoolean("returnToDepot"));
        }

        //read skills
        String skillString = vehicleConfig.getString("skills");
        if (skillString != null) {
            String cleaned = skillString.replaceAll("\\s", "");
            String[] skillTokens = cleaned.split("[,;]");
            for (String skill : skillTokens)
                builder.addSkill(skill.toLowerCase());
        }

        //build vehicle
        VehicleImpl vehicle = builder.build();
        vrpBuilder.addVehicle(vehicle);
        vehicleMap.put(vehicleId, vehicle);
    }

}

From source file:com.graphhopper.jsprit.core.problem.io.VrpXMLReader.java

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'");
        }// www . j  a v a  2 s. c o m
        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();
        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);

        //read startlocation
        Location.Builder startLocationBuilder = Location.Builder.newInstance();
        String locationId = vehicleConfig.getString("location.id");
        if (locationId == null) {
            locationId = vehicleConfig.getString("startLocation.id");
        }
        startLocationBuilder.setId(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.debug("location.coord is missing. will not warn you again.");
                doNotWarnAgain = true;
            }
        } else {
            Coordinate coordinate = Coordinate.newInstance(Double.parseDouble(coordX),
                    Double.parseDouble(coordY));
            startLocationBuilder.setCoordinate(coordinate);
        }
        String index = vehicleConfig.getString("startLocation.index");
        if (index == null)
            index = vehicleConfig.getString("location.index");
        if (index != null) {
            startLocationBuilder.setIndex(Integer.parseInt(index));
        }
        builder.setStartLocation(startLocationBuilder.build());

        //read endlocation
        Location.Builder endLocationBuilder = Location.Builder.newInstance();
        boolean hasEndLocation = false;
        String endLocationId = vehicleConfig.getString("endLocation.id");
        if (endLocationId != null) {
            hasEndLocation = true;
            endLocationBuilder.setId(endLocationId);
        }
        String endCoordX = vehicleConfig.getString("endLocation.coord[@x]");
        String endCoordY = vehicleConfig.getString("endLocation.coord[@y]");
        if (endCoordX == null || endCoordY == null) {
            if (!doNotWarnAgain) {
                logger.debug("endLocation.coord is missing. will not warn you again.");
                doNotWarnAgain = true;
            }
        } else {
            Coordinate coordinate = Coordinate.newInstance(Double.parseDouble(endCoordX),
                    Double.parseDouble(endCoordY));
            hasEndLocation = true;
            endLocationBuilder.setCoordinate(coordinate);
        }
        String endLocationIndex = vehicleConfig.getString("endLocation.index");
        if (endLocationIndex != null) {
            hasEndLocation = true;
            endLocationBuilder.setIndex(Integer.parseInt(endLocationIndex));
        }
        if (hasEndLocation)
            builder.setEndLocation(endLocationBuilder.build());

        //read timeSchedule
        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));

        //read return2depot
        String returnToDepot = vehicleConfig.getString("returnToDepot");
        if (returnToDepot != null) {
            builder.setReturnToDepot(vehicleConfig.getBoolean("returnToDepot"));
        }

        //read skills
        String skillString = vehicleConfig.getString("skills");
        if (skillString != null) {
            String cleaned = skillString.replaceAll("\\s", "");
            String[] skillTokens = cleaned.split("[,;]");
            for (String skill : skillTokens)
                builder.addSkill(skill.toLowerCase());
        }

        // read break
        List<HierarchicalConfiguration> breakTWConfigs = vehicleConfig
                .configurationsAt("break.timeWindows.timeWindow");
        if (!breakTWConfigs.isEmpty()) {
            String breakDurationString = vehicleConfig.getString("breaks.duration");
            Break.Builder current_break = Break.Builder.newInstance(vehicleId);
            current_break.setServiceTime(Double.parseDouble(breakDurationString));
            for (HierarchicalConfiguration twConfig : breakTWConfigs) {
                current_break.addTimeWindow(
                        TimeWindow.newInstance(twConfig.getDouble("start"), twConfig.getDouble("end")));
            }
            builder.setBreak(current_break.build());
        }

        //build vehicle
        VehicleImpl vehicle = builder.build();
        vrpBuilder.addVehicle(vehicle);
        vehicleMap.put(vehicleId, vehicle);
    }

}

From source file:com.graphhopper.jsprit.io.problem.VrpXMLReader.java

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 IllegalArgumentException("typeId is missing.");

        String capacityString = typeConfig.getString("capacity");
        boolean capacityDimensionsExist = typeConfig.containsKey("capacity-dimensions.dimension(0)");
        if (capacityString == null && !capacityDimensionsExist) {
            throw new IllegalArgumentException("capacity of type is not set. use 'capacity-dimensions'");
        }/*from   ww  w .  j  a va  2s .  com*/
        if (capacityString != null && capacityDimensionsExist) {
            throw new IllegalArgumentException(
                    "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 (typeConfig.containsKey("costs.service")) {
            Double serviceC = typeConfig.getDouble("costs.service");
            if (serviceC != null)
                typeBuilder.setCostPerServiceTime(serviceC);
        }

        if (typeConfig.containsKey("costs.wait")) {
            Double waitC = typeConfig.getDouble("costs.wait");
            if (waitC != null)
                typeBuilder.setCostPerWaitingTime(waitC);
        }

        if (fix != null)
            typeBuilder.setFixedCost(fix);
        if (timeC != null)
            typeBuilder.setCostPerTransportTime(timeC);
        if (distC != null)
            typeBuilder.setCostPerDistance(distC);
        VehicleType type = typeBuilder.build();
        String id = type.getTypeId();
        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 IllegalArgumentException("vehicleId is missing.");
        Builder builder = VehicleImpl.Builder.newInstance(vehicleId);
        String typeId = vehicleConfig.getString("typeId");
        if (typeId == null)
            throw new IllegalArgumentException("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 IllegalArgumentException("vehicleType with typeId " + typeId + " is missing.");
        builder.setType(type);

        //read startlocation
        Location.Builder startLocationBuilder = Location.Builder.newInstance();
        String locationId = vehicleConfig.getString("location.id");
        if (locationId == null) {
            locationId = vehicleConfig.getString("startLocation.id");
        }
        startLocationBuilder.setId(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.debug("location.coord is missing. will not warn you again.");
                doNotWarnAgain = true;
            }
        } else {
            Coordinate coordinate = Coordinate.newInstance(Double.parseDouble(coordX),
                    Double.parseDouble(coordY));
            startLocationBuilder.setCoordinate(coordinate);
        }
        String index = vehicleConfig.getString("startLocation.index");
        if (index == null)
            index = vehicleConfig.getString("location.index");
        if (index != null) {
            startLocationBuilder.setIndex(Integer.parseInt(index));
        }
        builder.setStartLocation(startLocationBuilder.build());

        //read endlocation
        Location.Builder endLocationBuilder = Location.Builder.newInstance();
        boolean hasEndLocation = false;
        String endLocationId = vehicleConfig.getString("endLocation.id");
        if (endLocationId != null) {
            hasEndLocation = true;
            endLocationBuilder.setId(endLocationId);
        }
        String endCoordX = vehicleConfig.getString("endLocation.coord[@x]");
        String endCoordY = vehicleConfig.getString("endLocation.coord[@y]");
        if (endCoordX == null || endCoordY == null) {
            if (!doNotWarnAgain) {
                logger.debug("endLocation.coord is missing. will not warn you again.");
                doNotWarnAgain = true;
            }
        } else {
            Coordinate coordinate = Coordinate.newInstance(Double.parseDouble(endCoordX),
                    Double.parseDouble(endCoordY));
            hasEndLocation = true;
            endLocationBuilder.setCoordinate(coordinate);
        }
        String endLocationIndex = vehicleConfig.getString("endLocation.index");
        if (endLocationIndex != null) {
            hasEndLocation = true;
            endLocationBuilder.setIndex(Integer.parseInt(endLocationIndex));
        }
        if (hasEndLocation)
            builder.setEndLocation(endLocationBuilder.build());

        //read timeSchedule
        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));

        //read return2depot
        String returnToDepot = vehicleConfig.getString("returnToDepot");
        if (returnToDepot != null) {
            builder.setReturnToDepot(vehicleConfig.getBoolean("returnToDepot"));
        }

        //read skills
        String skillString = vehicleConfig.getString("skills");
        if (skillString != null) {
            String cleaned = skillString.replaceAll("\\s", "");
            String[] skillTokens = cleaned.split("[,;]");
            for (String skill : skillTokens)
                builder.addSkill(skill.toLowerCase());
        }

        // read break
        List<HierarchicalConfiguration> breakTWConfigs = vehicleConfig
                .configurationsAt("breaks.timeWindows.timeWindow");
        if (!breakTWConfigs.isEmpty()) {
            String breakDurationString = vehicleConfig.getString("breaks.duration");
            Break.Builder current_break = Break.Builder.newInstance(vehicleId);
            current_break.setServiceTime(Double.parseDouble(breakDurationString));
            for (HierarchicalConfiguration twConfig : breakTWConfigs) {
                current_break.addTimeWindow(
                        TimeWindow.newInstance(twConfig.getDouble("start"), twConfig.getDouble("end")));
            }
            builder.setBreak(current_break.build());
        }

        //build vehicle
        VehicleImpl vehicle = builder.build();
        vrpBuilder.addVehicle(vehicle);
        vehicleMap.put(vehicleId, vehicle);
    }

}

From source file:com.intuit.tank.vm.settings.AgentConfig.java

@SuppressWarnings("unchecked")
public AgentConfig(@Nonnull HierarchicalConfiguration config) {
    this.config = config;
    validMimeTypes = new HashSet<String>();
    List<HierarchicalConfiguration> validMimes = config.configurationsAt(KEY_VALID_MIME_TYPES);
    if (validMimes != null) {
        for (HierarchicalConfiguration c : validMimes) {
            validMimeTypes.add(c.getString(""));
        }//from w w w  .ja va 2s  .  c  om
    }
    tankClientMap = new HashMap<String, String>();
    // <tank-http-clients>
    // <tank-client name="Apache HttpClient
    // 3.1">com.intuit.tank.httpclient3.TankHttpClient3</tank-client>
    // <tank-client name="apache HttpClient
    // 4.5">com.intuit.tank.httpclient4.TankHttpClient4</tank-client>
    // <tank-http-clients>
    List<HierarchicalConfiguration> tankClients = config.configurationsAt(KEY_TANK_HTTP_CLIENTS);
    if (tankClients != null) {
        for (HierarchicalConfiguration c : tankClients) {
            tankClientMap.put(c.getString(KEY_NAME), c.getString(""));
        }
    }
    if (tankClientMap.isEmpty()) {
        tankClientMap.put("Apache HttpClient 3.1", "com.intuit.tank.httpclient3.TankHttpClient3");
        tankClientMap.put("Apache HttpClient 4.5", "com.intuit.tank.httpclient4.TankHttpClient4");
    }
    resultsProviderMap = new HashMap<String, String>();
    resultsTypeMap = new HashMap<String, String>();
    requestHeaderMap = new HashMap<String, String>();
    List<HierarchicalConfiguration> requestHeaders = config.configurationsAt(KEY_REQUEST_HEADERS);
    if (requestHeaders != null) {
        for (HierarchicalConfiguration c : requestHeaders) {
            String key = c.getString(KEY_HEADER_KEY);
            requestHeaderMap.put(key, c.getString(""));
        }
    }
    minMaxMap = new HashMap<String, Range>();
    List<HierarchicalConfiguration> durations = config.configurationsAt(KEY_DURATION_SIMULATION);
    if (durations != null) {
        for (HierarchicalConfiguration c : durations) {
            try {
                String key = c.getString(KEY_FOR).trim();
                int min = c.getInt(KEY_MIN);
                int max = c.getInt(KEY_MAX);
                Range r = new Range(min, max);
                minMaxMap.put(key.toLowerCase(), r);
            } catch (Exception e) {
                LOG.warn("Error parsing duration: " + e);
            }
        }
    }
    if (!minMaxMap.containsKey("post")) {
        minMaxMap.put("post", new Range(500L, 1000L));
    }
    if (!minMaxMap.containsKey("get")) {
        minMaxMap.put("get", new Range(50L, 300L));
    }
    if (!minMaxMap.containsKey("process")) {
        minMaxMap.put("process", new Range(10L, 50L));
    }
}