Java Code Examples for org.matsim.api.core.v01.network.Link#setCapacity()

The following examples show how to use org.matsim.api.core.v01.network.Link#setCapacity() . 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: BasicScheduleEditor.java    From pt2matsim with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds a link to the network. Uses the attributes (freespeed, nr of lanes, transportModes)
 * of the attributeLink.
 */
@Override
public void addLink(Id<Link> newLinkId, Id<Node> fromNodeId, Id<Node> toNodeId, Id<Link> attributeLinkId) {
	Node fromNode = network.getNodes().get(fromNodeId);
	Node toNode = network.getNodes().get(toNodeId);

	Link newLink = networkFactory.createLink(newLinkId, fromNode, toNode);

	if(attributeLinkId != null) {
		Link attributeLink = network.getLinks().get(attributeLinkId);

		newLink.setAllowedModes(attributeLink.getAllowedModes());
		newLink.setCapacity(attributeLink.getCapacity());
		newLink.setFreespeed(attributeLink.getFreespeed());
		newLink.setNumberOfLanes(attributeLink.getNumberOfLanes());
	}

	network.addLink(newLink);
}
 
Example 2
Source File: NetworkTools.java    From pt2matsim with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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");
			}
		}
	}
}