Java Code Examples for org.matsim.api.core.v01.network.Network#addNode()
The following examples show how to use
org.matsim.api.core.v01.network.Network#addNode() .
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: PTMapperTools.java From pt2matsim with GNU General Public License v2.0 | 6 votes |
/** * Creates a node and dummy/loop link on the coordinate of the stop facility and * adds both to the network. The stop facility is NOT referenced. * * @return the new link or the existing link if it's already present in the network */ public static Link createArtificialStopFacilityLink(TransitStopFacility stopFacility, Network network, String prefix, double freespeed, Set<String> transportModes) { Id<Link> dummyLinkId = createArtificialLinkId(stopFacility); Link dummyLink = network.getLinks().get(dummyLinkId); if(dummyLink != null) { return dummyLink; } else { Node dummyNode = NetworkUtils.createNode(Id.createNodeId(prefix + stopFacility.getId()), stopFacility.getCoord()); network.addNode(dummyNode); dummyLink = NetworkUtils.createLink(dummyLinkId, dummyNode, dummyNode, network, 10, freespeed, 9999, 1); dummyLink.setAllowedModes(transportModes); network.addLink(dummyLink); return dummyLink; } }
Example 2
Source File: TestScenarioGenerator.java From amodeus with GNU General Public License v2.0 | 4 votes |
static private void generateNetwork(Network network) { NetworkFactory networkFactory = network.getFactory(); for (int i = 0; i < networkSize; i++) { for (int j = 0; j < networkSize; j++) { network.addNode(networkFactory.createNode(Id.createNodeId(String.format("%d:%d", i, j)), new Coord(i * networkScale, j * networkScale))); } } Node fromNode; Node toNode; for (int i = 0; i < networkSize; i++) { for (int j = 1; j < networkSize; j++) { fromNode = network.getNodes().get(Id.createNodeId(String.format("%d:%d", i, j - 1))); toNode = network.getNodes().get(Id.createNodeId(String.format("%d:%d", i, j))); network.addLink(networkFactory.createLink(Id.createLinkId(String.format("%s_%s", fromNode.getId(), toNode.getId())), fromNode, toNode)); fromNode = network.getNodes().get(Id.createNodeId(String.format("%d:%d", i, j))); toNode = network.getNodes().get(Id.createNodeId(String.format("%d:%d", i, j - 1))); network.addLink(networkFactory.createLink(Id.createLinkId(String.format("%s_%s", fromNode.getId(), toNode.getId())), fromNode, toNode)); } } for (int j = 0; j < networkSize; j++) { for (int i = 1; i < networkSize; i++) { fromNode = network.getNodes().get(Id.createNodeId(String.format("%d:%d", i - 1, j))); toNode = network.getNodes().get(Id.createNodeId(String.format("%d:%d", i, j))); network.addLink(networkFactory.createLink(Id.createLinkId(String.format("%s_%s", fromNode.getId(), toNode.getId())), fromNode, toNode)); fromNode = network.getNodes().get(Id.createNodeId(String.format("%d:%d", i, j))); toNode = network.getNodes().get(Id.createNodeId(String.format("%d:%d", i - 1, j))); network.addLink(networkFactory.createLink(Id.createLinkId(String.format("%s_%s", fromNode.getId(), toNode.getId())), fromNode, toNode)); } } for (Link link : network.getLinks().values()) { link.setFreespeed(freespeed); link.setLength(networkScale); } }
Example 3
Source File: NetworkTools.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
/** * Integrates <tt>network B</tt> into <tt>network A</tt>. Network * A contains all links and nodes of both networks * after integration. */ public static void integrateNetwork(final Network networkA, final Network networkB, boolean mergeModes) { final NetworkFactory factory = networkA.getFactory(); // Nodes for(Node node : networkB.getNodes().values()) { Id<Node> nodeId = Id.create(node.getId().toString(), Node.class); if(!networkA.getNodes().containsKey(nodeId)) { Node newNode = factory.createNode(nodeId, node.getCoord()); networkA.addNode(newNode); } } // Links double capacityFactor = networkA.getCapacityPeriod() / networkB.getCapacityPeriod(); for(Link link : networkB.getLinks().values()) { Id<Link> linkId = Id.create(link.getId().toString(), Link.class); if(!networkA.getLinks().containsKey(linkId)) { Id<Node> fromNodeId = Id.create(link.getFromNode().getId().toString(), Node.class); Id<Node> toNodeId = Id.create(link.getToNode().getId().toString(), Node.class); Link newLink = factory.createLink(linkId, networkA.getNodes().get(fromNodeId), networkA.getNodes().get(toNodeId)); newLink.setAllowedModes(link.getAllowedModes()); newLink.setCapacity(link.getCapacity() * capacityFactor); newLink.setFreespeed(link.getFreespeed()); newLink.setLength(link.getLength()); newLink.setNumberOfLanes(link.getNumberOfLanes()); networkA.addLink(newLink); } else if (mergeModes) { Link existingLink = networkA.getLinks().get(linkId); Set<String> allowedModes = new HashSet<>(); allowedModes.addAll(existingLink.getAllowedModes()); allowedModes.addAll(link.getAllowedModes()); existingLink.setAllowedModes(allowedModes); if (link.getCapacity() * capacityFactor != existingLink.getCapacity()) { throw new IllegalStateException("Capacity must be equal for integration"); } if (link.getFreespeed() != existingLink.getFreespeed()) { throw new IllegalStateException("Freespeed must be equal for integration"); } if (link.getLength() != existingLink.getLength()) { throw new IllegalStateException("Length must be equal for integration"); } if (link.getNumberOfLanes() != existingLink.getNumberOfLanes()) { throw new IllegalStateException("Number of lanes must be equal for integration"); } } } }