private boolean areLinksMergeable(Link inLink, Link outLink) { List<Node> fromNodes = this.mergedLinksToIntermediateNodes.get(inLink.getId()); if (fromNodes==null) fromNodes = new ArrayList<>(); fromNodes.add(inLink.getFromNode()); List<Node> toNodes = this.mergedLinksToIntermediateNodes.get(outLink.getId()); if(toNodes==null) toNodes = new ArrayList<>(); toNodes.add(outLink.getToNode()); for(Node n :fromNodes) { if (toNodes.contains(n)) return false; } return true; }
private EventLink(final Link link2, final double capCorrectionFactor, final double effectiveCellSize, final double storageCapFactor) { this.link = link2; this.drivingQueue = new ArrayList<>(); this.parkingQueue = new ArrayList<>(); this.waitingQueue = new ArrayList<>(); this.buffer = new ArrayList<>(); this.euklideanDist = CoordUtils.calcEuclideanDistance(link2.getFromNode().getCoord(), link2.getToNode().getCoord()); this.freespeedTravelTime = Math.ceil( this.link.getLength() / this.link.getFreespeed() ) + 1; this.timeCap = this.link.getCapacity() * capCorrectionFactor; this.storageCapFactor = storageCapFactor; this.inverseTimeCap = 1.0 / this.timeCap; this.effectiveCellSize = effectiveCellSize; this.spaceCap = (this.link.getLength() * this.link.getNumberOfLanes()) / this.effectiveCellSize * storageCapFactor; }
@Override public Coord getCoord() { return this.link.getCoord(); }
@Override public double getLinkTravelDisutility(final Link link, final double time, final Person person, final Vehicle vehicle) { if (this.marginalUtlOfDistance == 0.0) { return (link.getLength() / link.getFreespeed(time)) * this.travelCostFactor; } return (link.getLength() / link.getFreespeed(time)) * this.travelCostFactor - this.marginalUtlOfDistance * link.getLength(); }
public void initForLink(final Link link) { this.fromNode = link.getFromNode(); this.toNode = link.getToNode(); this.tmpToNodeData = null; }
/** * Compare link attributes. Return whether they are the same or not. */ private boolean bothLinksHaveSameLinkStats(Link linkA, Link linkB){ boolean bothLinksHaveSameLinkStats = true; if(!linkA.getAllowedModes().equals(linkB.getAllowedModes())){ bothLinksHaveSameLinkStats = false; } if(linkA.getFreespeed() != linkB.getFreespeed()){ bothLinksHaveSameLinkStats = false; } if(linkA.getCapacity() != linkB.getCapacity()){ bothLinksHaveSameLinkStats = false; } if(linkA.getNumberOfLanes() != linkB.getNumberOfLanes()){ bothLinksHaveSameLinkStats = false; } return bothLinksHaveSameLinkStats; }
private void splitLink(Link link) { this.network.removeLink(link.getId()); double length = link.getLength()/2.0; double freespeed = link.getFreespeed(); double capacity = link.getCapacity(); double permlanes = link.getNumberOfLanes(); Node medianNode = this.network.getFactory().createNode(getNewNodeId(), link.getCoord()); this.network.addNode(medianNode); Link tmpLink = this.network.getFactory().createLink(link.getId(), link.getFromNode(), medianNode); tmpLink.setLength(length); tmpLink.setFreespeed(freespeed); tmpLink.setCapacity(capacity); tmpLink.setNumberOfLanes(permlanes); this.network.addLink(tmpLink); tmpLink = this.network.getFactory().createLink(getNewLinkId(), medianNode, link.getToNode()); tmpLink.setLength(length); tmpLink.setFreespeed(freespeed); tmpLink.setCapacity(capacity); tmpLink.setNumberOfLanes(permlanes); this.network.addLink(tmpLink); }
private boolean checkLinkLengths(final Network network) { for (Link link : network.getLinks().values()) { double linkLength = link.getLength(); double eucDist = CoordUtils.calcEuclideanDistance(link.getFromNode().getCoord(), link.getToNode().getCoord()); if (linkLength < eucDist) { if (log.isDebugEnabled()) { log.debug("link " + link.getId() + " has length " + linkLength + " which is smaller than the euclidean distance " + eucDist); } return false; } } return true; }
private int createInvertedLink(Link inLink, Link outLink, int numberOfLinksGenerated, Set<String> modes){ Link link = NetworkUtils.createAndAddLink(this.invertedNetwork,Id.create(numberOfLinksGenerated + 1, Link.class), this.invertedNetwork.getNodes().get(Id.create(inLink.getId(), Node.class)), this.invertedNetwork.getNodes().get(Id.create(outLink.getId(), Node.class)), outLink.getLength(), outLink.getFreespeed(), outLink.getCapacity(), outLink.getNumberOfLanes() ); link.setAllowedModes(modes); // log.error("created inverted link " + link.getId() + " from " + inLink.getId() + " to " + outLink.getId() + " with modes " + modes); NetworkUtils.setType( ((Link) link), NetworkUtils.getType(((Link) outLink))); return numberOfLinksGenerated + 1; }
private void init() { // determine different occupancy criterion for links, i.e. maximum number of vehicles linkMaxNoCarsForStorage = new HashMap<>(); linkMaxNoCarsForFreeSpeed = new HashMap<>(); for (Link link : network.getLinks().values()) { // maximum number = storage capacity * factor linkMaxNoCarsForStorage.put(link.getId(), (int) ((link.getLength() / carSize) * maxStorageFactor * storageCapacityFactor)); // maximum number such that (free speed travel time * factor) can be reached (when vehicles are distributed uniformly over time) int maxNoCarsForFreeSpeedTT = (int) Math.ceil((link.getLength() / link.getFreespeed()) * maxDelayFactor * (link.getCapacity() / 3600)); linkMaxNoCarsForFreeSpeed.put(link.getId(), maxNoCarsForFreeSpeedTT); // log.info("setting max number of cars for free speed travel time to " + maxNoCarsForFreeSpeedTT); } }
@Override public void writeConstData(ByteBuffer out) throws IOException { String id = this.src.getLink().getId().toString(); ByteBufferUtils.putString(out, id); //subtract minEasting/Northing somehow! Point2D.Double.Double linkStart = OTFServerQuadTree.transform(this.src.getLink().getFromNode().getCoord()); Point2D.Double.Double linkEnd = OTFServerQuadTree.transform(this.src.getLink().getToNode().getCoord()); out.putFloat((float) linkStart.x); out.putFloat((float) linkStart.y); out.putFloat((float) linkEnd.x); out.putFloat((float) linkEnd.y); if ( OTFVisConfigGroup.NUMBER_OF_LANES.equals(OTFClientControl.getInstance().getOTFVisConfig().getLinkWidthIsProportionalTo()) ) { out.putInt(NetworkUtils.getNumberOfLanesAsInt(0, this.src.getLink())); } else if ( OTFVisConfigGroup.CAPACITY.equals(OTFClientControl.getInstance().getOTFVisConfig().getLinkWidthIsProportionalTo()) ) { out.putInt( 1 + (int)(2.*this.src.getLink().getCapacity()/3600.) ) ; // yyyyyy 3600. is a magic number (the default of the capacity period attribute in Network) but I cannot get to the network (where "capacityPeriod" resides). // Please do better if you know better. kai, jun'11 } else { throw new RuntimeException("I do not understand. Aborting ..." ) ; } }
public static double getGradientFactor(Link link) { double gradient = 0.; Double fromNodeZ = link.getFromNode().getCoord().getZ(); Double toNodeZ = link.getToNode().getCoord().getZ(); if ((fromNodeZ != null) && (toNodeZ != null)) { if (toNodeZ > fromNodeZ) { // No positive utility for downhill, only negative for uphill gradient = (toNodeZ - fromNodeZ) / link.getLength(); } } return gradient; }
private void processLink(Link link, EmissionsByPollutant emissions, Grid<Map<Pollutant, Double>> grid) { // create a clipping area to speed up calculation time // use 5*smoothing radius as longer distances result in a weighting of effectively 0 Geometry clip = factory.createPoint(new Coordinate(link.getCoord().getX(), link.getCoord().getY())).buffer(smoothingRadius * 5); grid.getCells(clip).forEach(cell -> { double normalizationFactor = grid.getCellArea() / (Math.PI * smoothingRadius * smoothingRadius); double weight = SpatialInterpolation.calculateWeightFromLine( transformToCoordinate(link.getFromNode()), transformToCoordinate(link.getToNode()), cell.getCoordinate(), smoothingRadius); processCell(cell, emissions, weight * normalizationFactor); }); }
private void collectMergedLinkNodeInfo(Link inLink, Link outLink, Id<Link> mergedLinkId) { List<Node> nodes = new ArrayList<>(); if (this.mergedLinksToIntermediateNodes.containsKey(inLink.getId())) nodes.addAll(this.mergedLinksToIntermediateNodes .remove(inLink.getId())); if (this.mergedLinksToIntermediateNodes.containsKey(outLink.getId())) nodes.addAll(this.mergedLinksToIntermediateNodes .remove(outLink.getId())); nodes.add(inLink.getToNode()); this.mergedLinksToIntermediateNodes.put(mergedLinkId, nodes); }
@Override public QueueWithBuffer createLane( AbstractQLink qLink ) { // a number of things I cannot configure before I have the qlink: if ( id==null ) { id = Id.create( qLink.getLink().getId() , Lane.class ) ; } if ( length==null ) { length = qLink.getLink().getLength() ; } if ( effectiveNumberOfLanes==null ) { effectiveNumberOfLanes = qLink.getLink().getNumberOfLanes() ; } if ( flowCapacity_s==null ) { flowCapacity_s = ((Link)qLink.getLink()).getFlowCapacityPerSec() ; } return new QueueWithBuffer( qLink.getInternalInterface(), vehicleQueue, id, length, effectiveNumberOfLanes, flowCapacity_s, context ) ; } }
@Override public double getLinkMinimumTravelDisutility(Link link) { return link.getLength(); } }
public static final ActivityFacilities createFacilityForEachLink(String facilityContainerName, Network network) { ActivityFacilities facilities = FacilitiesUtils.createActivityFacilities(facilityContainerName); ActivityFacilitiesFactory aff = facilities.getFactory(); for (Link link : network.getLinks().values()) { ActivityFacility facility = aff.createActivityFacility(Id.create(link.getId(),ActivityFacility.class), link.getCoord(), link.getId()); facilities.addActivityFacility(facility); } return facilities ; }
@Override public Set<String> getAllowedModes() { return link.getAllowedModes(); }