@Override public double getWidth(final Link link) { return link.getCapacity() * this.widthCoefficient; } }
@Override public double getCapacity() { return link.getCapacity(); }
@Override public double getCapacity(double time) { return link.getCapacity(time); }
@Override public boolean judgeLink(Link l) { if (l.getCapacity() >= pConfigGroup.getMinCapacityForStops()) return true; else return false; } });
/** * @param thetas map of outgoing-link and theta of that link. must include at least one entry, otherwise it won't work! * @return the link with the smallest theta, if multiple links have the same smallest theta, the one with the biggest capacity is returned. */ private Link computeSubsequentLink(final Map<Link, Double> thetas) { List<Link> minThetaOutLinks = new ArrayList<>(); minThetaOutLinks.clear(); double absMin = Collections.min(thetas.values()); for (Map.Entry<Link, Double> entry : thetas.entrySet()) { if (absMin == entry.getValue()) { minThetaOutLinks.add(entry.getKey()); } } if (minThetaOutLinks.size() == 1) { return minThetaOutLinks.get(0); } double maxCapacity = Double.NEGATIVE_INFINITY; Link maxCapLink = null; for (Link link : minThetaOutLinks) { double cap = link.getCapacity(); if (cap > maxCapacity) { maxCapacity = cap; maxCapLink = link; } } return maxCapLink; }
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); } }
/** * 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; }
public static void overwriteLaneCapacitiesByNetworkCapacities(Network net, Lanes lanes) { for (LanesToLinkAssignment linkLanes : lanes.getLanesToLinkAssignments().values()) { double linkCap = net.getLinks().get(linkLanes.getLinkId()).getCapacity(); for (Lane lane : linkLanes.getLanes().values()) { lane.setCapacityVehiclesPerHour(linkCap); } } } }
@Override public void run(Network network) { double capDivider = network.getCapacityPeriod(); for (Link link : network.getLinks().values()) { double capacity = link.getCapacity(); double cap1h = capacity * 3600.0 / capDivider; int lanes; if (cap1h <= 1400) lanes = 1; else if (cap1h <= 3000) lanes = 2; else if (cap1h <= 6000) lanes = 3; else if (cap1h <= 8500) lanes = 4; else lanes = 5; link.setNumberOfLanes(lanes); } } }
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; }
/** * Calculate capacity by formular from Neumann2008DA: * * Flow of a Lane is given by the flow of the link divided by the number of lanes represented by the link. * * A Lane may represent one or more lanes in reality. This is given by the attribute numberOfRepresentedLanes of * the Lane definition. The flow of a lane is scaled by this number. */ public static void calculateAndSetCapacity(Lane lane, boolean isLaneAtLinkEnd, Link link, Network network){ if (isLaneAtLinkEnd){ double noLanesLink = link.getNumberOfLanes(); double linkFlowCapPerSecondPerLane = link.getCapacity() / network.getCapacityPeriod() / noLanesLink; double laneFlowCapPerHour = lane.getNumberOfRepresentedLanes() * linkFlowCapPerSecondPerLane * 3600.0; lane.setCapacityVehiclesPerHour(laneFlowCapPerHour); } else { double capacity = link.getCapacity() / network.getCapacityPeriod() * 3600.0; lane.setCapacityVehiclesPerHour(capacity); } }
LaemmerSignal(SignalGroup signalGroup) { this.group = signalGroup; // calculate outflow capacity once (in reality one also has to initialize this value and cannot update it every second) for (Signal signal : group.getSignals().values()) { if (signal.getLaneIds() != null && !signal.getLaneIds().isEmpty() && lanes.getLanesToLinkAssignments().get(signal.getLinkId()).getLanes().size() > 1) { for (Id<Lane> laneId : signal.getLaneIds()) { double laneOutflow = lanes.getLanesToLinkAssignments().get(signal.getLinkId()).getLanes() .get(laneId).getCapacityVehiclesPerHour() * config.qsim().getFlowCapFactor() / 3600; laneOutflowCapacitiesPerS.put(laneId, laneOutflow); signalOutflowCapacityPerS += laneOutflow; } } else { double linkOutflowPerS = network.getLinks().get(signal.getLinkId()).getCapacity() * config.qsim().getFlowCapFactor() / 3600; linkOutflowCapacitiesPerS.put(signal.getLinkId(), linkOutflowPerS); signalOutflowCapacityPerS += linkOutflowPerS; } } }
@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 ..." ) ; } }
@Override public SimpleFeature getFeature(final Link link) { double width = this.widthCalculator.getWidth(link); Coordinate[] coords = createPolygonCoordsForLink(link, width); Polygon p = this.geofac.createPolygon(this.geofac.createLinearRing(coords), null); Object [] attribs = new Object[9]; attribs[0] = p; attribs[1] = link.getId().toString(); attribs[2] = link.getFromNode().getId().toString(); attribs[3] = link.getToNode().getId().toString(); attribs[4] = link.getLength(); attribs[5] = link.getFreespeed(); attribs[6] = link.getCapacity(); attribs[7] = link.getNumberOfLanes(); attribs[8] = width; try { return this.builder.buildFeature(null, attribs); } catch (IllegalArgumentException e) { throw new RuntimeException(e); } }
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; }
@Override public SimpleFeature getFeature(final Link link) { double width = this.widthCalculator.getWidth(link); LineString ls = this.geofac.createLineString(new Coordinate[] {MGC.coord2Coordinate(link.getFromNode().getCoord()), MGC.coord2Coordinate(link.getToNode().getCoord())}); Object [] attribs = new Object[10]; attribs[0] = ls; attribs[1] = link.getId().toString(); attribs[2] = link.getFromNode().getId().toString(); attribs[3] = link.getToNode().getId().toString(); attribs[4] = link.getLength(); attribs[5] = link.getFreespeed(); attribs[6] = link.getCapacity(); attribs[7] = link.getNumberOfLanes(); attribs[8] = width; attribs[9] = NetworkUtils.getType(link); try { return this.builder.buildFeature(null, attribs); } catch (IllegalArgumentException e) { throw new RuntimeException(e); } }
@Test public void testRun_remove() { Fixture f = new Fixture(); NetworkMergeDoubleLinks merger = new NetworkMergeDoubleLinks(NetworkMergeDoubleLinks.MergeType.REMOVE); merger.run(f.network); Assert.assertEquals("wrong number of links.", 3, f.network.getLinks().size()); Assert.assertNotNull(f.network.getLinks().get(f.linkIds[0])); Assert.assertNull(f.network.getLinks().get(f.linkIds[10])); Assert.assertNotNull(f.network.getLinks().get(f.linkIds[1])); Assert.assertNull(f.network.getLinks().get(f.linkIds[11])); Assert.assertNotNull(f.network.getLinks().get(f.linkIds[2])); Assert.assertNull(f.network.getLinks().get(f.linkIds[12])); // attributes should be unchanged Assert.assertEquals(100.0, f.network.getLinks().get(f.linkIds[0]).getLength(), MatsimTestUtils.EPSILON); Assert.assertEquals(200.0, f.network.getLinks().get(f.linkIds[0]).getCapacity(), MatsimTestUtils.EPSILON); Assert.assertEquals(1, f.network.getLinks().get(f.linkIds[0]).getNumberOfLanes(), MatsimTestUtils.EPSILON); Assert.assertEquals(30.0/3.6, f.network.getLinks().get(f.linkIds[0]).getFreespeed(), MatsimTestUtils.EPSILON); Assert.assertEquals(500.0, f.network.getLinks().get(f.linkIds[1]).getLength(), MatsimTestUtils.EPSILON); Assert.assertEquals(2000.0, f.network.getLinks().get(f.linkIds[1]).getCapacity(), MatsimTestUtils.EPSILON); Assert.assertEquals(2, f.network.getLinks().get(f.linkIds[1]).getNumberOfLanes(), MatsimTestUtils.EPSILON); Assert.assertEquals(70.0/3.6, f.network.getLinks().get(f.linkIds[1]).getFreespeed(), MatsimTestUtils.EPSILON); Assert.assertEquals(700.0, f.network.getLinks().get(f.linkIds[2]).getLength(), MatsimTestUtils.EPSILON); Assert.assertEquals(500.0, f.network.getLinks().get(f.linkIds[2]).getCapacity(), MatsimTestUtils.EPSILON); Assert.assertEquals(2, f.network.getLinks().get(f.linkIds[2]).getNumberOfLanes(), MatsimTestUtils.EPSILON); Assert.assertEquals(50.0/3.6, f.network.getLinks().get(f.linkIds[2]).getFreespeed(), MatsimTestUtils.EPSILON); }
@Test public void testRun_additive() { Fixture f = new Fixture(); NetworkMergeDoubleLinks merger = new NetworkMergeDoubleLinks(NetworkMergeDoubleLinks.MergeType.ADDITIVE); merger.run(f.network); Assert.assertEquals("wrong number of links.", 3, f.network.getLinks().size()); Assert.assertNotNull(f.network.getLinks().get(f.linkIds[0])); Assert.assertNull(f.network.getLinks().get(f.linkIds[10])); Assert.assertNotNull(f.network.getLinks().get(f.linkIds[1])); Assert.assertNull(f.network.getLinks().get(f.linkIds[11])); Assert.assertNotNull(f.network.getLinks().get(f.linkIds[2])); Assert.assertNull(f.network.getLinks().get(f.linkIds[12])); // additive merge (sum cap, max freespeed, sum lanes, max length) Assert.assertEquals(500.0, f.network.getLinks().get(f.linkIds[0]).getLength(), MatsimTestUtils.EPSILON); Assert.assertEquals(2200.0, f.network.getLinks().get(f.linkIds[0]).getCapacity(), MatsimTestUtils.EPSILON); Assert.assertEquals(3, f.network.getLinks().get(f.linkIds[0]).getNumberOfLanes(), MatsimTestUtils.EPSILON); Assert.assertEquals(70.0/3.6, f.network.getLinks().get(f.linkIds[0]).getFreespeed(), MatsimTestUtils.EPSILON); Assert.assertEquals(500.0, f.network.getLinks().get(f.linkIds[1]).getLength(), MatsimTestUtils.EPSILON); Assert.assertEquals(2200.0, f.network.getLinks().get(f.linkIds[1]).getCapacity(), MatsimTestUtils.EPSILON); Assert.assertEquals(3, f.network.getLinks().get(f.linkIds[1]).getNumberOfLanes(), MatsimTestUtils.EPSILON); Assert.assertEquals(70.0/3.6, f.network.getLinks().get(f.linkIds[1]).getFreespeed(), MatsimTestUtils.EPSILON); Assert.assertEquals(700.0, f.network.getLinks().get(f.linkIds[2]).getLength(), MatsimTestUtils.EPSILON); Assert.assertEquals(1500.0, f.network.getLinks().get(f.linkIds[2]).getCapacity(), MatsimTestUtils.EPSILON); Assert.assertEquals(3, f.network.getLinks().get(f.linkIds[2]).getNumberOfLanes(), MatsimTestUtils.EPSILON); Assert.assertEquals(80.0/3.6, f.network.getLinks().get(f.linkIds[2]).getFreespeed(), MatsimTestUtils.EPSILON); }
@Test public void testRun_maximum() { Fixture f = new Fixture(); NetworkMergeDoubleLinks merger = new NetworkMergeDoubleLinks(NetworkMergeDoubleLinks.MergeType.MAXIMUM); merger.run(f.network); Assert.assertEquals("wrong number of links.", 3, f.network.getLinks().size()); Assert.assertNotNull(f.network.getLinks().get(f.linkIds[0])); Assert.assertNull(f.network.getLinks().get(f.linkIds[10])); Assert.assertNotNull(f.network.getLinks().get(f.linkIds[1])); Assert.assertNull(f.network.getLinks().get(f.linkIds[11])); Assert.assertNotNull(f.network.getLinks().get(f.linkIds[2])); Assert.assertNull(f.network.getLinks().get(f.linkIds[12])); // max merge (max cap, max freespeed, max langes, max length Assert.assertEquals(500.0, f.network.getLinks().get(f.linkIds[0]).getLength(), MatsimTestUtils.EPSILON); Assert.assertEquals(2000.0, f.network.getLinks().get(f.linkIds[0]).getCapacity(), MatsimTestUtils.EPSILON); Assert.assertEquals(2, f.network.getLinks().get(f.linkIds[0]).getNumberOfLanes(), MatsimTestUtils.EPSILON); Assert.assertEquals(70.0/3.6, f.network.getLinks().get(f.linkIds[0]).getFreespeed(), MatsimTestUtils.EPSILON); Assert.assertEquals(500.0, f.network.getLinks().get(f.linkIds[1]).getLength(), MatsimTestUtils.EPSILON); Assert.assertEquals(2000.0, f.network.getLinks().get(f.linkIds[1]).getCapacity(), MatsimTestUtils.EPSILON); Assert.assertEquals(2, f.network.getLinks().get(f.linkIds[1]).getNumberOfLanes(), MatsimTestUtils.EPSILON); Assert.assertEquals(70.0/3.6, f.network.getLinks().get(f.linkIds[1]).getFreespeed(), MatsimTestUtils.EPSILON); Assert.assertEquals(700.0, f.network.getLinks().get(f.linkIds[2]).getLength(), MatsimTestUtils.EPSILON); Assert.assertEquals(1000.0, f.network.getLinks().get(f.linkIds[2]).getCapacity(), MatsimTestUtils.EPSILON); Assert.assertEquals(2, f.network.getLinks().get(f.linkIds[2]).getNumberOfLanes(), MatsimTestUtils.EPSILON); Assert.assertEquals(80.0/3.6, f.network.getLinks().get(f.linkIds[2]).getFreespeed(), MatsimTestUtils.EPSILON); }
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); }