org.matsim.api.core.v01.TransportMode Java Examples
The following examples show how to use
org.matsim.api.core.v01.TransportMode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateFleetVehicles.java From matsim-maas with GNU General Public License v2.0 | 6 votes |
private void run() { Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); new MatsimNetworkReader(scenario.getNetwork()).readFile(networkFile.toString()); final int[] i = {0}; Stream<DvrpVehicleSpecification> vehicleSpecificationStream = scenario.getNetwork().getLinks().entrySet().stream() .filter(entry -> entry.getValue().getAllowedModes().contains(TransportMode.car)) // drt can only start on links with Transport mode 'car' .sorted((e1, e2) -> (random.nextInt(2) - 1)) // shuffle links .limit(numberOfVehicles) // select the first *numberOfVehicles* links .map(entry -> ImmutableDvrpVehicleSpecification.newBuilder() .id(Id.create("drt_" + i[0]++, DvrpVehicle.class)) .startLinkId(entry.getKey()) .capacity(seatsPerVehicle) .serviceBeginTime(operationStartTime) .serviceEndTime(operationEndTime) .build()); new FleetWriter(vehicleSpecificationStream).write(outputFile.toString()); }
Example #2
Source File: ScheduleTools.java From pt2matsim with GNU General Public License v2.0 | 6 votes |
/** * Add mode "pt" to any link of the network that is * passed by any transitRoute of the schedule. */ public static void addPTModeToNetwork(TransitSchedule schedule, Network network) { log.info("... Adding mode \"pt\" to all links with public transit"); Map<Id<Link>, ? extends Link> networkLinks = network.getLinks(); Set<Id<Link>> transitLinkIds = new HashSet<>(); for(TransitLine line : schedule.getTransitLines().values()) { for(TransitRoute transitRoute : line.getRoutes().values()) { if(transitRoute.getRoute() != null) { transitLinkIds.addAll(getTransitRouteLinkIds(transitRoute)); } } } for(Id<Link> transitLinkId : transitLinkIds) { Link transitLink = networkLinks.get(transitLinkId); if(!transitLink.getAllowedModes().contains(TransportMode.pt)) { Set<String> modes = new HashSet<>(transitLink.getAllowedModes()); modes.add(TransportMode.pt); transitLink.setAllowedModes(modes); } } }
Example #3
Source File: NetworkTools.java From pt2matsim with GNU General Public License v2.0 | 6 votes |
/** * Replaces all non-car link modes with "pt" */ public static void replaceNonCarModesWithPT(Network network) { log.info("... Replacing all non-car link modes with \"pt\""); Set<String> modesCar = Collections.singleton(TransportMode.car); Set<String> modesCarPt = new HashSet<>(); modesCarPt.add(TransportMode.car); modesCarPt.add(TransportMode.pt); Set<String> modesPt = new HashSet<>(); modesPt.add(TransportMode.pt); for(Link link : network.getLinks().values()) { if(link.getAllowedModes().size() == 0 && link.getAllowedModes().contains(TransportMode.car)) { link.setAllowedModes(modesCar); } if(link.getAllowedModes().size() > 0 && link.getAllowedModes().contains(TransportMode.car)) { link.setAllowedModes(modesCarPt); } else if(!link.getAllowedModes().contains(TransportMode.car)) { link.setAllowedModes(modesPt); } } }
Example #4
Source File: OsmMultimodalNetworkConverter.java From pt2matsim with GNU General Public License v2.0 | 6 votes |
private void initPT() { ptFilter = new AllowedTagsFilter(); ptFilter.add(Osm.ElementType.RELATION, Osm.Key.ROUTE_MASTER, Osm.Value.BUS); ptFilter.add(Osm.ElementType.RELATION, Osm.Key.ROUTE_MASTER, Osm.Value.TROLLEYBUS); ptFilter.add(Osm.ElementType.RELATION, Osm.Key.ROUTE_MASTER, Osm.Value.TRAM); ptFilter.add(Osm.ElementType.RELATION, Osm.Key.ROUTE_MASTER, Osm.Value.MONORAIL); ptFilter.add(Osm.ElementType.RELATION, Osm.Key.ROUTE_MASTER, Osm.Value.SUBWAY); ptFilter.add(Osm.ElementType.RELATION, Osm.Key.ROUTE_MASTER, Osm.Value.FERRY); ptFilter.add(Osm.ElementType.RELATION, Osm.Key.ROUTE, Osm.Value.BUS); ptFilter.add(Osm.ElementType.RELATION, Osm.Key.ROUTE, Osm.Value.TROLLEYBUS); ptFilter.add(Osm.ElementType.RELATION, Osm.Key.ROUTE, Osm.Value.RAIL); ptFilter.add(Osm.ElementType.RELATION, Osm.Key.ROUTE, Osm.Value.TRAIN); ptFilter.add(Osm.ElementType.RELATION, Osm.Key.ROUTE, Osm.Value.TRAM); ptFilter.add(Osm.ElementType.RELATION, Osm.Key.ROUTE, Osm.Value.LIGHT_RAIL); ptFilter.add(Osm.ElementType.RELATION, Osm.Key.ROUTE, Osm.Value.FUNICULAR); ptFilter.add(Osm.ElementType.RELATION, Osm.Key.ROUTE, Osm.Value.MONORAIL); ptFilter.add(Osm.ElementType.RELATION, Osm.Key.ROUTE, Osm.Value.SUBWAY); ptFilter.add(Osm.ElementType.WAY, Osm.Key.PSV, Osm.Value.YES); ptFilter.add(Osm.ElementType.WAY, Osm.Key.PSV, Osm.Value.DESIGNATED); ptFilter.add(Osm.ElementType.WAY, Osm.Key.BUS, Osm.Value.DESIGNATED); ptFilter.add(Osm.ElementType.WAY, Osm.Key.BUS, Osm.Value.DESIGNATED); ptDefaultParams = new OsmConverterConfigGroup.OsmWayParams("NULL", "NULL", 1, 50 / 3.6, 1.0, 9999, false, Collections.singleton(TransportMode.pt)); }
Example #5
Source File: PublicTransitMapper.java From pt2matsim with GNU General Public License v2.0 | 5 votes |
/** * Routes the unmapped MATSim Transit Schedule to the network using the file * paths specified in the config. Writes the resulting schedule and network to xml files.<p/> * * @see CreateDefaultPTMapperConfig * * @param configFile the PublicTransitMapping config file */ public static void run(String configFile) { // Load config, input schedule and input network Config configAll = ConfigUtils.loadConfig(configFile, new PublicTransitMappingConfigGroup()); PublicTransitMappingConfigGroup config = ConfigUtils.addOrGetModule(configAll, PublicTransitMappingConfigGroup.class); TransitSchedule schedule = config.getInputScheduleFile() == null ? null : ScheduleTools.readTransitSchedule(config.getInputScheduleFile()); Network network = config.getInputNetworkFile() == null ? null : NetworkTools.readNetwork(config.getInputNetworkFile()); // Run PTMapper PTMapper.mapScheduleToNetwork(schedule, network, config); // or: new PTMapper(schedule, network).run(config); // Write the schedule and network to output files (if defined in config) if(config.getOutputNetworkFile() != null && config.getOutputScheduleFile() != null) { log.info("Writing schedule and network to file..."); try { ScheduleTools.writeTransitSchedule(schedule, config.getOutputScheduleFile()); NetworkTools.writeNetwork(network, config.getOutputNetworkFile()); } catch (Exception e) { log.error("Cannot write to output directory!"); } if(config.getOutputStreetNetworkFile() != null) { NetworkTools.writeNetwork(NetworkTools.createFilteredNetworkByLinkMode(network, Collections.singleton(TransportMode.car)), config.getOutputStreetNetworkFile()); } } else { log.info("No output paths defined, schedule and network are not written to files."); } }
Example #6
Source File: TestPreparer.java From amodeus with GNU General Public License v2.0 | 4 votes |
private TestPreparer(File workingDirectory) throws Exception { System.out.println("working directory: " + workingDirectory); // run preparer in simulation working directory ScenarioOptions scenarioOptions = new ScenarioOptions(workingDirectory, ScenarioOptionsBase.getDefault()); // load Settings from IDSC Options File configFile = new File(scenarioOptions.getPreparerConfigName()); AmodeusConfigGroup avConfigGroup = new AmodeusConfigGroup(); Config config = ConfigUtils.loadConfig(configFile.getAbsolutePath(), avConfigGroup); Scenario scenario = ScenarioUtils.loadScenario(config); GeneratorConfig avGeneratorConfig = // avConfigGroup.getModes().values().iterator().next().getGeneratorConfig(); int numRt = avGeneratorConfig.getNumberOfVehicles(); int endTime = (int) config.qsim().getEndTime().seconds(); // 1) cut network (and reduce population to new network) networkPrepared = scenario.getNetwork(); NetworkPreparer.run(networkPrepared, scenarioOptions); // 2) adapt the population to new network populationPrepared = scenario.getPopulation(); // To make Test input data consistent (e.g. avoid people departing fom "tram" links) SnapToClosestNetworkLink.run(populationPrepared, networkPrepared, TransportMode.car); PopulationPreparer.run(networkPrepared, populationPrepared, scenarioOptions, config, 10); // 3) create virtual Network // Amodeus uses internally a mode-filtered network (default is the car network). The provided // VirtualNetwork needs to be consistent with this node-filtered network. Network roadNetwork = NetworkUtils.createNetwork(); new TransportModeNetworkFilter(networkPrepared).filter(roadNetwork, Collections.singleton("car")); new NetworkCleaner().run(roadNetwork); VirtualNetworkPreparer virtualNetworkPreparer = VirtualNetworkPreparer.INSTANCE; VirtualNetwork<Link> virtualNetwork = // virtualNetworkPreparer.create(roadNetwork, populationPrepared, scenarioOptions, numRt, endTime); // 4) create TravelData /** reading the customer requests */ StaticTravelData travelData = StaticTravelDataCreator.create( // scenarioOptions.getWorkingDirectory(), // virtualNetwork, roadNetwork, populationPrepared, // scenarioOptions.getdtTravelData(), numRt, endTime); File travelDataFile = new File(scenarioOptions.getVirtualNetworkDirectoryName(), scenarioOptions.getTravelDataName()); TravelDataIO.writeStatic(travelDataFile, travelData); // 5) save a simulation config file // IncludeActTypeOf.BaselineCH(config); // Only needed in Some Scenarios ConfigCreator.createSimulationConfigFile(config, scenarioOptions); }