List of usage examples for org.apache.commons.configuration XMLConfiguration setProperty
public void setProperty(String key, Object value)
From source file:com.bytelightning.opensource.pokerface.PokerFaceApp.java
public static void main(String[] args) { if (JavaVersionAsFloat() < (1.8f - Float.MIN_VALUE)) { System.err.println("PokerFace requires at least Java v8 to run."); return;// w w w.j ava 2s . co m } // Configure the command line options parser Options options = new Options(); options.addOption("h", false, "help"); options.addOption("listen", true, "(http,https,secure,tls,ssl,CertAlias)=Address:Port for https."); options.addOption("keystore", true, "Filepath for PokerFace certificate keystore."); options.addOption("storepass", true, "The store password of the keystore."); options.addOption("keypass", true, "The key password of the keystore."); options.addOption("target", true, "Remote Target requestPattern=targetUri"); // NOTE: targetUri may contain user-info and if so will be interpreted as the alias of a cert to be presented to the remote target options.addOption("servercpu", true, "Number of cores the server should use."); options.addOption("targetcpu", true, "Number of cores the http targets should use."); options.addOption("trustany", false, "Ignore certificate identity errors from target servers."); options.addOption("files", true, "Filepath to a directory of static files."); options.addOption("config", true, "Path for XML Configuration file."); options.addOption("scripts", true, "Filepath for root scripts directory."); options.addOption("library", true, "JavaScript library to load into global context."); options.addOption("watch", false, "Dynamically watch scripts directory for changes."); options.addOption("dynamicTargetScripting", false, "WARNING! This option allows scripts to redirect requests to *any* other remote server."); CommandLine cmdLine = null; // parse the command line. try { CommandLineParser parser = new PosixParser(); cmdLine = parser.parse(options, args); if (args.length == 0 || cmdLine.hasOption('h')) { HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(PokerFaceApp.class.getSimpleName(), options); return; } } catch (ParseException exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); return; } catch (Exception ex) { ex.printStackTrace(System.err); return; } XMLConfiguration config = new XMLConfiguration(); try { if (cmdLine.hasOption("config")) { Path tmp = Utils.MakePath(cmdLine.getOptionValue("config")); if (!Files.exists(tmp)) throw new FileNotFoundException("Configuration file does not exist."); if (Files.isDirectory(tmp)) throw new FileNotFoundException("'config' path is not a file."); // This is a bit of a pain, but but let's make sure we have a valid configuration file before we actually try to use it. config.setEntityResolver(new DefaultEntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException { InputSource retVal = super.resolveEntity(publicId, systemId); if ((retVal == null) && (systemId != null)) { try { URL entityURL; if (systemId.endsWith("/PokerFace_v1Config.xsd")) entityURL = PokerFaceApp.class.getResource("/PokerFace_v1Config.xsd"); else entityURL = new URL(systemId); URLConnection connection = entityURL.openConnection(); connection.setUseCaches(false); InputStream stream = connection.getInputStream(); retVal = new InputSource(stream); retVal.setSystemId(entityURL.toExternalForm()); } catch (Throwable e) { return retVal; } } return retVal; } }); config.setSchemaValidation(true); config.setURL(tmp.toUri().toURL()); config.load(); if (cmdLine.hasOption("listen")) System.out.println("IGNORING 'listen' option because a configuration file was supplied."); if (cmdLine.hasOption("target")) System.out.println("IGNORING 'target' option(s) because a configuration file was supplied."); if (cmdLine.hasOption("scripts")) System.out.println("IGNORING 'scripts' option because a configuration file was supplied."); if (cmdLine.hasOption("library")) System.out.println("IGNORING 'library' option(s) because a configuration file was supplied."); } else { String[] serverStrs; String[] addr = { null }; String[] port = { null }; serverStrs = cmdLine.getOptionValues("listen"); if (serverStrs == null) throw new MissingOptionException("No listening addresses specified specified"); for (int i = 0; i < serverStrs.length; i++) { String addrStr; String alias = null; String protocol = null; Boolean https = null; int addrPos = serverStrs[i].indexOf('='); if (addrPos >= 0) { if (addrPos < 2) throw new IllegalArgumentException("Invalid http argument."); else if (addrPos + 1 >= serverStrs[i].length()) throw new IllegalArgumentException("Invalid http argument."); addrStr = serverStrs[i].substring(addrPos + 1, serverStrs[i].length()); String[] types = serverStrs[i].substring(0, addrPos).split(","); for (String type : types) { if (type.equalsIgnoreCase("http")) break; else if (type.equalsIgnoreCase("https") || type.equalsIgnoreCase("secure")) https = true; else if (type.equalsIgnoreCase("tls") || type.equalsIgnoreCase("ssl")) protocol = type.toUpperCase(); else alias = type; } } else addrStr = serverStrs[i]; ParseAddressString(addrStr, addr, port, alias != null ? 443 : 80); config.addProperty("server.listen(" + i + ")[@address]", addr[0]); config.addProperty("server.listen(" + i + ")[@port]", port[0]); if (alias != null) config.addProperty("server.listen(" + i + ")[@alias]", alias); if (protocol != null) config.addProperty("server.listen(" + i + ")[@protocol]", protocol); if (https != null) config.addProperty("server.listen(" + i + ")[@secure]", https); } String servercpu = cmdLine.getOptionValue("servercpu"); if (servercpu != null) config.setProperty("server[@cpu]", servercpu); String clientcpu = cmdLine.getOptionValue("targetcpu"); if (clientcpu != null) config.setProperty("targets[@cpu]", clientcpu); // Configure static files if (cmdLine.hasOption("files")) { Path tmp = Utils.MakePath(cmdLine.getOptionValue("files")); if (!Files.exists(tmp)) throw new FileNotFoundException("Files directory does not exist."); if (!Files.isDirectory(tmp)) throw new FileNotFoundException("'files' path is not a directory."); config.setProperty("files.rootDirectory", tmp.toAbsolutePath().toUri()); } // Configure scripting if (cmdLine.hasOption("scripts")) { Path tmp = Utils.MakePath(cmdLine.getOptionValue("scripts")); if (!Files.exists(tmp)) throw new FileNotFoundException("Scripts directory does not exist."); if (!Files.isDirectory(tmp)) throw new FileNotFoundException("'scripts' path is not a directory."); config.setProperty("scripts.rootDirectory", tmp.toAbsolutePath().toUri()); config.setProperty("scripts.dynamicWatch", cmdLine.hasOption("watch")); String[] libraries = cmdLine.getOptionValues("library"); if (libraries != null) { for (int i = 0; i < libraries.length; i++) { Path lib = Utils.MakePath(libraries[i]); if (!Files.exists(lib)) throw new FileNotFoundException( "Script library does not exist [" + libraries[i] + "]."); if (Files.isDirectory(lib)) throw new FileNotFoundException( "Script library is not a file [" + libraries[i] + "]."); config.setProperty("scripts.library(" + i + ")", lib.toAbsolutePath().toUri()); } } } else if (cmdLine.hasOption("watch")) System.out.println("IGNORING 'watch' option as no 'scripts' directory was specified."); else if (cmdLine.hasOption("library")) System.out.println("IGNORING 'library' option as no 'scripts' directory was specified."); } String keyStorePath = cmdLine.getOptionValue("keystore"); if (keyStorePath != null) config.setProperty("keystore", keyStorePath); String keypass = cmdLine.getOptionValue("keypass"); if (keypass != null) config.setProperty("keypass", keypass); String storepass = cmdLine.getOptionValue("storepass"); if (storepass != null) config.setProperty("storepass", keypass); if (cmdLine.hasOption("trustany")) config.setProperty("targets[@trustAny]", true); config.setProperty("scripts.dynamicTargetScripting", cmdLine.hasOption("dynamicTargetScripting")); String[] targetStrs = cmdLine.getOptionValues("target"); if (targetStrs != null) { for (int i = 0; i < targetStrs.length; i++) { int uriPos = targetStrs[i].indexOf('='); if (uriPos < 2) throw new IllegalArgumentException("Invalid target argument."); else if (uriPos + 1 >= targetStrs[i].length()) throw new IllegalArgumentException("Invalid target argument."); String patternStr = targetStrs[i].substring(0, uriPos); String urlStr = targetStrs[i].substring(uriPos + 1, targetStrs[i].length()); String alias; try { URL url = new URL(urlStr); alias = url.getUserInfo(); String scheme = url.getProtocol(); if ((!"http".equals(scheme)) && (!"https".equals(scheme))) throw new IllegalArgumentException("Invalid target uri scheme."); int port = url.getPort(); if (port < 0) port = url.getDefaultPort(); urlStr = scheme + "://" + url.getHost() + ":" + port + url.getPath(); String ref = url.getRef(); if (ref != null) urlStr += "#" + ref; } catch (MalformedURLException ex) { throw new IllegalArgumentException("Malformed target uri"); } config.addProperty("targets.target(" + i + ")[@pattern]", patternStr); config.addProperty("targets.target(" + i + ")[@url]", urlStr); if (alias != null) config.addProperty("targets.target(" + i + ")[@alias]", alias); } } // config.save(System.out); } catch (Throwable e) { e.printStackTrace(System.err); return; } // If we get here, we have a possibly valid configuration. try { final PokerFace p = new PokerFace(); p.config(config); if (p.start()) { PokerFace.Logger.warn("Started!"); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { PokerFace.Logger.warn("Initiating shutdown..."); p.stop(); PokerFace.Logger.warn("Shutdown completed!"); } catch (Throwable e) { PokerFace.Logger.error("Failed to shutdown cleanly!"); e.printStackTrace(System.err); } } }); } else { PokerFace.Logger.error("Failed to start!"); System.exit(-1); } } catch (Throwable e) { e.printStackTrace(System.err); } }
From source file:com.graphhopper.jsprit.examples.ConfigureAlgorithmInCodeInsteadOfPerXml.java
private static AlgorithmConfig getAlgorithmConfig() { AlgorithmConfig config = new AlgorithmConfig(); XMLConfiguration xmlConfig = config.getXMLConfiguration(); xmlConfig.setProperty("iterations", "2000"); xmlConfig.setProperty("construction.insertion[@name]", "bestInsertion"); xmlConfig.setProperty("strategy.memory", 1); String searchStrategy = "strategy.searchStrategies.searchStrategy"; xmlConfig.setProperty(searchStrategy + "(0)[@name]", "random_best"); xmlConfig.setProperty(searchStrategy + "(0).selector[@name]", "selectBest"); xmlConfig.setProperty(searchStrategy + "(0).acceptor[@name]", "acceptNewRemoveWorst"); xmlConfig.setProperty(searchStrategy + "(0).modules.module(0)[@name]", "ruin_and_recreate"); xmlConfig.setProperty(searchStrategy + "(0).modules.module(0).ruin[@name]", "randomRuin"); xmlConfig.setProperty(searchStrategy + "(0).modules.module(0).ruin.share", "0.3"); xmlConfig.setProperty(searchStrategy + "(0).modules.module(0).insertion[@name]", "bestInsertion"); xmlConfig.setProperty(searchStrategy + "(0).probability", "0.5"); xmlConfig.setProperty(searchStrategy + "(1)[@name]", "radial_best"); xmlConfig.setProperty(searchStrategy + "(1).selector[@name]", "selectBest"); xmlConfig.setProperty(searchStrategy + "(1).acceptor[@name]", "acceptNewRemoveWorst"); xmlConfig.setProperty(searchStrategy + "(1).modules.module(0)[@name]", "ruin_and_recreate"); xmlConfig.setProperty(searchStrategy + "(1).modules.module(0).ruin[@name]", "radialRuin"); xmlConfig.setProperty(searchStrategy + "(1).modules.module(0).ruin.share", "0.15"); xmlConfig.setProperty(searchStrategy + "(1).modules.module(0).insertion[@name]", "bestInsertion"); xmlConfig.setProperty(searchStrategy + "(1).probability", "0.5"); return config; }
From source file:jsprit.examples.ComputationalExperiments_alphaSenstivity.java
private static AlgorithmConfig getAlgorithmConfig(String alpha) { AlgorithmConfig config = new AlgorithmConfig(); XMLConfiguration xmlConfig = config.getXMLConfiguration(); xmlConfig.setProperty("iterations", 10000); xmlConfig.setProperty("construction.insertion[@name]", "bestInsertion"); xmlConfig.setProperty("strategy.memory", 1); String searchStrategy = "strategy.searchStrategies.searchStrategy"; xmlConfig.setProperty(searchStrategy + "(0).selector[@name]", "selectBest"); xmlConfig.setProperty(searchStrategy + "(0).acceptor[@name]", "schrimpfAcceptance"); xmlConfig.setProperty(searchStrategy + "(0).acceptor.alpha", alpha); xmlConfig.setProperty(searchStrategy + "(0).acceptor.warmup", "50"); xmlConfig.setProperty(searchStrategy + "(0).modules.module(0)[@name]", "ruin_and_recreate"); xmlConfig.setProperty(searchStrategy + "(0).modules.module(0).ruin[@name]", "randomRuin"); xmlConfig.setProperty(searchStrategy + "(0).modules.module(0).ruin.share", "0.3"); xmlConfig.setProperty(searchStrategy + "(0).modules.module(0).insertion[@name]", "bestInsertion"); xmlConfig.setProperty(searchStrategy + "(0).probability", ".5"); xmlConfig.setProperty(searchStrategy + "(1).selector[@name]", "selectBest"); xmlConfig.setProperty(searchStrategy + "(1).acceptor[@name]", "schrimpfAcceptance"); xmlConfig.setProperty(searchStrategy + "(1).modules.module(0)[@name]", "ruin_and_recreate"); xmlConfig.setProperty(searchStrategy + "(1).modules.module(0).ruin[@name]", "radialRuin"); xmlConfig.setProperty(searchStrategy + "(1).modules.module(0).ruin.share", "0.1"); xmlConfig.setProperty(searchStrategy + "(1).modules.module(0).insertion[@name]", "bestInsertion"); xmlConfig.setProperty(searchStrategy + "(1).probability", "0.5"); return config; }
From source file:edu.usc.goffish.gopher.impl.client.DeploymentTool.java
private void createClientConfig(StartFloeInfo info, String managerHost, String coordinatorHost) throws IOException, ConfigurationException { XMLConfiguration config = new XMLConfiguration(); config.setRootElementName("GopherConfiguration"); config.setProperty(FLOE_MANAGER, managerHost + ":" + MANAGER_PORT); config.setProperty(FLOE_COORDINATOR, coordinatorHost + ":" + COORDINATOR_PORT); info.getSourceInfo().sourceNodeTransport.values(); for (List<TransportInfoBase> b : info.getSourceInfo().sourceNodeTransport.values()) { for (TransportInfoBase base : b) { String host = base.getParams().get("hostAddress"); int dataPort = Integer.parseInt(base.getParams().get("tcpListenerPort")); int controlPort = Integer.parseInt(base.getControlChannelInfo().getParams().get("tcpListenerPort")); config.setProperty(DATA_FLOW_HOST, host); config.setProperty(DATA_FLOW_DATA_PORT, dataPort); config.setProperty(DATA_FLOW_CONTROL_PORT, controlPort); break; }//from w w w .jav a2s.c om break; } config.save(new FileWriter(CONFIG_FILE_PATH)); }
From source file:cirad.cgh.vcf2fasta.Vcf2fastaUI.java
private XMLConfiguration initConfig() { System.out.println("INIT"); try {//from w ww . j a v a 2 s . co m File base = this.getSession().getService().getBaseDirectory(); File webinf = new File(base, "WEB-INF"); File tmp = new File(base, "tmp"); if (!tmp.exists()) tmp.mkdirs(); XMLConfiguration config = new XMLConfiguration(new File(webinf, "config.xml")); config.setProperty("base", base.getAbsolutePath()); config.setExpressionEngine(new XPathExpressionEngine()); return config; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.graphhopper.jsprit.core.problem.io.VrpXMLWriter.java
private void writeProblemType(XMLConfiguration xmlConfig) { xmlConfig.setProperty("problemType.fleetSize", vrp.getFleetSize()); }
From source file:de.nec.nle.siafu.control.Controller.java
/** * Create a config file with default values. This is used when the config * file doesn't exist in the first place. * /*from w w w . j a v a 2 s . com*/ * @return the newly created configuration file. */ private XMLConfiguration createDefaultConfigFile() { System.out.println("Creating a default configuration file at " + DEFAULT_CONFIG_FILE); XMLConfiguration newConfig = new XMLConfiguration(); newConfig.setRootElementName("configuration"); newConfig.setProperty("commandlistener.enable", true); newConfig.setProperty("commandlistener.tcpport", DEFAULT_PORT); newConfig.setProperty("ui.usegui", true); newConfig.setProperty("ui.speed", DEFAULT_UI_SPEED); newConfig.setProperty("ui.gradientcache.prefill", true); newConfig.setProperty("ui.gradientcache.size", DEFAULT_CACHE_SIZE); newConfig.setProperty("output.type", "null"); newConfig.setProperty("output.csv.path", System.getProperty("user.home") + File.separator + "SiafuContext.csv"); newConfig.setProperty("output.csv.interval", DEFAULT_CSV_INTERVAL); newConfig.setProperty("output.csv.keephistory", true); try { newConfig.setFileName(DEFAULT_CONFIG_FILE); newConfig.save(); } catch (ConfigurationException e) { throw new RuntimeException("Can not create a default config file at " + DEFAULT_CONFIG_FILE, e); } return newConfig; }
From source file:com.graphhopper.jsprit.core.problem.io.VrpXMLWriter.java
private void writeVehiclesAndTheirTypes(XMLConfiguration xmlConfig) { //vehicles/* ww w .jav a 2s . co m*/ String vehiclePathString = Schema.VEHICLES + "." + Schema.VEHICLE; int counter = 0; for (Vehicle vehicle : vrp.getVehicles()) { xmlConfig.setProperty(vehiclePathString + "(" + counter + ").id", vehicle.getId()); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").typeId", vehicle.getType().getTypeId()); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").startLocation.id", vehicle.getStartLocation().getId()); if (vehicle.getStartLocation().getCoordinate() != null) { xmlConfig.setProperty(vehiclePathString + "(" + counter + ").startLocation.coord[@x]", vehicle.getStartLocation().getCoordinate().getX()); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").startLocation.coord[@y]", vehicle.getStartLocation().getCoordinate().getY()); } if (vehicle.getStartLocation().getIndex() != Location.NO_INDEX) { xmlConfig.setProperty(vehiclePathString + "(" + counter + ").startLocation.index", vehicle.getStartLocation().getIndex()); } xmlConfig.setProperty(vehiclePathString + "(" + counter + ").endLocation.id", vehicle.getEndLocation().getId()); if (vehicle.getEndLocation().getCoordinate() != null) { xmlConfig.setProperty(vehiclePathString + "(" + counter + ").endLocation.coord[@x]", vehicle.getEndLocation().getCoordinate().getX()); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").endLocation.coord[@y]", vehicle.getEndLocation().getCoordinate().getY()); } if (vehicle.getEndLocation().getIndex() != Location.NO_INDEX) { xmlConfig.setProperty(vehiclePathString + "(" + counter + ").endLocation.index", vehicle.getEndLocation().getId()); } xmlConfig.setProperty(vehiclePathString + "(" + counter + ").timeSchedule.start", vehicle.getEarliestDeparture()); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").timeSchedule.end", vehicle.getLatestArrival()); if (vehicle.getBreak() != null) { Collection<TimeWindow> tws = vehicle.getBreak().getTimeWindows(); int index = 0; xmlConfig.setProperty(vehiclePathString + "(" + counter + ").break.duration", vehicle.getBreak().getServiceDuration()); for (TimeWindow tw : tws) { xmlConfig.setProperty(vehiclePathString + "(" + counter + ").break.timeWindows.timeWindow(" + index + ").start", tw.getStart()); xmlConfig.setProperty( vehiclePathString + "(" + counter + ").break.timeWindows.timeWindow(" + index + ").end", tw.getEnd()); ++index; } } xmlConfig.setProperty(vehiclePathString + "(" + counter + ").returnToDepot", vehicle.isReturnToDepot()); //write skills String skillString = getSkillString(vehicle); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").skills", skillString); counter++; } //types String typePathString = Schema.builder().append(Schema.TYPES).dot(Schema.TYPE).build(); int typeCounter = 0; for (VehicleType type : vrp.getTypes()) { xmlConfig.setProperty(typePathString + "(" + typeCounter + ").id", type.getTypeId()); for (int i = 0; i < type.getCapacityDimensions().getNuOfDimensions(); i++) { xmlConfig.setProperty( typePathString + "(" + typeCounter + ").capacity-dimensions.dimension(" + i + ")[@index]", i); xmlConfig.setProperty( typePathString + "(" + typeCounter + ").capacity-dimensions.dimension(" + i + ")", type.getCapacityDimensions().get(i)); } xmlConfig.setProperty(typePathString + "(" + typeCounter + ").costs.fixed", type.getVehicleCostParams().fix); xmlConfig.setProperty(typePathString + "(" + typeCounter + ").costs.distance", type.getVehicleCostParams().perDistanceUnit); xmlConfig.setProperty(typePathString + "(" + typeCounter + ").costs.time", type.getVehicleCostParams().perTimeUnit); typeCounter++; } }
From source file:jsprit.core.problem.io.VrpXMLWriter.java
private void writeVehiclesAndTheirTypes(XMLConfiguration xmlConfig) { //vehicles/* w ww .j a va 2 s. c o m*/ String vehiclePathString = Schema.VEHICLES + "." + Schema.VEHICLE; int counter = 0; for (Vehicle vehicle : vrp.getVehicles()) { xmlConfig.setProperty(vehiclePathString + "(" + counter + ").id", vehicle.getId()); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").typeId", vehicle.getType().getTypeId()); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").startLocation.id", vehicle.getStartLocation().getId()); if (vehicle.getStartLocation().getCoordinate() != null) { xmlConfig.setProperty(vehiclePathString + "(" + counter + ").startLocation.coord[@x]", vehicle.getStartLocation().getCoordinate().getX()); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").startLocation.coord[@y]", vehicle.getStartLocation().getCoordinate().getY()); } if (vehicle.getStartLocation().getIndex() != Location.NO_INDEX) { xmlConfig.setProperty(vehiclePathString + "(" + counter + ").startLocation.index", vehicle.getStartLocation().getIndex()); } xmlConfig.setProperty(vehiclePathString + "(" + counter + ").endLocation.id", vehicle.getEndLocation().getId()); if (vehicle.getEndLocation().getCoordinate() != null) { xmlConfig.setProperty(vehiclePathString + "(" + counter + ").endLocation.coord[@x]", vehicle.getEndLocation().getCoordinate().getX()); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").endLocation.coord[@y]", vehicle.getEndLocation().getCoordinate().getY()); } if (vehicle.getEndLocation().getIndex() != Location.NO_INDEX) { xmlConfig.setProperty(vehiclePathString + "(" + counter + ").endLocation.index", vehicle.getEndLocation().getId()); } xmlConfig.setProperty(vehiclePathString + "(" + counter + ").timeSchedule.start", vehicle.getEarliestDeparture()); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").timeSchedule.end", vehicle.getLatestArrival()); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").returnToDepot", vehicle.isReturnToDepot()); //write skills String skillString = getSkillString(vehicle); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").skills", skillString); counter++; } //types String typePathString = Schema.builder().append(Schema.TYPES).dot(Schema.TYPE).build(); int typeCounter = 0; for (VehicleType type : vrp.getTypes()) { xmlConfig.setProperty(typePathString + "(" + typeCounter + ").id", type.getTypeId()); for (int i = 0; i < type.getCapacityDimensions().getNuOfDimensions(); i++) { xmlConfig.setProperty( typePathString + "(" + typeCounter + ").capacity-dimensions.dimension(" + i + ")[@index]", i); xmlConfig.setProperty( typePathString + "(" + typeCounter + ").capacity-dimensions.dimension(" + i + ")", type.getCapacityDimensions().get(i)); } xmlConfig.setProperty(typePathString + "(" + typeCounter + ").costs.fixed", type.getVehicleCostParams().fix); xmlConfig.setProperty(typePathString + "(" + typeCounter + ").costs.distance", type.getVehicleCostParams().perDistanceUnit); xmlConfig.setProperty(typePathString + "(" + typeCounter + ").costs.time", type.getVehicleCostParams().perTimeUnit); typeCounter++; } }
From source file:com.graphhopper.jsprit.io.problem.VrpXMLWriter.java
private void writeVehiclesAndTheirTypes(XMLConfiguration xmlConfig) { //vehicles/*from w w w . java 2 s . c o m*/ String vehiclePathString = Schema.VEHICLES + "." + Schema.VEHICLE; int counter = 0; for (Vehicle vehicle : vrp.getVehicles()) { xmlConfig.setProperty(vehiclePathString + "(" + counter + ").id", vehicle.getId()); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").typeId", vehicle.getType().getTypeId()); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").startLocation.id", vehicle.getStartLocation().getId()); if (vehicle.getStartLocation().getCoordinate() != null) { xmlConfig.setProperty(vehiclePathString + "(" + counter + ").startLocation.coord[@x]", vehicle.getStartLocation().getCoordinate().getX()); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").startLocation.coord[@y]", vehicle.getStartLocation().getCoordinate().getY()); } if (vehicle.getStartLocation().getIndex() != Location.NO_INDEX) { xmlConfig.setProperty(vehiclePathString + "(" + counter + ").startLocation.index", vehicle.getStartLocation().getIndex()); } xmlConfig.setProperty(vehiclePathString + "(" + counter + ").endLocation.id", vehicle.getEndLocation().getId()); if (vehicle.getEndLocation().getCoordinate() != null) { xmlConfig.setProperty(vehiclePathString + "(" + counter + ").endLocation.coord[@x]", vehicle.getEndLocation().getCoordinate().getX()); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").endLocation.coord[@y]", vehicle.getEndLocation().getCoordinate().getY()); } if (vehicle.getEndLocation().getIndex() != Location.NO_INDEX) { xmlConfig.setProperty(vehiclePathString + "(" + counter + ").endLocation.index", vehicle.getEndLocation().getId()); } xmlConfig.setProperty(vehiclePathString + "(" + counter + ").timeSchedule.start", vehicle.getEarliestDeparture()); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").timeSchedule.end", vehicle.getLatestArrival()); if (vehicle.getBreak() != null) { Collection<TimeWindow> tws = vehicle.getBreak().getTimeWindows(); int index = 0; xmlConfig.setProperty(vehiclePathString + "(" + counter + ").breaks.duration", vehicle.getBreak().getServiceDuration()); for (TimeWindow tw : tws) { xmlConfig.setProperty(vehiclePathString + "(" + counter + ").breaks.timeWindows.timeWindow(" + index + ").start", tw.getStart()); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").breaks.timeWindows.timeWindow(" + index + ").end", tw.getEnd()); ++index; } } xmlConfig.setProperty(vehiclePathString + "(" + counter + ").returnToDepot", vehicle.isReturnToDepot()); //write skills String skillString = getSkillString(vehicle); xmlConfig.setProperty(vehiclePathString + "(" + counter + ").skills", skillString); counter++; } //types String typePathString = Schema.builder().append(Schema.TYPES).dot(Schema.TYPE).build(); int typeCounter = 0; for (VehicleType type : vrp.getTypes()) { xmlConfig.setProperty(typePathString + "(" + typeCounter + ").id", type.getTypeId()); for (int i = 0; i < type.getCapacityDimensions().getNuOfDimensions(); i++) { xmlConfig.setProperty( typePathString + "(" + typeCounter + ").capacity-dimensions.dimension(" + i + ")[@index]", i); xmlConfig.setProperty( typePathString + "(" + typeCounter + ").capacity-dimensions.dimension(" + i + ")", type.getCapacityDimensions().get(i)); } xmlConfig.setProperty(typePathString + "(" + typeCounter + ").costs.fixed", type.getVehicleCostParams().fix); xmlConfig.setProperty(typePathString + "(" + typeCounter + ").costs.distance", type.getVehicleCostParams().perDistanceUnit); xmlConfig.setProperty(typePathString + "(" + typeCounter + ").costs.time", type.getVehicleCostParams().perTransportTimeUnit); xmlConfig.setProperty(typePathString + "(" + typeCounter + ").costs.service", type.getVehicleCostParams().perServiceTimeUnit); xmlConfig.setProperty(typePathString + "(" + typeCounter + ").costs.wait", type.getVehicleCostParams().perWaitingTimeUnit); typeCounter++; } }