本文整理了Java中org.matsim.core.utils.io.IOUtils.newUrl()
方法的一些代码示例,展示了IOUtils.newUrl()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.newUrl()
方法的具体详情如下:
包路径:org.matsim.core.utils.io.IOUtils
类名称:IOUtils
方法名:newUrl
暂无
代码示例来源:origin: matsim-org/matsim
@Test
public void testNewUrl() throws MalformedURLException {
URL context = Paths.get("").toUri().toURL();
System.out.println(context.toString());
URL url = IOUtils.newUrl(context, "C:\\windows\\directory\\filename.txt");
System.out.println(url.toString());
}
代码示例来源:origin: matsim-org/matsim
private void loadVehicles() throws UncheckedIOException {
final String vehiclesFile = this.config.vehicles().getVehiclesFile();
if ( vehiclesFile != null ) {
log.info("loading vehicles from " + vehiclesFile );
new VehicleReaderV1(this.scenario.getVehicles()).parse(IOUtils.newUrl(this.config.getContext(), vehiclesFile));
}
else {
log.info("no vehicles file set in config, not loading any vehicles");
}
}
代码示例来源:origin: matsim-org/matsim
public static void main(String[] args) throws IOException {
Config config = ConfigUtils.loadConfig(IOUtils.newUrl(ExamplesUtils.getTestScenarioURL("benchmark"), "config.xml"));
Controler ctl = new Controler(config);
ctl.getConfig().controler().setCreateGraphs(false);
ctl.run();
}
代码示例来源:origin: matsim-org/matsim
public Config prepareConfig(){
final URL url = ExamplesUtils.getTestScenarioURL("freight-chessboard-9x9");
final URL configURL = IOUtils.newUrl(url, "config.xml");
config = ConfigUtils.loadConfig(configURL );
config.controler().setOverwriteFileSetting( OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles );
config.global().setRandomSeed(4177);
config.controler().setOutputDirectory("./output/");
return config;
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testInput_V4() {
final String testFile = new File(utils.getOutputDirectory() + "/plans.xml.gz").getAbsolutePath();
// create test file in V4 format
Config config = ConfigUtils.createConfig(ExamplesUtils.getTestScenarioURL("berlin"));
final Scenario scenario = ScenarioUtils.createScenario(config);
new MatsimNetworkReader(scenario.getNetwork()).parse(IOUtils.newUrl(config.getContext(), NET_FILE));
new PopulationReader(scenario).parse(IOUtils.newUrl(config.getContext(), BASE_FILE));
new PopulationWriter(scenario.getPopulation(), scenario.getNetwork()).writeV4(testFile);
testConversionAtInput(testFile);
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testModifyPaths_missingSeparator() throws IOException {
Config config = ConfigUtils.loadConfig(IOUtils.newUrl(ExamplesUtils.getTestScenarioURL("equil"), "config.xml"));
Assert.assertEquals("network.xml", config.network().getInputFile());
ConfigUtils.modifyFilePaths(config, "/home/username/matsim");
Assert.assertThat(config.network().getInputFile(), anyOf(is("/home/username/matsim/network.xml"),is("/home/username/matsim\\network.xml")));
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testInput_V5() {
final String testFile = new File(utils.getOutputDirectory() + "/plans.xml.gz").getAbsolutePath();
// create test file in V5 format
Config config = ConfigUtils.createConfig(ExamplesUtils.getTestScenarioURL("berlin"));
final Scenario scenario = ScenarioUtils.createScenario(config);
// necessary for v4...
new MatsimNetworkReader(scenario.getNetwork()).parse(IOUtils.newUrl(config.getContext(), NET_FILE));
new PopulationReader(scenario).parse(IOUtils.newUrl(config.getContext(), BASE_FILE));
new PopulationWriter(scenario.getPopulation(), scenario.getNetwork()).writeV5(testFile);
testConversionAtInput(testFile);
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testModifyPaths_withSeparator() throws IOException {
Config config = ConfigUtils.loadConfig(IOUtils.newUrl(ExamplesUtils.getTestScenarioURL("equil"), "config.xml"));
Assert.assertEquals("network.xml", config.network().getInputFile());
ConfigUtils.modifyFilePaths(config, "/home/username/matsim/");
Assert.assertThat(config.network().getInputFile(), anyOf(is("/home/username/matsim/network.xml"),is("/home/username/matsim\\network.xml")));
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testReprojectionAtImport() {
final Scenario originalScenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
final Scenario reprojectedScenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
new MatsimFacilitiesReader( originalScenario ).parse(IOUtils.newUrl(ExamplesUtils.getTestScenarioURL("chessboard"), "facilities.xml"));
new MatsimFacilitiesReader( INITIAL_CRS, TARGET_CRS, reprojectedScenario.getActivityFacilities() ).parse(IOUtils.newUrl(ExamplesUtils.getTestScenarioURL("chessboard"), "facilities.xml"));
assertScenarioReprojectedCorrectly(originalScenario, reprojectedScenario);
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testLoadConfig_filenameOnly() throws IOException {
Config config = ConfigUtils.loadConfig(IOUtils.newUrl(ExamplesUtils.getTestScenarioURL("equil"), "config.xml"));
Assert.assertNotNull(config);
Assert.assertEquals("network.xml", config.network().getInputFile());
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testLoadScenario_loadTransitStopsAttributes() {
Config config = ConfigUtils.loadConfig(IOUtils.newUrl(this.util.classInputResourcePath(), "transitConfig.xml"));
config.transit().setTransitStopsAttributesFile("transitStopsAttributes.xml");
Scenario scenario = ScenarioUtils.loadScenario(config);
Assert.assertEquals(Boolean.TRUE, scenario.getTransitSchedule().getTransitStopsAttributes().getAttribute("1", "hasP+R"));
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testLoadScenario_loadPersonAttributes() {
Config config = ConfigUtils.loadConfig(IOUtils.newUrl(this.util.classInputResourcePath(), "personAttributesConfig.xml"));
config.plans().addParam("inputPersonAttributesFile", "personAttributes.xml");
Scenario scenario = ScenarioUtils.loadScenario(config);
Assert.assertEquals("world", scenario.getPopulation().getPersonAttributes().getAttribute("1", "hello"));
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testLoadScenario_loadTransitLinesAttributes() {
Config config = ConfigUtils.loadConfig(IOUtils.newUrl(this.util.classInputResourcePath(), "transitConfig.xml"));
config.transit().setTransitLinesAttributesFile("transitLinesAttributes.xml");
Scenario scenario = ScenarioUtils.loadScenario(config);
Assert.assertEquals("world", scenario.getTransitSchedule().getTransitLinesAttributes().getAttribute("Blue Line", "hello"));
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testLoadScenario_loadHouseholdAttributes() {
Config config = ConfigUtils.loadConfig(IOUtils.newUrl(this.util.classInputResourcePath(), "householdAttributesConfig.xml"));
config.households().addParam("inputHouseholdAttributesFile", "householdAttributes.xml");
Scenario scenario = ScenarioUtils.loadScenario(config);
Assert.assertEquals("world", scenario.getHouseholds().getHouseholdAttributes().getAttribute("1", "hello"));
}
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testLoadScenario_loadFacilitiesAttributes() {
Config config = ConfigUtils.loadConfig(IOUtils.newUrl(this.util.classInputResourcePath(), "facilityAttributesConfig.xml"));
config.facilities().addParam("inputFacilityAttributesFile", "facilityAttributes.xml");
Scenario scenario = ScenarioUtils.loadScenario(config);
Assert.assertEquals("world", scenario.getActivityFacilities().getFacilityAttributes().getAttribute("1", "hello"));
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testLoadConfig_emptyConfig() throws IOException {
Config config = new Config();
Assert.assertNull(config.network());
ConfigUtils.loadConfig(config, IOUtils.newUrl(ExamplesUtils.getTestScenarioURL("equil"), "config.xml"));
Assert.assertNotNull(config.network());
Assert.assertEquals("network.xml", config.network().getInputFile());
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testInput() {
URL transitSchedule = IOUtils.newUrl(ExamplesUtils.getTestScenarioURL("pt-tutorial"), "transitschedule.xml");
final Scenario originalScenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
new TransitScheduleReader( originalScenario ).readURL(transitSchedule );
final Scenario reprojectedScenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
new TransitScheduleReader(INITIAL_CRS, TARGET_CRS, reprojectedScenario).readURL(transitSchedule );
assertCorrectlyReprojected( originalScenario.getTransitSchedule() , reprojectedScenario.getTransitSchedule() );
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testLoadConfig_preparedConfig() throws IOException {
Config config = new Config();
config.addCoreModules();
Assert.assertNotNull(config.network());
Assert.assertNull(config.network().getInputFile());
ConfigUtils.loadConfig(config, IOUtils.newUrl(ExamplesUtils.getTestScenarioURL("equil"), "config.xml"));
Assert.assertEquals("network.xml", config.network().getInputFile());
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testReprojectionAtExport() {
final Scenario originalScenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
new MatsimFacilitiesReader( originalScenario ).parse(IOUtils.newUrl(ExamplesUtils.getTestScenarioURL("chessboard"), "facilities.xml"));
final String outFile = utils.getOutputDirectory()+"/facilities.xml.gz";
new FacilitiesWriter( transformation , originalScenario.getActivityFacilities() ).write( outFile );
final Scenario reprojectedScenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
new MatsimFacilitiesReader( reprojectedScenario ).readFile( outFile );
assertScenarioReprojectedCorrectly(originalScenario, reprojectedScenario);
}
代码示例来源:origin: matsim-org/matsim
@Test
public void testOutput() {
URL transitSchedule = IOUtils.newUrl(ExamplesUtils.getTestScenarioURL("pt-tutorial"), "transitschedule.xml");
final Scenario originalScenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
new TransitScheduleReader(originalScenario).readURL(transitSchedule );
final String file = utils.getOutputDirectory()+"/schedule.xml";
new TransitScheduleWriterV1( transformation , originalScenario.getTransitSchedule() ).write( file );
final Scenario reprojectedScenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
new TransitScheduleReader(reprojectedScenario).readFile(file);
assertCorrectlyReprojected( originalScenario.getTransitSchedule() , reprojectedScenario.getTransitSchedule() );
}
内容来源于网络,如有侵权,请联系作者删除!