List of usage examples for org.apache.commons.configuration HierarchicalConfiguration configurationsAt
public List configurationsAt(String key)
From source file:com.vmware.qe.framework.datadriven.impl.DDHelper.java
private static final List<HierarchicalConfiguration> getData(String className, HierarchicalConfiguration context) throws DDException { log.info("Getting data for '{}'", className); // selecting supplier and getting data String supplierType = context.getString(TAG_SUPPLIER_TYPE, null); supplierType = supplierType == null//from ww w .j a v a 2 s . co m ? DDConfig.getSingleton().getData().getString(TAG_SUPPLIER_DEFAULT, null) : supplierType; DataSupplier supplier = null; if (supplierType != null) { if (ddCoreConfig.getDataSupplierMap().containsKey(supplierType)) { supplier = ddCoreConfig.getDataSupplierMap().get(supplierType); } else { throw new IllegalArgumentException("Given supplier with name = " + supplierType + " not found"); } } else { if (ddCoreConfig.getDataSupplierMap().containsKey(KEY_DEFAULT)) { supplier = ddCoreConfig.getDataSupplierMap().get(KEY_DEFAULT); } else { log.warn( "no supplier selected. could not find default supplier. Using the first avaliable supplier"); supplier = ddCoreConfig.getDataSuppliers().iterator().next(); } } log.info("Supplier used: {}", supplier.getClass().getName()); final HierarchicalConfiguration testData; testData = supplier.getData(className, context); if (testData == null) { log.warn("no test data found for the given test class = " + className); return null; } // selecting generator and generating dynamic data along with static data. List<HierarchicalConfiguration> datas = null; boolean dynamicGeneration = context.getBoolean(TAG_GENERATOR_DYNAMIC, false); dynamicGeneration = dynamicGeneration ? dynamicGeneration : DDConfig.getSingleton().getData().getBoolean(TAG_GENERATOR_DYNAMIC, false); if (dynamicGeneration) { log.info("Dynamic data generation selected!"); String generatorType = context.getString(TAG_GENERATOR_TYPE, null); generatorType = generatorType == null ? DDConfig.getSingleton().getData().getString(TAG_GENERATOR_DEFAULT, null) : generatorType; DataGenerator dataGenerator = null; if (generatorType != null) { if (ddCoreConfig.getDataGeneratorMap().containsKey(generatorType)) { dataGenerator = ddCoreConfig.getDataGeneratorMap().get(generatorType); } else { throw new IllegalArgumentException( "Given generator with name = " + generatorType + " not found"); } } else { if (ddCoreConfig.getDataGeneratorMap().containsKey(KEY_DEFAULT)) { dataGenerator = ddCoreConfig.getDataGeneratorMap().get(KEY_DEFAULT); } else { log.warn("Could not find default generator, using the first avaliable generator"); dataGenerator = ddCoreConfig.getDataGenerators().iterator().next(); } } log.info("Generator Used: {}", dataGenerator.getClass().getName()); datas = dataGenerator.generate(testData, context); List<HierarchicalConfiguration> staticData = testData.configurationsAt(TAG_DATA); for (HierarchicalConfiguration aStaticData : staticData) { if (!aStaticData.getBoolean(TAG_AUTOGEN_ATTR, false)) { datas.add(aStaticData); } } } else { log.info("No Dynamic data generation."); datas = testData.configurationsAt(TAG_DATA); } log.info("Applying filters..."); List<HierarchicalConfiguration> filteredData = new ArrayList<>(); for (int i = 0; i < datas.size(); i++) {// for each data we create // new test instance. HierarchicalConfiguration aTestData = datas.get(i); boolean canRun = true; for (DataFilter filter : ddCoreConfig.getDataFilters()) { if (!filter.canRun(className, aTestData, context)) { canRun = false; break; } } if (canRun) { filteredData.add(aTestData); } } return filteredData; }
From source file:com.graphhopper.jsprit.core.problem.io.VrpXMLReader.java
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); } 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); } else if (type.equals("deliverShipment")) { routeBuilder.addDelivery(shipment); } else throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here"); }/*from w w w .j a v a2s . c o m*/ } VehicleRoute route = routeBuilder.build(); vrpBuilder.addInitialVehicleRoute(route); } }
From source file:com.graphhopper.jsprit.io.problem.VrpXMLReader.java
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 IllegalArgumentException("vehicle is missing."); String start = routeConfig.getString("start"); if (start == null) throw new IllegalArgumentException("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 IllegalArgumentException("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 (type.equals("break")) { Break currentbreak = getBreak(vehicleId); routeBuilder.addBreak(currentbreak); } else { if (serviceId != null) { Service service = getService(serviceId); if (service == null) throw new IllegalArgumentException("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); } else { String shipmentId = actConfig.getString("shipmentId"); if (shipmentId == null) throw new IllegalArgumentException("either serviceId or shipmentId is missing"); Shipment shipment = getShipment(shipmentId); if (shipment == null) throw new IllegalArgumentException("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); } else if (type.equals("deliverShipment")) { routeBuilder.addDelivery(shipment); } else throw new IllegalArgumentException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here"); }/*from www. j a va2s .c om*/ } } VehicleRoute route = routeBuilder.build(); vrpBuilder.addInitialVehicleRoute(route); } }
From source file:com.github.steveash.typedconfig.resolver.type.container.AbstractContainerValueResolverFactory.java
@Override public ValueResolver makeForThis(final ConfigBinding containerBinding, final HierarchicalConfiguration config, final ConfigFactoryContext context) { return new ValueResolver() { @Override//from w w w . ja va 2 s . co m public Object resolve() { TypeToken<?> thisType = getContainedType(containerBinding.getDataType()); ConfigBinding childBinding = containerBinding.withKey("").withDataType(thisType) .withOptions(Option.EmptyOptions); ValueResolverFactory childFactory = context.getRegistry().lookup(childBinding); switch (childFactory.getValueType()) { case Simple: return makeForSimpleType(childBinding, childFactory); case Nested: return makeForNestedType(childBinding, childFactory); default: throw new InvalidProxyException("The proxy method returning " + containerBinding.getDataType() + " for configuration key " + containerBinding.getConfigKeyToLookup() + " uses a container type " + "which returns " + thisType + " which is also a container type. You can't have " + "containers of container types."); } } private Object makeForNestedType(ConfigBinding childBinding, ValueResolverFactory childFactory) { List<HierarchicalConfiguration> childConfigs = config .configurationsAt(containerBinding.getConfigKeyToLookup()); Collection<Object> values = makeEmptyCollection(childConfigs.size()); for (HierarchicalConfiguration childConfig : childConfigs) { SubnodeConfiguration childConfigAsSub = (SubnodeConfiguration) childConfig; ConfigBinding subBinding = childBinding.withKey(childConfigAsSub.getSubnodeKey()); ValueResolver r = childFactory.makeForThis(subBinding, childConfig, context); values.add(r.resolve()); } return makeReturnValueFrom(values, containerBinding); } private Object makeForSimpleType(ConfigBinding childBinding, ValueResolverFactory childFactory) { ValueResolver childResolver = childFactory.makeForThis(childBinding, config, context); List<Object> configValues = config.getList(containerBinding.getConfigKeyToLookup()); Collection<Object> containedValues = makeEmptyCollection(configValues.size()); for (Object o : configValues) { if (!(o instanceof String)) throw new IllegalArgumentException( "Can only use Configuration instances which return string " + "representations of the values which we will then convert. XMLConfiguration does this"); containedValues.add(childResolver.convertDefaultValue((String) o)); } return makeReturnValueFrom(containedValues, containerBinding); } @Override public Object convertDefaultValue(String defaultValue) { throw new IllegalStateException("cannot specify a defaults for container types"); } @Override public String configurationKeyToLookup() { return containerBinding.getConfigKeyToLookup(); } }; }
From source file:ch.admin.suis.msghandler.config.ClientConfigurationFactory.java
private void setupTransparentApps(String defaultSenderCronValue, String baseDir, ReceiverConfiguration receiverConfiguration, StatusCheckerConfiguration statusCheckerConfiguration) throws ConfigurationException { // ************** transparent applications LOG.info("Configure the transparent applications..."); final List transparent = xmlConfig.configurationsAt("transparentApp"); for (Iterator i = transparent.iterator(); i.hasNext();) { HierarchicalConfiguration sub = (HierarchicalConfiguration) i.next(); // the sedex ID of this application final String sedexId = sub.getString(".[@participantId]"); final String outboxDir = sub.getString("outbox[@dirPath]"); // the outbox if (null != outboxDir) { final String cronValue = sub.getString("outbox[@cron]"); // the outbox exists final SenderConfiguration senderConfiguration = new SenderConfiguration( StringUtils.defaultIfEmpty(cronValue, defaultSenderCronValue)); senderConfiguration.addOutbox(new Outbox(FileUtils.createPath(baseDir, outboxDir))); clientConfiguration.addTransparentSenderConfiguration(senderConfiguration); // MANTIS 5023 LOG.info("transparent sender added, " + senderConfiguration); }/*from ww w . j av a2 s .c o m*/ // inboxes final List inboxes = sub.configurationsAt(".inbox"); for (Iterator j = inboxes.iterator(); j.hasNext();) { final HierarchicalConfiguration inboxSub = (HierarchicalConfiguration) j.next(); String inboxDir = inboxSub.getString("[@dirPath]"); File tmpDir = FileUtils.createPath(baseDir, inboxDir); Inbox inbox = new TransparentInbox(tmpDir, sedexId, MessageType.from(inboxSub.getString(MSG_TYPES))); checkSedexIdMsgTypes(inbox); receiverConfiguration.addInbox(inbox); } // receipt folder if (sub.getString("receipts[@dirPath]") != null) { String receiptsDir = sub.getString("receipts[@dirPath]"); File tmpDir = FileUtils.createPath(baseDir, receiptsDir); statusCheckerConfiguration.addReceiptFolder(new ReceiptsFolder(tmpDir, sedexId, MessageType.from(sub.getString("receipts[@msgTypes]")))); } } // wrap-up for MANTIS 5023 clientConfiguration.setReceiverConfiguration(receiverConfiguration); LOG.info("receiver added, " + receiverConfiguration); clientConfiguration.setStatusCheckerConfiguration(statusCheckerConfiguration); LOG.info("status checker added, " + statusCheckerConfiguration); // **************** status database settings clientConfiguration.setLogServiceConfiguration(createLogServiceConfig(xmlConfig)); // the localRecipients (replacement from targetDirectoryResolver) final List<HierarchicalConfiguration> localRecipients = xmlConfig .configurationsAt("messageHandler.localRecipients.localRecipient"); for (HierarchicalConfiguration lr : localRecipients) { final String recipientId = lr.getString("[@recipientId]"); final String msgTypes = lr.getString(MSG_TYPES); LocalRecipient localRecipient = new LocalRecipient(recipientId, msgTypes); LOG.info("LocalRecipient: " + localRecipient); clientConfiguration.addLocalRecipient(localRecipient); } // if the protocol files should be created ProtocolWriter.getInstance() .setActive(xmlConfig.getBoolean("messageHandler.protocol[@createPerMessageProtocols]", false)); LOG.info(ProtocolWriter.getInstance().isActive() ? "protocol writer configured" : "protocol writer not configured"); }
From source file:ch.admin.suis.msghandler.config.ClientConfigurationFactory.java
private void setupSiginingOutbox(List cfgSigningOutboxes, String baseDir, Outbox outbox) throws ConfigurationException { for (Iterator k = cfgSigningOutboxes.iterator(); k.hasNext();) { HierarchicalConfiguration signingOutboxSub = (HierarchicalConfiguration) k.next(); // where the original files are final String srcDirName = signingOutboxSub.getString(DIR_PATH); // where the original files should be moved to final String processDir = signingOutboxSub.getString(".[@processedDir]"); final String batchSignerCfg = signingOutboxSub.getString(".[@signingProfilePath]"); File fileSigningOutbox = FileUtils.createPath(baseDir, srcDirName); FileUtils.isDirectory(fileSigningOutbox, DIR_PATH); File fileProcessDir = StringUtils.isEmpty(processDir) ? null : FileUtils.createPath(baseDir, processDir); if (fileProcessDir != null) { FileUtils.isDirectory(fileProcessDir, ".[@processedDir]"); }//from ww w. j a v a 2 s. c o m File fileBatchSignerCfg = FileUtils.createPath(baseDir, batchSignerCfg); FileUtils.isFile(fileBatchSignerCfg, ".[@signingProfilePath]"); checkSignatureOutbox(fileSigningOutbox, fileProcessDir); SigningOutbox signingOutbox = null; List certificateConfigs = signingOutboxSub.configurationsAt(".certificate"); List certificateFileConfigs = signingOutboxSub.configurationsAt(".certificateConfigFile"); //First check if the signing config is in the MH config.xml file. Such as p12 file and password if (certificateConfigs.size() == 1) { HierarchicalConfiguration certificateConfigsSub = (HierarchicalConfiguration) certificateConfigs .get(0); final String p12FileName = certificateConfigsSub.getString(".[@filePath]"); File fileP12 = FileUtils.createPath(baseDir, p12FileName); FileUtils.isFile(fileP12, "certificate[@filePath]"); final String p12Password = certificateConfigsSub.getString(".[@password]"); signingOutbox = new SigningOutboxMHCfg(fileP12, p12Password, fileSigningOutbox, fileBatchSignerCfg, fileProcessDir); LOG.info("SigningOutbox p12 file: " + fileP12.getAbsolutePath()); } //Second if not in MH config.xml then try the sedex certificateConfiguration else if (certificateFileConfigs.size() == 1) { HierarchicalConfiguration certificateConfigsSub = (HierarchicalConfiguration) certificateFileConfigs .get(0); final String fileName = certificateConfigsSub.getString(".[@filePath]"); File sedexCertConfig = FileUtils.createPath(baseDir, fileName); signingOutbox = new SigningOutboxSedexCfg(sedexCertConfig, fileSigningOutbox, fileBatchSignerCfg, fileProcessDir); LOG.info("SigningOutbox sedex certificateConfiguration file: " + sedexCertConfig.getAbsolutePath()); } outbox.addSigningOutbox(signingOutbox); // add it LOG.info("signing outbox added to " + outbox.getDirectory() + ": " + signingOutbox); } }
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 a v a2 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'."); } 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'"); }/*from w ww . j ava 2 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 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'"); }/* w w w . j av a 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'."); } 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'"); }/* ww w . java 2s . com*/ 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); } }