List<HierarchicalConfiguration> servers = config.configurationsAt("failoverServers.server"); for(HierarchicalConfiguration server : servers) { System.out.println(server.getString("ipAddress")); }
private static Coordinate getCoord(HierarchicalConfiguration serviceConfig, String prefix) { Coordinate pickupCoord = null; if (serviceConfig.getString(prefix + "coord[@x]") != null && serviceConfig.getString(prefix + "coord[@y]") != null) { double x = Double.parseDouble(serviceConfig.getString(prefix + "coord[@x]")); double y = Double.parseDouble(serviceConfig.getString(prefix + "coord[@y]")); pickupCoord = Coordinate.newInstance(x, y); } return pickupCoord; }
private static String getName(HierarchicalConfiguration strategyConfig) { if (strategyConfig.containsKey("[@name]")) { return strategyConfig.getString("[@name]"); } return ""; }
private static PrematureAlgorithmTermination getTerminationCriterion(HierarchicalConfiguration config, Set<PrioritizedVRAListener> algorithmListeners) { String basedOn = config.getString("[@basedOn]"); if (basedOn == null) { log.debug("set default prematureBreak, i.e. no premature break at all."); String iter = config.getString("iterations"); if (iter == null) throw new IllegalStateException("iterations is missing"); int iterations = Integer.valueOf(iter); String timeString = config.getString("time"); if (timeString == null) throw new IllegalStateException("time is missing"); long time = Long.parseLong(timeString); String thresholdString = config.getString("threshold"); String iterationsString = config.getString("iterations"); if (thresholdString == null) throw new IllegalStateException("threshold is missing"); if (iterationsString == null) throw new IllegalStateException("iterations is missing");
private static InsertionStrategy createInitialSolution(XMLConfiguration config, final VehicleRoutingProblem vrp, VehicleFleetManager vehicleFleetManager, final StateManager routeStates, Set<PrioritizedVRAListener> algorithmListeners, TypedMap definedClasses, ExecutorService executorService, int nuOfThreads, final SolutionCostCalculator solutionCostCalculator, ConstraintManager constraintManager, boolean addDefaultCostCalculators) { List<HierarchicalConfiguration> modConfigs = config.configurationsAt("construction.insertion"); if (modConfigs == null) return null; if (modConfigs.isEmpty()) return null; if (modConfigs.size() != 1) throw new IllegalStateException("#construction.modules != 1. 1 expected"); HierarchicalConfiguration modConfig = modConfigs.get(0); String insertionName = modConfig.getString("[@name]"); if (insertionName == null) throw new IllegalStateException("insertion[@name] is missing."); String insertionId = modConfig.getString("[@id]"); if (insertionId == null) insertionId = "noId"; ModKey modKey = makeKey(insertionName, insertionId); InsertionStrategyKey insertionStrategyKey = new InsertionStrategyKey(modKey); InsertionStrategy insertionStrategy = definedClasses.get(insertionStrategyKey); if (insertionStrategy == null) { List<PrioritizedVRAListener> prioListeners = new ArrayList<PrioritizedVRAListener>(); insertionStrategy = createInsertionStrategy(modConfig, vrp, vehicleFleetManager, routeStates, prioListeners, executorService, nuOfThreads, constraintManager, addDefaultCostCalculators); algorithmListeners.addAll(prioListeners); definedClasses.put(insertionStrategyKey, insertionStrategy); } return insertionStrategy; }
String insertionName = config.getString("[@name]"); if (!insertionName.equals("bestInsertion") && !insertionName.equals("regretInsertion")) { throw new IllegalStateException(insertionName + " is not supported. use either \"bestInsertion\" or \"regretInsertion\""); String level = config.getString("level"); if (level.equals("local")) { iBuilder.setLocalLevel(addDefaultCostCalculators); int forwardLooking = 0; int memory = 1; String forward = config.getString("level[@forwardLooking]"); String mem = config.getString("level[@memory]"); if (forward != null) forwardLooking = Integer.parseInt(forward); else String val = config.getString("considerFixedCosts"); if (val == null) val = config.getString("considerFixedCost"); if (val.equals("true")) { double fixedCostWeight = 0.5; String weight = config.getString("considerFixedCosts[@weight]"); if (weight == null) weight = config.getString("considerFixedCost[@weight]"); if (weight != null) fixedCostWeight = Double.parseDouble(weight); else String allowVehicleSwitch = config.getString("allowVehicleSwitch"); if (allowVehicleSwitch != null) { iBuilder.setAllowVehicleSwitch(Boolean.parseBoolean(allowVehicleSwitch)); String fastRegret = config.getString("fastRegret");
private static SearchStrategyModule buildModule(HierarchicalConfiguration moduleConfig, final VehicleRoutingProblem vrp, VehicleFleetManager vehicleFleetManager, final StateManager routeStates, Set<PrioritizedVRAListener> algorithmListeners, TypedMap definedClasses, ExecutorService executorService, int nuOfThreads, ConstraintManager constraintManager, boolean addDefaultCostCalculators) { String moduleName = moduleConfig.getString("[@name]"); if (moduleName == null) throw new IllegalStateException("module(-name) is missing."); String moduleId = moduleConfig.getString("[@id]"); if (moduleId == null) moduleId = "noId"; ModKey modKey = makeKey(moduleName, moduleId); String ruin_name = moduleConfig.getString("ruin[@name]"); if (ruin_name == null) throw new IllegalStateException("module.ruin[@name] is missing."); String ruin_id = moduleConfig.getString("ruin[@id]"); if (ruin_id == null) ruin_id = "noId"; final RuinStrategy ruin; ModKey ruinKey = makeKey(ruin_name, ruin_id); if (ruin_name.equals("randomRuin")) { String shareToRuinString = moduleConfig.getString("ruin.share"); if (shareToRuinString == null) throw new IllegalStateException("module.ruin.share is missing."); double shareToRuin = Double.valueOf(shareToRuinString); ruin = getRandomRuin(vrp, routeStates, definedClasses, ruinKey, shareToRuin); } else if (ruin_name.equals("radialRuin")) { String shareToRuinString = moduleConfig.getString("ruin.share"); if (shareToRuinString == null) throw new IllegalStateException("module.ruin.share is missing."); double shareToRuin = Double.valueOf(shareToRuinString); ruin = getRadialRuin(vrp, routeStates, definedClasses, ruinKey, shareToRuin, jobDistance); } else if (ruin_name.equals("clusterRuin")) { String initialNumberJobsToRemoveString = moduleConfig.getString("ruin.initRemoveJobs"); if (initialNumberJobsToRemoveString == null) throw new IllegalStateException("module.ruin.initRemoveJobs is missing."); int initialNumberJobsToRemove = Integer.valueOf(initialNumberJobsToRemoveString);
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); 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.addService(service); } else { String shipmentId = actConfig.getString("shipmentId"); if (shipmentId == null) throw new IllegalArgumentException("either serviceId or shipmentId is missing");
private static SolutionSelector getSelector(HierarchicalConfiguration strategyConfig, VehicleRoutingProblem vrp, Set<PrioritizedVRAListener> algorithmListeners, TypedMap definedSelectors) { String selectorName = strategyConfig.getString("selector[@name]"); if (selectorName == null) throw new IllegalStateException("no solutionSelector defined. define either \"selectRandomly\" or \"selectBest\""); String selectorId = strategyConfig.getString("selector[@id]"); if (selectorId == null) selectorId = "noId"; ModKey modKey = makeKey(selectorName, selectorId); SelectorKey selectorKey = new SelectorKey(modKey); SolutionSelector definedSelector = definedSelectors.get(selectorKey); if (definedSelector != null) { return definedSelector; } if (selectorName.equals("selectRandomly")) { SelectRandomly selector = SelectRandomly.getInstance(); definedSelectors.put(selectorKey, selector); return selector; } if (selectorName.equals("selectBest")) { SelectBest selector = SelectBest.getInstance(); definedSelectors.put(selectorKey, selector); return selector; } throw new IllegalStateException("solutionSelector is not know. Currently, it only knows \"selectRandomly\" and \"selectBest\""); }
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); 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); String end = routeConfig.getString("end"); if (end == null) throw new IllegalArgumentException("route end-time is missing."); 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); if(type.equals("break")) { String serviceId = actConfig.getString("serviceId");
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) { 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")) { String locationId = vehicleConfig.getString("location.id"); if (locationId == null) { locationId = vehicleConfig.getString("startLocation.id"); 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]");
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) { String name = serviceConfig.getString("name"); if (name != null) builder.setName(name); String serviceLocationId = serviceConfig.getString("locationId"); if (serviceLocationId == null) { serviceLocationId = serviceConfig.getString("location.id"); String locationIndex = serviceConfig.getString("location.index"); if (locationIndex != null) locationBuilder.setIndex(Integer.parseInt(locationIndex)); builder.setLocation(locationBuilder.build()); String skillString = serviceConfig.getString("requiredSkills"); if (skillString != null) { String cleaned = skillString.replaceAll("\\s", "");
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) { String name = shipmentConfig.getString("name"); if (name != null) builder.setName(name); String pickupLocationId = shipmentConfig.getString("pickup.locationId"); if (pickupLocationId == null) pickupLocationId = shipmentConfig.getString("pickup.location.id"); if (pickupLocationId != null) { pickupLocationBuilder.setId(pickupLocationId); String pickupLocationIndex = shipmentConfig.getString("pickup.location.index"); if (pickupLocationIndex != null) pickupLocationBuilder.setIndex(Integer.parseInt(pickupLocationIndex)); builder.setPickupLocation(pickupLocationBuilder.build()); String pickupServiceTime = shipmentConfig.getString("pickup.duration"); if (pickupServiceTime != null) builder.setPickupServiceTime(Double.parseDouble(pickupServiceTime)); String deliveryLocationId = shipmentConfig.getString("delivery.locationId"); if (deliveryLocationId == null) deliveryLocationId = shipmentConfig.getString("delivery.location.id"); if (deliveryLocationId != null) { deliveryLocationBuilder.setId(deliveryLocationId);
private static SolutionAcceptor getAcceptor(HierarchicalConfiguration strategyConfig, VehicleRoutingProblem vrp, Set<PrioritizedVRAListener> algorithmListeners, TypedMap typedMap, int solutionMemory) { String acceptorName = strategyConfig.getString("acceptor[@name]"); if (acceptorName == null) throw new IllegalStateException("no solution acceptor is defined"); String acceptorId = strategyConfig.getString("acceptor[@id]"); if (acceptorId == null) acceptorId = "noId"; AcceptorKey acceptorKey = new AcceptorKey(makeKey(acceptorName, acceptorId)); String nuWarmupIterations = strategyConfig.getString("acceptor.warmup"); double alpha = strategyConfig.getDouble("acceptor.alpha"); SchrimpfAcceptance schrimpf = new SchrimpfAcceptance(solutionMemory, alpha);
/** * The pattern for converting an enum constant to a unique C-style type name. * * @return The pattern for converting an enum constant to a unique C-style type name. */ public String getEnumConstantNamePattern() { return this.config.getString("[@enumConstantNamePattern]", "%1$S_%2$S_%3$S_%9$S"); }
public Map<String, String> getFacetPatterns() { List<HierarchicalConfiguration> configs = this.source.configurationsAt("api-classes.facet"); HashMap<String, String> facets = new HashMap<String, String>(); for (HierarchicalConfiguration config : configs) { String pattern = config.getString("[@pattern]"); String name = config.getString("[@name]"); if (pattern != null && name != null) { facets.put(pattern, name); } } return facets; }
public Map<String, String> getClientPackageConversions() { List<HierarchicalConfiguration> conversionElements = this.config.configurationsAt("package-conversions.convert"); HashMap<String, String> conversions = new HashMap<String, String>(); conversions.put("java.lang.Exception", "client.java.lang.Exception"); conversions.put("java.util.Map.Entry", "java.util.Map.Entry"); for (HierarchicalConfiguration conversionElement : conversionElements) { conversions.put(conversionElement.getString("[@from]"), conversionElement.getString("[@to]")); } return conversions; }
public Set<String> getServerSideTypesToUse() { List<HierarchicalConfiguration> typeElements = this.config.configurationsAt("server-side-type"); TreeSet<String> types = new TreeSet<String>(); for (HierarchicalConfiguration typeElement : typeElements) { types.add(typeElement.getString("[@pattern]")); } return types; }
public DataTypeDetectionStrategy getDataTypeDetectionStrategy() { String dataTypeDetection = this.config.getString("[@datatype-detection]", null); if (dataTypeDetection != null) { try { return DataTypeDetectionStrategy.valueOf(dataTypeDetection); } catch (IllegalArgumentException e) { //fall through... } } return this.defaultDataTypeDetectionStrategy == null ? DataTypeDetectionStrategy.local : this.defaultDataTypeDetectionStrategy; }
/** * The subdirectory in the web application where the documentation will be put. * * @return The subdirectory in the web application where the documentation will be put. */ public File getDocsDir() { String docsDir = this.config.getString("[@docsDir]"); return docsDir != null ? resolveFile(docsDir) : this.defaultDocsDir != null ? this.defaultDocsDir : new File(this.enunciate.getBuildDir(), getName()); }