public static void readNetwork( Network network, String string ) { new MatsimNetworkReader(network).readFile(string); } public static Network readNetwork( String string ) {
public static Network readNetwork( String string ) { Network network = ScenarioUtils.createScenario(ConfigUtils.createConfig() ).getNetwork() ; new MatsimNetworkReader(network).readFile(string); return network ; } }
private void prepareScen() { sc = ScenarioUtils.createScenario(ConfigUtils.createConfig()); new MatsimNetworkReader(sc.getNetwork()).readFile(NETWORKFILE); }
private void init(final String networkPath) { this.scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); this.plans0= ScenarioUtils.createScenario(ConfigUtils.createConfig()).getPopulation(); this.plans1= ScenarioUtils.createScenario(ConfigUtils.createConfig()).getPopulation(); System.out.println(" reading the network..."); new MatsimNetworkReader(this.scenario.getNetwork()).readFile(networkPath); }
/** Runs the network cleaning algorithms over the network read in from <code>inputNetworkFile</code> * and writes the resulting ("cleaned") network to the specified file. * * @param inputNetworkFile filename of the network to be handled * @param outputNetworkFile filename where to write the cleaned network to */ public void run(final String inputNetworkFile, final String outputNetworkFile) { final Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); final Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile(inputNetworkFile); new org.matsim.core.network.algorithms.NetworkCleaner().run(network); new NetworkWriter(network).write(outputNetworkFile); }
public void testCalcLeastCostPath_SameFromTo() throws SAXException, ParserConfigurationException, IOException { Scenario scenario = ScenarioUtils.createScenario(loadConfig(null)); Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile("test/scenarios/equil/network.xml"); Node node12 = network.getNodes().get(Id.create("12", Node.class)); LeastCostPathCalculator routerAlgo = getLeastCostPathCalculator(network); Path path = routerAlgo.calcLeastCostPath(node12, node12, 8.0*3600, null, null); assertEquals("number of nodes wrong.", 1, path.nodes.size()); assertEquals("number of links wrong.", 0, path.links.size()); assertEquals(network.getNodes().get(Id.create("12", Node.class)), path.nodes.get(0)); }
public void testNodesShape() { String netFileName = "test/scenarios/equil/network.xml"; String outputFileShp = getOutputDirectory() + "./network.shp"; Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); final Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile(netFileName); new Nodes2ESRIShape(network,outputFileShp, "DHDN_GK4").write(); Collection<SimpleFeature> writtenFeatures = ShapeFileReader.getAllFeatures(outputFileShp); Assert.assertEquals(network.getNodes().size(), writtenFeatures.size()); } }
@Test public void testReadFile_v4() { Scenario s = ScenarioUtils.createScenario(ConfigUtils.createConfig()); Assert.assertEquals(0, s.getPopulation().getPersons().size()); new MatsimNetworkReader(s.getNetwork()).readFile("test/scenarios/equil/network.xml"); new PopulationReader(s).readFile("test/scenarios/equil/plans1.xml"); Assert.assertEquals(1, s.getPopulation().getPersons().size()); }
public static void main(String[] args) { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); new MatsimNetworkReader(scenario.getNetwork()).readFile("input/usecases/chessboard/network/grid9x9_cap20.xml"); Carriers carriers = new Carriers(); new CarrierPlanXmlReaderV2(carriers).readFile("input/usecases/chessboard/freight/carrierPlansWithoutRoutes_10minTW.xml"); CarrierVehicleTypes types = new CarrierVehicleTypes(); new CarrierVehicleTypeReader(types).readFile("input/usecases/chessboard/freight/vehicleTypes.xml"); new CarrierVehicleTypeLoader(carriers).loadVehicleTypes(types); for(Carrier carrier : carriers.getCarriers().values()){ CarrierPlan plan = new InitialCarrierPlanCreator(scenario.getNetwork()).createPlan(carrier); carrier.setSelectedPlan(plan); } new CarrierPlanXmlWriterV2(carriers).write("input/usecases/chessboard/freight/carrierPlans_10minTW.xml"); }
@Test public void testReadingPlansV4parallel() { Config config = ConfigUtils.createConfig(); config.plans().setNetworkRouteType("CompressedNetworkRoute"); Scenario s = ScenarioUtils.createScenario(config); new MatsimNetworkReader(s.getNetwork()).readFile("test/scenarios/equil/network.xml"); new ParallelPopulationReaderMatsimV4(s).readFile("test/scenarios/equil/plans1.xml"); Assert.assertEquals(1, s.getPopulation().getPersons().size()); Leg firstPersonsLeg = (Leg) s.getPopulation().getPersons().get(Id.create("1", Person.class)).getSelectedPlan().getPlanElements().get(1); // Assert.assertTrue(firstPersonsLeg.getRoute() instanceof CompressedNetworkRouteImpl); }
public void testReadFile() throws IOException, SAXException, ParserConfigurationException { final String inputDir = getClassInputDirectory(); MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); scenario.getConfig().transit().setUseTransit(true); new MatsimNetworkReader(scenario.getNetwork()).readFile(inputDir + INPUT_TEST_FILE_NETWORK); new TransitScheduleReader(scenario).readFile(inputDir + INPUT_TEST_FILE_TRANSITSCHEDULE); // only a minimal test, the actual reader used should be tested somewhere separately assertEquals("wrong number of transit lines.", 1, scenario.getTransitSchedule().getTransitLines().size()); // in the end, we mostly test that there is no Exception when reading the file. }
public Fixture() { this.scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); new MatsimNetworkReader(this.scenario.getNetwork()).readFile("test/scenarios/equil/network.xml"); this.person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); this.vehicle = new VehicleImpl(null, null); this.costFunction = new PersonEnforcingTravelDisutility(); this.costFunction.setExpectations(this.person, this.vehicle); this.network = this.scenario.getNetwork(); } }
@Test public void testCompareBigPopulationWithItself() { Scenario s1 = ScenarioUtils.createScenario(ConfigUtils.createConfig()); String netFileName = "test/scenarios/berlin/network.xml"; String popFileName = "test/scenarios/berlin/plans_hwh_1pct.xml.gz"; new MatsimNetworkReader(s1.getNetwork()).readFile(netFileName); new PopulationReader(s1).readFile(popFileName); Assert.assertTrue(PopulationUtils.equalPopulation(s1.getPopulation(), s1.getPopulation())); }
@Test public void testLinksAttributes() { final Scenario sc = createTestNetwork( false ); new NetworkWriter( sc.getNetwork() ).writeV2( utils.getOutputDirectory()+"network.xml" ); final Scenario read = ScenarioUtils.createScenario( ConfigUtils.createConfig() ); new MatsimNetworkReader( read.getNetwork() ).readFile( utils.getOutputDirectory()+"network.xml" ); final Id<Link> id = Id.createLinkId( "trip" ); Assert.assertEquals( "unexpected mode attribute in link metadata", 3, read.getNetwork().getLinks().get( id ).getAttributes().getAttribute( "number of modes" ) ); }
@Test public void testNo3DCoord() { // should be done through once "mixed" network as soon as possible final Scenario sc = createTestNetwork( false ); new NetworkWriter( sc.getNetwork() ).writeV2( utils.getOutputDirectory()+"network.xml" ); final Scenario read = ScenarioUtils.createScenario( ConfigUtils.createConfig() ); new MatsimNetworkReader( read.getNetwork() ).readFile( utils.getOutputDirectory()+"network.xml" ); final Id<Node> zh = Id.createNodeId( "Zurich" ); final Coord zhCoord = read.getNetwork().getNodes().get( zh ).getCoord(); Assert.assertFalse( "did not expect Z", zhCoord.hasZ() ); }
@Test public void testNodesAttributes() { final Scenario sc = createTestNetwork( false ); new NetworkWriter( sc.getNetwork() ).writeV2( utils.getOutputDirectory()+"network.xml" ); final Scenario read = ScenarioUtils.createScenario( ConfigUtils.createConfig() ); new MatsimNetworkReader( read.getNetwork() ).readFile( utils.getOutputDirectory()+"network.xml" ); final Id<Node> id = Id.createNodeId( "Zurich" ); Assert.assertEquals( "unexpected internet attribute in node metadata", "good", read.getNetwork().getNodes().get( id ).getAttributes().getAttribute( "Internet" ) ); Assert.assertEquals( "unexpected meeting attribute in node metadata", false, read.getNetwork().getNodes().get( id ).getAttributes().getAttribute( "Developper Meeting" ) ); }
public void setUp() { String configFile = "test/input/org/matsim/pt/counts/config.xml"; this.config = ConfigUtils.loadConfig(configFile); MatsimRandom.reset(config.global().getRandomSeed()); this.scenario = ScenarioUtils.createScenario(config); config = scenario.getConfig(); new MatsimCountsReader(this.counts).readFile(config.findParam(MODULE_NAME, countFileParamName)); this.network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile(config.network().getInputFile()); }
public void setUp() { String configFile = "test/input/org/matsim/counts/config.xml"; Config config = ConfigUtils.loadConfig(configFile); MatsimRandom.reset(config.global().getRandomSeed()); this.scenario = ScenarioUtils.createScenario(config); MatsimCountsReader counts_parser = new MatsimCountsReader(this.counts); counts_parser.readFile(config.counts().getCountsFileName()); this.network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile(config.network().getInputFile()); }
@Test public void test3DCoord() { // should be done through once "mixed" network as soon as possible final Scenario sc = createTestNetwork( true ); new NetworkWriter( sc.getNetwork() ).writeV2( utils.getOutputDirectory()+"network.xml" ); final Scenario read = ScenarioUtils.createScenario( ConfigUtils.createConfig() ); new MatsimNetworkReader( read.getNetwork() ).readFile( utils.getOutputDirectory()+"network.xml" ); final Id<Node> zh = Id.createNodeId( "Zurich" ); final Coord zhCoord = read.getNetwork().getNodes().get( zh ).getCoord(); Assert.assertTrue( "did expect Z", zhCoord.hasZ() ); Assert.assertEquals( "unexpected Z value", 400, zhCoord.getZ() , MatsimTestUtils.EPSILON ); }
@Test public void testNetworkAttributes() { final Scenario sc = createTestNetwork( false ); new NetworkWriter( sc.getNetwork() ).writeV2( utils.getOutputDirectory()+"network.xml" ); final Scenario read = ScenarioUtils.createScenario( ConfigUtils.createConfig() ); new MatsimNetworkReader( read.getNetwork() ).readFile( utils.getOutputDirectory()+"network.xml" ); Assert.assertEquals( "unexpected year in network metadata", sc.getNetwork().getAttributes().getAttribute( "year" ), read.getNetwork().getAttributes().getAttribute( "year" ) ); }