List of usage examples for org.apache.commons.configuration HierarchicalConfiguration getDouble
public double getDouble(String key)
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 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()); } //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'"); }//from ww w .j a va 2 s .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'."); } 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'"); }/* ww w . j ava 2s . c o m*/ 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.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 ww w . jav a2 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'."); } 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'"); }// w ww . j ava 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'."); } 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 . j a v a 2 s . c o 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:org.onosproject.drivers.ciena.waveserver.rest.CienaWaveserverDeviceDescription.java
public static PortDescription parseWaveServerCienaOchPorts(long portNumber, HierarchicalConfiguration config, SparseAnnotations annotations) { final List<String> tunableType = Lists.newArrayList("performance-optimized", "accelerated"); final String flexGrid = "flex-grid"; final String state = "properties.transmitter.state"; final String tunable = "properties.modem.tx-tuning-mode"; final String spacing = "properties.line-system.wavelength-spacing"; final String frequency = "properties.transmitter.frequency.value"; boolean isEnabled = config.getString(state).equals(ENABLED); boolean isTunable = tunableType.contains(config.getString(tunable)); GridType gridType = config.getString(spacing).equals(flexGrid) ? GridType.FLEX : null; ChannelSpacing chSpacing = gridType == GridType.FLEX ? ChannelSpacing.CHL_6P25GHZ : null; //Working in Ghz //(Nominal central frequency - 193.1)/channelSpacing = spacingMultiplier final int baseFrequency = 193100; long spacingFrequency = chSpacing == null ? baseFrequency : chSpacing.frequency().asHz(); int spacingMult = ((int) (toGbps(((int) config.getDouble(frequency) - baseFrequency)) / toGbpsFromHz(spacingFrequency))); //FIXME is there a better way ? return ochPortDescription(PortNumber.portNumber(portNumber), isEnabled, OduSignalType.ODU4, isTunable, new OchSignal(gridType, chSpacing, spacingMult, 1), annotations); }
From source file:org.onosproject.drivers.oplink.OplinkOpticalPowerConfig.java
private Long acquirePortPower(PortNumber port, String selection) { String reply = netconfGet(handler(), getPortPowerFilter(port, selection)); HierarchicalConfiguration info = configAt(reply, KEY_PORTS_PORT); if (info == null) { return null; }/*from w ww . j av a 2s . c om*/ return (long) (info.getDouble(selection) * POWER_MULTIPLIER); }
From source file:org.onosproject.drivers.oplink.OplinkOpticalPowerConfig.java
private Long acquireChannelAttenuation(PortNumber port, OchSignal channel) { log.debug("Get port{} channel{} attenuation...", port, channel.channelSpacing()); String reply = netconfGet(handler(), getChannelAttenuationFilter(port, channel)); HierarchicalConfiguration info = configAt(reply, KEY_CONNS); if (info == null) { return null; }/*ww w . j a v a 2 s . com*/ return (long) (info.getDouble(KEY_CHATT) * POWER_MULTIPLIER); }
From source file:org.onosproject.drivers.oplink.OplinkOpticalPowerConfig.java
private Long acquireChannelPower(PortNumber port, OchSignal channel) { log.debug("Get port{} channel{} power...", port, channel.channelSpacing()); String reply = netconfGet(handler(), getChannelPowerFilter(port, channel)); HierarchicalConfiguration info = configAt(reply, KEY_DATA_CONNS); if (info == null) { return null; }//from w ww .ja v a 2 s . com return (long) (info.getDouble(KEY_CHPWR) * POWER_MULTIPLIER); }