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

The following examples show how to use org.matsim.api.core.v01.network.Link#getLength() . 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: NetworkTools.java    From pt2matsim with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Calculates the length of a link sequence
 * @param euclidian uses the sum of all link lengths if <tt>false</tt>
 */
public static double calcRouteLength(List<Link> links, boolean euclidian) {
	double length = 0;
	Link debugPrev = null;
	for(Link link : links) {
		if(debugPrev != null && !debugPrev.getToNode().getOutLinks().values().contains(link)) {
			throw new NoSuchElementException("Links not connected!");
		}
		if(euclidian) {
			length += CoordUtils.calcEuclideanDistance(link.getFromNode().getCoord(), link.getToNode().getCoord());
		} else {
			length += link.getLength();
		}

		debugPrev = link;
	}
	return length;
}
 
Example 2
Source File: LSDataTravelTime.java    From amodeus with GNU General Public License v2.0 5 votes vote down vote up
@Override
public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) {
    double speed = link.getFreespeed();
    LinkSpeedTimeSeries timeSeries = lsData.get(link);
    if (Objects.nonNull(timeSeries))
        speed = timeSeries.getSpeedsFloor((int) time);
    return link.getLength() / speed;
}
 
Example 3
Source File: Schedule2Geojson.java    From pt2matsim with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return the sum of all link lenghts of a transit route
 */
private double getRouteLength(TransitRoute transitRoute) {
	double length = 0;
	for(Link l : NetworkTools.getLinksFromIds(network, ScheduleTools.getTransitRouteLinkIds(transitRoute))) {
		length += l.getLength();
	}
	return length;
}
 
Example 4
Source File: Schedule2ShapeFile.java    From pt2matsim with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return the sum of all link lenghts of a transit route
 */
private double getRouteLength(TransitRoute transitRoute) {
	double length = 0;
	for(Link l : NetworkTools.getLinksFromIds(network, ScheduleTools.getTransitRouteLinkIds(transitRoute))) {
		length += l.getLength();
	}
	return length;
}
 
Example 5
Source File: ScheduleRoutersGtfsShapes.java    From pt2matsim with GNU General Public License v2.0 4 votes vote down vote up
@Override
public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) {
	return link.getLength() / link.getFreespeed();
}
 
Example 6
Source File: ScheduleRoutersStandard.java    From pt2matsim with GNU General Public License v2.0 4 votes vote down vote up
@Override
public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) {
	return link.getLength() / link.getFreespeed();
}
 
Example 7
Source File: ScheduleRoutersOsmAttributes.java    From pt2matsim with GNU General Public License v2.0 4 votes vote down vote up
@Override
public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) {
    return link.getLength() / link.getFreespeed();
}
 
Example 8
Source File: PTMapperTools.java    From pt2matsim with GNU General Public License v2.0 4 votes vote down vote up
public static double calcTravelCost(Link link, PublicTransitMappingConfigGroup.TravelCostType travelCostType) {
	return (travelCostType.equals(PublicTransitMappingConfigGroup.TravelCostType.travelTime) ? link.getLength() / link.getFreespeed() : link.getLength());
}
 
Example 9
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");
			}
		}
	}
}