Java Code Examples for org.matsim.core.network.NetworkUtils#createNetwork()

The following examples show how to use org.matsim.core.network.NetworkUtils#createNetwork() . 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: 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 2
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 3
Source File: StandardMATSimScenarioTest.java    From amodeus with GNU General Public License v2.0 6 votes vote down vote up
private static void fixInvalidActivityLocations(Network network, Population population) {
    // In the test fixture there are agents who start and end activities on non-car links. This should not be happen and is fixed here.

    Network roadNetwork = NetworkUtils.createNetwork();
    new TransportModeNetworkFilter(network).filter(roadNetwork, Collections.singleton("car"));

    for (Person person : population.getPersons().values())
        for (Plan plan : person.getPlans())
            for (PlanElement element : plan.getPlanElements())
                if (element instanceof Activity) {
                    Activity activity = (Activity) element;

                    Link link = network.getLinks().get(activity.getLinkId());

                    if (!link.getAllowedModes().contains("car")) {
                        link = NetworkUtils.getNearestLink(roadNetwork, link.getCoord());
                        activity.setLinkId(link.getId());
                    }
                }
}
 
Example 4
Source File: ArtificialScenarioCreator.java    From amodeus with GNU General Public License v2.0 4 votes vote down vote up
public ArtificialScenarioCreator(Config config) {
    network = (config == null) ? NetworkUtils.createNetwork() : NetworkUtils.createNetwork(config);

    Id<Node> nodeid1 = Id.createNodeId("node1");
    Coord coord1 = new Coord(100, 100);
    node1 = NetworkUtils.createNode(nodeid1, coord1);
    network.addNode(node1);

    Id<Node> nodeid2 = Id.createNodeId("node2");
    Coord coord2 = new Coord(100, 200);
    node2 = NetworkUtils.createNode(nodeid2, coord2);
    network.addNode(node2);

    Id<Node> nodeid3 = Id.createNodeId("node3");
    Coord coord3 = new Coord(200, 200);
    node3 = NetworkUtils.createNode(nodeid3, coord3);
    network.addNode(node3);

    Id<Node> nodeid4 = Id.createNodeId("node4");
    Coord coord4 = new Coord(200, 100);
    node4 = NetworkUtils.createNode(nodeid4, coord4);
    network.addNode(node4);

    Id<Node> depotId = Id.createNodeId("depot");
    Coord depotCoord = new Coord(100, 0);
    depot = NetworkUtils.createNode(depotId, depotCoord);
    network.addNode(depot);

    Id<Link> idUp = Id.createLinkId("linkUp");
    linkUp = NetworkUtils.createLink(idUp, node1, node2, network, length, freespeed, capacity, lanes);
    Id<Link> idRight = Id.createLinkId("linkRight");
    linkRight = NetworkUtils.createLink(idRight, node2, node3, network, length, freespeed, capacity, lanes);
    Id<Link> idDown = Id.createLinkId("linkDown");
    linkDown = NetworkUtils.createLink(idDown, node3, node4, network, length, freespeed, capacity, lanes);
    Id<Link> idLeft = Id.createLinkId("linkLeft");
    linkLeft = NetworkUtils.createLink(idLeft, node4, node1, network, length, freespeed, capacity, lanes);

    Id<Link> iddepotIn = Id.createLinkId("linkDepotIn");
    linkDepotIn = NetworkUtils.createLink(iddepotIn, node1, depot, network, length, freespeed, capacity, lanes);
    Id<Link> iddepotOut = Id.createLinkId("linkDepotOut");
    linkDepotOut = NetworkUtils.createLink(iddepotOut, depot, node1, network, length, freespeed, capacity, lanes);

    network.addLink(linkUp);
    network.addLink(linkRight);
    network.addLink(linkDown);
    network.addLink(linkLeft);
    network.addLink(linkDepotIn);
    network.addLink(linkDepotOut);

    avRequest1 = new AmodeusRequest(Id.create("p1", Request.class), null, linkUp, linkDown, 0.0, AmodeusModeConfig.DEFAULT_MODE, null);
    avRequest2 = new AmodeusRequest(Id.create("p2", Request.class), null, linkRight, linkLeft, 0.0, AmodeusModeConfig.DEFAULT_MODE, null);
    avRequest3 = new AmodeusRequest(Id.create("p3", Request.class), null, linkRight, linkUp, 0.0, AmodeusModeConfig.DEFAULT_MODE, null);
    avRequest4 = new AmodeusRequest(Id.create("p4", Request.class), null, linkRight, linkDown, 0.0, AmodeusModeConfig.DEFAULT_MODE, null);
    avRequest5 = new AmodeusRequest(Id.create("p5", Request.class), null, linkUp, linkRight, 0.0, AmodeusModeConfig.DEFAULT_MODE, null);
    avRequest6 = new AmodeusRequest(Id.create("p6", Request.class), null, linkUp, linkLeft, 0.0, AmodeusModeConfig.DEFAULT_MODE, null);
    avRequest7 = new AmodeusRequest(Id.create("p7", Request.class), null, linkRight, linkLeft, 0.0, AmodeusModeConfig.DEFAULT_MODE, null);
    avRequestDepotOut = new AmodeusRequest(Id.create("depotRequestOut", Request.class), null, linkDepotOut, linkDepotOut, 0.0, AmodeusModeConfig.DEFAULT_MODE, null);
    avRequestDepotIn = new AmodeusRequest(Id.create("depotRequestIn", Request.class), null, linkDepotIn, linkDepotIn, 0.0, AmodeusModeConfig.DEFAULT_MODE, null);

}
 
Example 5
Source File: TestPreparer.java    From amodeus with GNU General Public License v2.0 4 votes vote down vote up
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);
}
 
Example 6
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;
}
 
Example 7
Source File: NetworkTools.java    From pt2matsim with GNU General Public License v2.0 4 votes vote down vote up
public static Network createNetwork() {
	return NetworkUtils.createNetwork();
}