org.matsim.core.network.io.MatsimNetworkReader Java Examples

The following examples show how to use org.matsim.core.network.io.MatsimNetworkReader. 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 vote down vote up
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: RunVehicleAnalysis.java    From amodeus with GNU General Public License v2.0 6 votes vote down vote up
static public void main(String[] args) throws ConfigurationException, IOException {
    CommandLine cmd = new CommandLine.Builder(args) //
            .requireOptions("events-path", "network-path", "movements-output-path", "activities-output-path") //
            .build();

    String eventsPath = cmd.getOptionStrict("events-path");
    String networkPath = cmd.getOptionStrict("network-path");
    String movementsOutputPath = cmd.getOptionStrict("movements-output-path");
    String activitiesOutputPath = cmd.getOptionStrict("activities-output-path");

    Network network = NetworkUtils.createNetwork();
    new MatsimNetworkReader(network).readFile(networkPath);

    LinkFinder linkFinder = new LinkFinder(network);
    VehicleAnalysisListener listener = new VehicleAnalysisListener(linkFinder);

    EventsManager eventsManager = EventsUtils.createEventsManager();
    eventsManager.addHandler(listener);
    new MatsimEventsReader(eventsManager).readFile(eventsPath);

    new VehicleAnalysisWriter(listener).writeMovements(new File(movementsOutputPath));
    new VehicleAnalysisWriter(listener).writeActivities(new File(activitiesOutputPath));
}
 
Example #3
Source File: RunPassengerAnalysis.java    From amodeus with GNU General Public License v2.0 6 votes vote down vote up
static public void main(String[] args) throws ConfigurationException, IOException {
    CommandLine cmd = new CommandLine.Builder(args) //
            .requireOptions("events-path", "network-path", "output-path", "modes") //
            .build();

    String eventsPath = cmd.getOptionStrict("events-path");
    String networkPath = cmd.getOptionStrict("network-path");
    String outputPath = cmd.getOptionStrict("output-path");

    String rawModes = cmd.getOptionStrict("modes");
    Set<String> modes = Arrays.asList(rawModes.split(",")).stream().map(String::trim).collect(Collectors.toSet());

    Network network = NetworkUtils.createNetwork();
    new MatsimNetworkReader(network).readFile(networkPath);

    LinkFinder linkFinder = new LinkFinder(network);
    PassengerAnalysisListener listener = new PassengerAnalysisListener(modes, linkFinder);

    EventsManager eventsManager = EventsUtils.createEventsManager();
    eventsManager.addHandler(listener);
    new MatsimEventsReader(eventsManager).readFile(eventsPath);

    new PassengerAnalysisWriter(listener).writeRides(new File(outputPath));
}
 
Example #4
Source File: NetworkTools.java    From pt2matsim with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Reads and returns a network
 */
public static Network readNetwork(String fileName) {
	Network network = NetworkUtils.createNetwork();
	new MatsimNetworkReader(network).readFile(fileName);
	return network;
}