protected void loadStringTransformerFromXML(XMLConfiguration xml) throws IOException { setCaseSensitive(xml.getBoolean("[@caseSensitive]", false)); setInclusive(xml.getBoolean("[@inclusive]", false)); List<HierarchicalConfiguration> nodes = xml.configurationsAt("stripBetween"); for (HierarchicalConfiguration node : nodes) { addStripEndpoints(node.getString("start", null), node.getString("end", null)); } }
@PostConstruct public void init() { String genreFileName = PropertyTools.getProperty("yamj3.genre.fileName"); if (StringUtils.isBlank(genreFileName)) { LOG.trace("No valid genre file name configured"); return; } if (!StringUtils.endsWithIgnoreCase(genreFileName, "xml")) { LOG.warn("Invalid genre file name specified: {}", genreFileName); return; } File xmlFile; if (StringUtils.isBlank(FilenameUtils.getPrefix(genreFileName))) { // relative path given String path = System.getProperty("yamj3.home"); if (StringUtils.isEmpty(path)) { path = "."; } xmlFile = new File(FilenameUtils.concat(path, genreFileName)); } else { // absolute path given xmlFile = new File(genreFileName); } if (!xmlFile.exists() || !xmlFile.isFile()) { LOG.warn("Genres file does not exist: {}", xmlFile.getPath()); return; } if (!xmlFile.canRead()) { LOG.warn("Genres file not readble: {}", xmlFile.getPath()); return; } LOG.debug("Initialize genres from file: {}", xmlFile.getPath()); try { XMLConfiguration c = new XMLConfiguration(xmlFile); List<HierarchicalConfiguration> genres = c.configurationsAt("genre"); for (HierarchicalConfiguration genre : genres) { String masterGenre = genre.getString("[@name]"); List<Object> subGenres = genre.getList("subgenre"); for (Object subGenre : subGenres) { LOG.debug("New genre added to map: {} -> {}", subGenre, masterGenre); GENRES_MAP.put(((String) subGenre).toLowerCase(), masterGenre); } } try { this.commonStorageService.updateGenresXml(GENRES_MAP); } catch (Exception ex) { LOG.warn("Failed update genres xml in database", ex); } } catch (Exception ex) { LOG.error("Failed parsing genre input file: " + xmlFile.getPath(), ex); } }
public static boolean loadConfig(String configFilePath) { String tmp = System.getProperty("os.name").toLowerCase(); if (tmp.startsWith("windows")) { g.os = g.OS_WINDOWS; } else if (tmp.startsWith("linux")) { g.os = g.OS_LINUX; } else { g.os = g.OS_OTHER; } tmp = System.getProperty("sun.arch.data.model"); if (tmp.equals("64")) { g.arch = g.ARCH_64; } else { g.arch = g.ARCH_32; } try { if (configFilePath == null) { config = new XMLConfiguration(configPath + "config.xml"); } else { config = new XMLConfiguration(configFilePath); } dbConfig = config.getString("db", "").toLowerCase(); siteUrl = config.getString("serverInfo.siteUrl"); siteName = config.getString("serverInfo.siteName"); uploadTemp = rootPath + config.getString("serverInfo.uploadTemp"); uploadSizeMax = config.getLong("serverInfo.uploadSizeMax", 0); sessionExpiredTime = config.getInt("serverInfo.sessionExpiredTime", 0); sessionIdName = config.getString("serverInfo.sessionIdName", "ycsid"); String _s = g.getConfig().getString("startup"); if ("".equals(_s)) { startup = null; } else { _s = _s.replaceAll("\\s", ""); startup = _s.split(";"); } _s = null; // 加载全局参数 List<HierarchicalConfiguration> fields = config.configurationsAt("globalVars.var"); if (fields != null && fields.size() > 0) { vars = new String[fields.size()][2]; HierarchicalConfiguration sub; for (int i = 0; i < fields.size(); i++) { sub = fields.get(i); vars[i][0] = sub.getString("[@name]"); vars[i][1] = sub.getString("[@value]"); } sub = null; } return true; } catch (ConfigurationException e) { return false; } }
public static Hashtable getMap(String config) throws FitsConfigurationException { Hashtable mappings = new Hashtable(); XMLConfiguration conf = null; try { conf = new XMLConfiguration(config); } catch (ConfigurationException e) { throw new FitsConfigurationException("Error reading " + config + "fits.xml", e); } List fields = conf.configurationsAt("map"); for (Iterator it = fields.iterator(); it.hasNext(); ) { HierarchicalConfiguration sub = (HierarchicalConfiguration) it.next(); // sub contains now all data about a single field String format = sub.getString("[@format]"); String transform = sub.getString("[@transform]"); mappings.put(format, transform); } return mappings; }
public static DefaultEngineConfig create() { DefaultEngineConfig conf = new DefaultEngineConfig(); String path = Utils.getConfigDir() + Constants.HDATA_XML; try { XMLConfiguration config = new XMLConfiguration(path); config.setValidating(true); List<HierarchicalConfiguration> properties = config.configurationsAt(".property"); for (HierarchicalConfiguration hc : properties) { String name = hc.getString("name"); String value = hc.getString("value"); conf.setProperty(name, value); } } catch (ConfigurationException e) { Throwables.propagate(e); } return conf; }
@Override public void loadFromXML(Reader in) throws IOException { try { XMLConfiguration xml = ConfigurationUtil.newXMLConfiguration(in); defaultDelay = xml.getLong("[@default]", defaultDelay); ignoreRobotsCrawlDelay = xml.getBoolean("[@ignoreRobotsCrawlDelay]", ignoreRobotsCrawlDelay); scope = xml.getString("[@scope]", SCOPE_CRAWLER); List<HierarchicalConfiguration> nodes = xml.configurationsAt("schedule"); for (HierarchicalConfiguration node : nodes) { schedules.add( new DelaySchedule( node.getString("[@dayOfWeek]", null), node.getString("[@dayOfMonth]", null), node.getString("[@time]", null), node.getLong("", DEFAULT_DELAY))); } } catch (ConfigurationException e) { throw new IOException("Cannot load XML.", e); } }
@Override public void call(EnunciateContext context) { jaxwsContext = new EnunciateJaxwsContext(this.jaxbModule.getJaxbContext(), isUseSourceParameterNames()); boolean aggressiveWebMethodExcludePolicy = isAggressiveWebMethodExcludePolicy(); Map<String, String> eiPaths = new HashMap<String, String>(); File sunJaxwsXmlFile = getSunJaxwsXmlFile(); if (sunJaxwsXmlFile != null) { XMLConfiguration config; try { config = new XMLConfiguration(sunJaxwsXmlFile); } catch (ConfigurationException e) { throw new EnunciateException(e); } List<HierarchicalConfiguration> endpoints = config.configurationsAt("endpoint"); for (HierarchicalConfiguration endpoint : endpoints) { String impl = endpoint.getString("[@implementation]", null); String urlPattern = endpoint.getString("[@url-pattern]", null); if (impl != null && urlPattern != null) { eiPaths.put(impl, urlPattern); } } } DataTypeDetectionStrategy detectionStrategy = getDataTypeDetectionStrategy(); if (detectionStrategy != DataTypeDetectionStrategy.passive) { Set<? extends Element> elements = detectionStrategy == DataTypeDetectionStrategy.local ? context.getLocalApiElements() : context.getApiElements(); for (Element declaration : elements) { if (declaration instanceof TypeElement) { TypeElement element = (TypeElement) declaration; XmlRegistry registryMetadata = declaration.getAnnotation(XmlRegistry.class); if (registryMetadata != null) { this.jaxbModule.addPotentialJaxbElement(element, new LinkedList<Element>()); } if (isEndpointInterface(element)) { EndpointInterface ei = new EndpointInterface( element, elements, aggressiveWebMethodExcludePolicy, jaxwsContext); for (EndpointImplementation implementation : ei.getEndpointImplementations()) { String urlPattern = eiPaths.get(implementation.getQualifiedName().toString()); if (urlPattern != null) { if (!urlPattern.startsWith("/")) { urlPattern = "/" + urlPattern; } if (urlPattern.endsWith("/*")) { urlPattern = urlPattern.substring(0, urlPattern.length() - 2) + ei.getServiceName(); } implementation.setPath(urlPattern); } } jaxwsContext.add(ei); addReferencedDataTypeDefinitions(ei); } } } } if (jaxwsContext.getEndpointInterfaces().size() > 0) { this.apiRegistry.getServiceApis().add(jaxwsContext); if (!this.apiRegistry.getSyntaxes().contains(jaxwsContext.getJaxbContext())) { this.apiRegistry.getSyntaxes().add(jaxwsContext.getJaxbContext()); } } }
public void processQueries(String instanceName, String xmlFile) { XMLConfiguration config = null; /** clear'em out */ if (collectionQueries.get(instanceName) != null) { collectionQueries.get(instanceName).clear(); } if (relationshipQueries.get(instanceName) != null) { relationshipQueries.get(instanceName).clear(); } if (jdbcDriver != null) { jdbcDriver = null; } if (validationQuery != null) { validationQuery = null; } if (url != null) { url = null; } try { /** * use strange ethiopic unicode character so that it never delimits the properties * * <p>This is a workaround becuase config.setDelimiterParsingDisabled(true) doesn't disable * parsing */ AbstractConfiguration.setDefaultListDelimiter('\u12BF'); config = new XMLConfiguration(xmlFile); config.setDelimiterParsingDisabled(true); Map<String, String> instanceCollectionQueryMap = new TreeMap<String, String>(); Map<String, String> instanceRelationshipQueryMap = new TreeMap<String, String>(); Map<String, String> instanceAttributeQueryMap = new TreeMap<String, String>(); @SuppressWarnings("unchecked") List<HierarchicalConfiguration> params = config.configurationsAt("configuration"); for (HierarchicalConfiguration param : params) { this.jdbcDriver = param.getString("driver"); this.validationQuery = param.getString("validationquery"); this.url = param.getString("url"); this.cycleTimeOffset = param.getInt("cycletimeoffset"); if (log.isDebugEnabled()) { log.debug("jdbcDriver:" + param.getString("driver")); log.debug("validationQuery:" + param.getString("validationquery")); log.debug("url:" + param.getString("url")); log.debug("cycleTimeOffset:" + param.getInt("cycletimeoffset")); } } @SuppressWarnings("unchecked") List<HierarchicalConfiguration> queries = config.configurationsAt("queries.query"); for (HierarchicalConfiguration sub : queries) { String name = sub.getString("name"); String type = sub.getString("type"); String sql = sub.getString("sql"); if (type.equalsIgnoreCase("collection")) { instanceCollectionQueryMap.put(name, sql); } else if (type.equalsIgnoreCase("relationship")) { instanceRelationshipQueryMap.put(name, sql); } else if (type.equalsIgnoreCase("attribute")) { instanceAttributeQueryMap.put(name, sql); } } collectionQueries.put(instanceName, instanceCollectionQueryMap); relationshipQueries.put(instanceName, instanceRelationshipQueryMap); attributeQueries.put(instanceName, instanceAttributeQueryMap); } catch (ConfigurationException e) { log.error(e); } }
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); } }
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); } }
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); } }
private void readSolutions(XMLConfiguration vrpProblem) { if (solutions == null) return; List<HierarchicalConfiguration> solutionConfigs = vrpProblem.configurationsAt("solutions.solution"); for (HierarchicalConfiguration solutionConfig : solutionConfigs) { String totalCost = solutionConfig.getString("cost"); double cost = -1; if (totalCost != null) cost = Double.parseDouble(totalCost); List<HierarchicalConfiguration> routeConfigs = solutionConfig.configurationsAt("routes.route"); List<VehicleRoute> routes = new ArrayList<VehicleRoute>(); for (HierarchicalConfiguration routeConfig : routeConfigs) { // ! here, driverId is set to noDriver, no matter whats in driverId. Driver driver = DriverImpl.noDriver(); String vehicleId = routeConfig.getString("vehicleId"); Vehicle vehicle = getVehicle(vehicleId); if (vehicle == null) throw new IllegalStateException("vehicle is missing."); String start = routeConfig.getString("start"); if (start == null) throw new IllegalStateException("route start-time is missing."); double departureTime = Double.parseDouble(start); String end = routeConfig.getString("end"); if (end == null) throw new IllegalStateException("route end-time is missing."); VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver); routeBuilder.setDepartureTime(departureTime); routeBuilder.setRouteEndArrivalTime(Double.parseDouble(end)); List<HierarchicalConfiguration> actConfigs = routeConfig.configurationsAt("act"); for (HierarchicalConfiguration actConfig : actConfigs) { String type = actConfig.getString("[@type]"); if (type == null) throw new IllegalStateException("act[@type] is missing."); double arrTime = 0.; double endTime = 0.; String arrTimeS = actConfig.getString("arrTime"); if (arrTimeS != null) arrTime = Double.parseDouble(arrTimeS); String endTimeS = actConfig.getString("endTime"); if (endTimeS != null) endTime = Double.parseDouble(endTimeS); String serviceId = actConfig.getString("serviceId"); if (serviceId != null) { Service service = getService(serviceId); routeBuilder.addService(service, arrTime, endTime); } else { String shipmentId = actConfig.getString("shipmentId"); if (shipmentId == null) throw new IllegalStateException("either serviceId or shipmentId is missing"); Shipment shipment = getShipment(shipmentId); if (shipment == null) throw new IllegalStateException( "shipment with id " + shipmentId + " does not exist."); if (type.equals("pickupShipment")) { routeBuilder.addPickup(shipment, arrTime, endTime); } else if (type.equals("deliverShipment")) { routeBuilder.addDelivery(shipment, arrTime, endTime); } else throw new IllegalStateException( "type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here"); } } routes.add(routeBuilder.build()); } VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(routes, cost); solutions.add(solution); } }
private void readInitialRoutes(XMLConfiguration xmlConfig) { List<HierarchicalConfiguration> initialRouteConfigs = xmlConfig.configurationsAt("initialRoutes.route"); for (HierarchicalConfiguration routeConfig : initialRouteConfigs) { Driver driver = DriverImpl.noDriver(); String vehicleId = routeConfig.getString("vehicleId"); Vehicle vehicle = getVehicle(vehicleId); if (vehicle == null) throw new IllegalStateException("vehicle is missing."); String start = routeConfig.getString("start"); if (start == null) throw new IllegalStateException("route start-time is missing."); double departureTime = Double.parseDouble(start); VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver); routeBuilder.setDepartureTime(departureTime); List<HierarchicalConfiguration> actConfigs = routeConfig.configurationsAt("act"); for (HierarchicalConfiguration actConfig : actConfigs) { String type = actConfig.getString("[@type]"); if (type == null) throw new IllegalStateException("act[@type] is missing."); double arrTime = 0.; double endTime = 0.; String arrTimeS = actConfig.getString("arrTime"); if (arrTimeS != null) arrTime = Double.parseDouble(arrTimeS); String endTimeS = actConfig.getString("endTime"); if (endTimeS != null) endTime = Double.parseDouble(endTimeS); String serviceId = actConfig.getString("serviceId"); if (serviceId != null) { Service service = getService(serviceId); if (service == null) throw new IllegalStateException( "service to serviceId " + serviceId + " is missing (reference in one of your initial routes). make sure you define the service you refer to here in <services> </services>."); // !!!since job is part of initial route, it does not belong to jobs in problem, i.e. // variable jobs that can be assigned/scheduled freezedJobIds.add(serviceId); routeBuilder.addService(service, arrTime, endTime); } else { String shipmentId = actConfig.getString("shipmentId"); if (shipmentId == null) throw new IllegalStateException("either serviceId or shipmentId is missing"); Shipment shipment = getShipment(shipmentId); if (shipment == null) throw new IllegalStateException( "shipment to shipmentId " + shipmentId + " is missing (reference in one of your initial routes). make sure you define the shipment you refer to here in <shipments> </shipments>."); freezedJobIds.add(shipmentId); if (type.equals("pickupShipment")) { routeBuilder.addPickup(shipment, arrTime, endTime); } else if (type.equals("deliverShipment")) { routeBuilder.addDelivery(shipment, arrTime, endTime); } else throw new IllegalStateException( "type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here"); } } VehicleRoute route = routeBuilder.build(); vrpBuilder.addInitialVehicleRoute(route); } }