@Override public void run(Network network) { log.info("running " + this.getClass().getName() + " module..."); log.info(" adapting link length to at least 'overLengthFactor * euclidean distance' (works properly only for eucledian coord systems)"); log.info(" also ceil link length to meters"); log.info(" overLengthFactor: "+overLengthFactor); for (Link l : network.getLinks().values()) { double dist = overLengthFactor*CoordUtils.calcEuclideanDistance(l.getFromNode().getCoord(),l.getToNode().getCoord()); if (dist > l.getLength()) { l.setLength(dist); } double len = Math.ceil(l.getLength()); l.setLength(len); } log.info("done."); } }
@Test public void testCalcDistance_oneLinkRoute() { Fixture f = new Fixture(); f.network.getLinks().get(f.linkIds[0]).setLength(100.0); f.network.getLinks().get(f.linkIds[1]).setLength(200.0); f.network.getLinks().get(f.linkIds[2]).setLength(300.0); f.network.getLinks().get(f.linkIds[3]).setLength(400.0); f.network.getLinks().get(f.linkIds[4]).setLength(500.0); f.network.getLinks().get(f.linkIds[5]).setLength(600.0); NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(f.linkIds[2], f.linkIds[4]); List<Id<Link>> linkIds = new ArrayList<Id<Link>>(); linkIds.add(f.linkIds[3]); route.setLinkIds(f.linkIds[2], linkIds, f.linkIds[4]); Assert.assertEquals(400.0, RouteUtils.calcDistanceExcludingStartEndLink(route, f.network), MatsimTestUtils.EPSILON); Assert.assertEquals(900.0, RouteUtils.calcDistance(route, 1.0, 1.0, f.network), MatsimTestUtils.EPSILON); }
@Test public void testCalcDistance_subsequentStartEndRoute() { Fixture f = new Fixture(); f.network.getLinks().get(f.linkIds[0]).setLength(100.0); f.network.getLinks().get(f.linkIds[1]).setLength(200.0); f.network.getLinks().get(f.linkIds[2]).setLength(300.0); f.network.getLinks().get(f.linkIds[3]).setLength(400.0); f.network.getLinks().get(f.linkIds[4]).setLength(500.0); f.network.getLinks().get(f.linkIds[5]).setLength(600.0); NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(f.linkIds[2], f.linkIds[3]); List<Id<Link>> linkIds = new ArrayList<Id<Link>>(); route.setLinkIds(f.linkIds[2], linkIds, f.linkIds[3]); Assert.assertEquals(0.0, RouteUtils.calcDistanceExcludingStartEndLink(route, f.network), MatsimTestUtils.EPSILON); Assert.assertEquals(400.0, RouteUtils.calcDistance(route, 1.0, 1.0, f.network), MatsimTestUtils.EPSILON); }
@Override public void run(Network network) { double maxDistance = this.distance * 2.0; for (Node node : network.getNodes().values()) { Coord coord = node.getCoord(); node.setCoord( new Coord(coord.getX() + (MatsimRandom.getRandom().nextDouble() - 0.5) * maxDistance, coord.getY() + (MatsimRandom.getRandom().nextDouble() - 0.5) * maxDistance) ) ; } for (Link link : network.getLinks().values()) { Coord fromCoord = link.getFromNode().getCoord(); Coord toCoord = link.getToNode().getCoord(); link.setLength(CoordUtils.calcEuclideanDistance(fromCoord, toCoord)); } }
private Link createAndAddLink(Node fromNode, Node toNode, Tuple<Node, Node> connection) { Link link; link = this.network.getFactory().createLink(Id.create(this.prefix + this.linkIdCounter++, Link.class), fromNode, toNode); if (fromNode == toNode) { link.setLength(50); } else { link.setLength(CoordUtils.calcEuclideanDistance(fromNode.getCoord(), toNode.getCoord())); } link.setFreespeed(30.0 / 3.6); link.setCapacity(500); link.setNumberOfLanes(1); this.network.addLink(link); link.setAllowedModes(this.transitModes); this.links.put(connection, link); return link; }
public static Link createAndAddLink(Network network, final Id<Link> id, final Node fromNode, final Node toNode, final double length, final double freespeed, final double capacity, final double numLanes, final String origId, final String type) { if (network.getNodes().get(fromNode.getId()) == null) { throw new IllegalArgumentException(network+"[from="+fromNode+" does not exist]"); } if (network.getNodes().get(toNode.getId()) == null) { throw new IllegalArgumentException(network+"[to="+toNode+" does not exist]"); } Link link = network.getFactory().createLink(id, fromNode, toNode) ; link.setLength(length); link.setFreespeed(freespeed); link.setCapacity(capacity); link.setNumberOfLanes(numLanes); setType( link, type); setOrigId( link, origId ) ; network.addLink( link ) ; return link; }
@Test public void testCalcDistance_sameStartEndRoute() { Fixture f = new Fixture(); f.network.getLinks().get(f.linkIds[0]).setLength(100.0); f.network.getLinks().get(f.linkIds[1]).setLength(200.0); f.network.getLinks().get(f.linkIds[2]).setLength(300.0); f.network.getLinks().get(f.linkIds[3]).setLength(400.0); f.network.getLinks().get(f.linkIds[4]).setLength(500.0); f.network.getLinks().get(f.linkIds[5]).setLength(600.0); NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(f.linkIds[3], f.linkIds[3]); List<Id<Link>> linkIds = new ArrayList<Id<Link>>(); route.setLinkIds(f.linkIds[3], linkIds, f.linkIds[3]); Assert.assertEquals(0.0, RouteUtils.calcDistanceExcludingStartEndLink(route, f.network), MatsimTestUtils.EPSILON); Assert.assertEquals(0.0, RouteUtils.calcDistance(route, 1.0, 1.0, f.network), MatsimTestUtils.EPSILON); Assert.assertEquals(400.0, RouteUtils.calcDistance(route, 0.0, 1.0, f.network), MatsimTestUtils.EPSILON); }
private void setDefaultLinkAttributes(final Link link) { link.setLength(1000.0); link.setFreespeed(10.0); link.setCapacity(3600.0); link.setNumberOfLanes(1); } }
private void setDefaultLinkAttributes(final Link link) { link.setLength(1000.0); link.setFreespeed(10.0); link.setCapacity(3600.0); link.setNumberOfLanes(1); }
private void setDefaultLinkAttributes(final Link link) { link.setLength(1000.0); link.setFreespeed(10.0); link.setCapacity(3600.0); link.setNumberOfLanes(1); } }
@Test public void testCalcDistance() { Fixture f = new Fixture(); f.network.getLinks().get(f.linkIds[0]).setLength(100.0); f.network.getLinks().get(f.linkIds[1]).setLength(200.0); f.network.getLinks().get(f.linkIds[2]).setLength(300.0); f.network.getLinks().get(f.linkIds[3]).setLength(400.0); f.network.getLinks().get(f.linkIds[4]).setLength(500.0); f.network.getLinks().get(f.linkIds[5]).setLength(600.0); NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(f.linkIds[0], f.linkIds[5]); List<Id<Link>> linkIds = new ArrayList<Id<Link>>(); Collections.addAll(linkIds, f.linkIds[1], f.linkIds[2], f.linkIds[3]); route.setLinkIds(f.linkIds[0], linkIds, f.linkIds[4]); Assert.assertEquals(900.0, RouteUtils.calcDistanceExcludingStartEndLink(route, f.network), MatsimTestUtils.EPSILON); Assert.assertEquals(1400.0, RouteUtils.calcDistance(route, 1.0, 1.0, f.network), MatsimTestUtils.EPSILON); // modify the route linkIds.add(f.linkIds[4]); route.setLinkIds(f.linkIds[0], linkIds, f.linkIds[5]); Assert.assertEquals(1400.0, RouteUtils.calcDistanceExcludingStartEndLink(route, f.network), MatsimTestUtils.EPSILON); Assert.assertEquals(2000.0, RouteUtils.calcDistance(route, 1.0, 1.0, f.network), MatsimTestUtils.EPSILON); }
private Link createLink(final NetworkFactory nf, final String id, final Node fromNode, final Node toNode) { Link l = nf.createLink(Id.create(id, Link.class), fromNode, toNode); l.setLength(1000.0); l.setCapacity(1800.0); l.setNumberOfLanes(2); l.setFreespeed(10.0); HashSet<String> modes = new HashSet<String>(); modes.add(TransportMode.car); modes.add(TransportMode.walk); l.setAllowedModes(modes); return l; } }
private static Link createLink(final Network network, final Id<Link> id, final Id<Node> fromNodeId, final Id<Node> toNodeId, final Set<String> modes) { Link link = network.getFactory().createLink(id, network.getNodes().get(fromNodeId), network.getNodes().get(toNodeId)); link.setAllowedModes(modes); link.setCapacity(2000.0); link.setFreespeed(10.0); link.setLength(100.0); link.setNumberOfLanes(1); return link; }
private void createNetwork() { Network network = this.scenario.getNetwork(); Node[] nodes = new Node[nOfLinks + 1]; for (int i = 0; i <= nOfLinks; i++) { nodes[i] = network.getFactory().createNode(Id.create(i, Node.class), new Coord(i * 500, 0)); network.addNode(nodes[i]); } for (int i = 0; i < nOfLinks; i++) { Link l = network.getFactory().createLink(Id.create(i, Link.class), nodes[i], nodes[i+1]); l.setLength(500.0); l.setFreespeed(10.0); l.setCapacity(1000.0); l.setNumberOfLanes(1); network.addLink(l); } }
private void createNetwork() { Network network = this.scenario.getNetwork(); Node[] nodes = new Node[nOfLinks * 2 + 2]; for (int i = 0; i <= nOfLinks; i++) { nodes[i] = network.getFactory().createNode(Id.create(i, Node.class), new Coord(i * 500, 0)); network.addNode(nodes[i]); nodes[i+nOfLinks+1] = network.getFactory().createNode(Id.create(i+nOfLinks+1, Node.class), new Coord(i * 500, 500)); network.addNode(nodes[i+nOfLinks+1]); } for (int i = 0; i < nOfLinks; i++) { Link link = network.getFactory().createLink(Id.create(i, Link.class), nodes[i], nodes[i+1]); link.setLength(500.0); link.setFreespeed(10.0); link.setCapacity(1000.0); link.setNumberOfLanes(1); network.addLink(link); link = network.getFactory().createLink(Id.create(i+nOfLinks, Link.class), nodes[i+nOfLinks+1], nodes[i+nOfLinks+2]); link.setLength(500.0); link.setFreespeed(10.0); link.setCapacity(1000.0); link.setNumberOfLanes(1); network.addLink(link); } }
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); }
public Fixture() { Network net = this.s.getNetwork(); NetworkFactory nf = net.getFactory(); Node n1 = nf.createNode(Id.create("1", Node.class), new Coord(0, 0)); Node n2 = nf.createNode(Id.create("2", Node.class), new Coord(0, 1000)); Node n3 = nf.createNode(Id.create("3", Node.class), new Coord(0, 2000)); Node n4 = nf.createNode(Id.create("4", Node.class), new Coord(0, 3000)); net.addNode(n1); net.addNode(n2); net.addNode(n3); net.addNode(n4); Link l1 = nf.createLink(Id.create("1", Link.class), n1, n2); Link l2 = nf.createLink(Id.create("2", Link.class), n2, n3); Link l3 = nf.createLink(Id.create("3", Link.class), n3, n4); l1.setFreespeed(10.0); l2.setFreespeed(10.0); l3.setFreespeed(10.0); l1.setLength(1000.0); l2.setLength(1000.0); l3.setLength(1000.0); net.addLink(l1); net.addLink(l2); net.addLink(l3); } }
private void createNetwork() { Network network = this.scenario.getNetwork(); NetworkFactory factory = network.getFactory(); Node a = factory.createNode(Id.create("A", Node.class), new Coord((double) 0, (double) 0)); Node b = factory.createNode(Id.create("B", Node.class), new Coord((double) 1000, (double) 0)); Node c = factory.createNode(Id.create("C", Node.class), new Coord((double) 500, (double) 600)); network.addNode(a); network.addNode(b); network.addNode(c); Link ab = factory.createLink(Id.create("ab", Link.class), a, b); Link bc = factory.createLink(Id.create("bc", Link.class), b, c); Link ca = factory.createLink(Id.create("ca", Link.class), c, a); Set<String> modes = new HashSet<>(); modes.add("car"); for (Link l : new Link[] {ab, bc, ca}) { l.setLength(1000); l.setCapacity(1800); l.setNumberOfLanes(1); l.setFreespeed(10.0); l.setAllowedModes(modes); network.addLink(l); } }
@Test public void testSetAttributes() { Network network = new NetworkImpl(); network.setCapacityPeriod(3600.0); Node node1 = NetworkUtils.createAndAddNode(network, Id.create(1, Node.class), new Coord((double) 0, (double) 0)); Node node2 = NetworkUtils.createAndAddNode(network, Id.create(2, Node.class), new Coord((double) 50, (double) 50)); final Node fromNode = node1; final Node toNode = node2; Link link1 = (Link) NetworkUtils.createAndAddLink(network,Id.create(1, Link.class), fromNode, toNode, 500.0, 10.0, 1000.0, 1.0 ); Assert.assertEquals("wrong freespeed traveltime.", 50.0, NetworkUtils.getFreespeedTravelTime(link1), EPSILON); link1.setLength(1000.0); Assert.assertEquals("wrong freespeed traveltime.", 100.0, NetworkUtils.getFreespeedTravelTime(link1), EPSILON); link1.setFreespeed(20.0); Assert.assertEquals("wrong freespeed traveltime.", 50.0, NetworkUtils.getFreespeedTravelTime(link1), EPSILON); }
private static void initNetwork(Network network) { Node node1 = network.getFactory().createNode(Id.create("1", Node.class), new Coord((double) 0, (double) 0)); Node node2 = network.getFactory().createNode(Id.create("2", Node.class), new Coord((double) 1, (double) 0)); Node node3 = network.getFactory().createNode(Id.create("3", Node.class), new Coord((double) 2, (double) 0)); network.addNode(node1); network.addNode(node2); network.addNode(node3); Link l1 = network.getFactory().createLink(Id.create("1", Link.class), node1, node2); l1.setLength(1005.0); l1.setFreespeed(15.0); l1.setCapacity(1800.0); l1.setNumberOfLanes(2.0); network.addLink(l1); Link l2 = network.getFactory().createLink(Id.create("2", Link.class), node2, node3); network.addLink(l2); }