net.setEffectiveCellSize(0.26); NetworkFactory fac = net.getFactory(); Node n0 = fac.createNode(Id.createNodeId(0), CoordUtils.createCoord(93.85, 110.1)); net.addNode(n0); Node n1 = fac.createNode(Id.createNodeId(1), CoordUtils.createCoord(103.85, 110.1)); net.addNode(n1); Node n2 = fac.createNode(Id.createNodeId(2), CoordUtils.createCoord(113.85, 110.1)); net.addNode(n2); Node n3 = fac.createNode(Id.createNodeId(3), CoordUtils.createCoord(200, 110.1)); net.addNode(n3); Node n4 = fac.createNode(Id.createNodeId(4), CoordUtils.createCoord(210, 110.1)); net.addNode(n4); Node n5 = fac.createNode(Id.createNodeId(5), CoordUtils.createCoord(220, 110.1)); net.addNode(n5); Link l0 = fac.createLink(Id.createLinkId(0), n0, n1); net.addLink(l0); Link l1 = fac.createLink(Id.createLinkId(1), n1, n2); net.addLink(l1); Link lJPS0 = fac.createLink(Id.createLinkId("JPS0"), n2, n3); net.addLink(lJPS0); Link l2 = fac.createLink(Id.createLinkId("2"), n3, n4); net.addLink(l2); Link l3 = fac.createLink(Id.createLinkId("3"), n4, n5); net.addLink(l3); Link l3r = fac.createLink(Id.createLinkId("3r"), n5, n4); net.addLink(l3r); Link l2r = fac.createLink(Id.createLinkId("2r"), n4, n3); net.addLink(l2r); Link lJPS0r = fac.createLink(Id.createLinkId("JPS0r"), n3, n2);
public static Network createNetwork(NetworkConfigGroup networkConfigGroup) { Network network = new NetworkImpl(); if (networkConfigGroup.isTimeVariantNetwork()) { network.getFactory().setLinkFactory(new VariableIntervalTimeVariantLinkFactory()); } return network; }
public static Node createAndAddNode(Network network, final Id<Node> id, final Coord coord) { if (network.getNodes().containsKey(id)) { throw new IllegalArgumentException(network + "[id=" + id + " already exists]"); } Node n = network.getFactory().createNode(id, coord); network.addNode(n) ; return n; }
throw new RuntimeException("node id given by link cannot be dereferenced; node label=" + toNodeStr ) ; Link l = this.network.getFactory().createLink(Id.create(atts.getValue("id"), Link.class), fromNode, toNode); l.setLength(Double.parseDouble(atts.getValue("length"))); l.setFreespeed(Double.parseDouble(atts.getValue("freespeed")));
private void startNode(final Attributes atts) { boolean hasZ = atts.getValue("z") == null ? false : true; Coord c; if(hasZ){ c = transformation.transform(new Coord( Double.parseDouble(atts.getValue("x")), Double.parseDouble(atts.getValue("y")), Double.parseDouble(atts.getValue("z")))); hasElevation = true; } else{ c = transformation.transform(new Coord( Double.parseDouble(atts.getValue("x")), Double.parseDouble(atts.getValue("y")))); hasNoElevation = true; } final Node node = this.network.getFactory().createNode( Id.create(atts.getValue("id"), Node.class), c); this.network.addNode(node); NetworkUtils.setType(node,atts.getValue("type")); // (did not have a null check when I found it. kai, jul'16) if (atts.getValue("origid") != null) { NetworkUtils.setOrigId( node, atts.getValue("origid") ) ; } }
throw new RuntimeException("node id given by link cannot be dereferenced; node label=" + toNodeStr ) ; Link l = this.network.getFactory().createLink(Id.create(atts.getValue("id"), Link.class), fromNode, toNode); l.setLength(Double.parseDouble(atts.getValue("length"))); l.setFreespeed(Double.parseDouble(atts.getValue("freespeed")));
NetworkFactory fac = net.getFactory(); net.addNode(fac.createNode(Id.createNodeId(1), new Coord(-2000, 0))); net.addNode(fac.createNode(Id.createNodeId(2), new Coord(-1000, 0))); net.addNode(fac.createNode(Id.createNodeId(3), new Coord(0, 0))); net.addNode(fac.createNode(Id.createNodeId(4), new Coord(1000, 0))); net.addNode(fac.createNode(Id.createNodeId(5), new Coord(2000, 0))); net.addNode(fac.createNode(Id.createNodeId(6), new Coord(0, 2000))); net.addNode(fac.createNode(Id.createNodeId(7), new Coord(0, 1000))); net.addNode(fac.createNode(Id.createNodeId(8), new Coord(0, -1000))); net.addNode(fac.createNode(Id.createNodeId(9), new Coord(0, -2000))); String fromNodeId = linkId.split("_")[0]; String toNodeId = linkId.split("_")[1]; Link link = fac.createLink(Id.createLinkId(linkId), net.getNodes().get(Id.createNodeId(fromNodeId)), net.getNodes().get(Id.createNodeId(toNodeId)));
private void startNode(final Attributes atts) { final Node node = this.network.getFactory().createNode( Id.create(atts.getValue("id"), Node.class), parseCoord(atts)); this.network.addNode(node); NetworkUtils.setType(node,atts.getValue("type")); // (did not have a null check when I found it. kai, jul'16) if (atts.getValue(NetworkUtils.ORIGID) != null) { NetworkUtils.setOrigId( node, atts.getValue(NetworkUtils.ORIGID) ) ; } currentAttributes = node.getAttributes(); }
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 testChangeEventsParserWriter() { String input = utils.getInputDirectory() + "testNetworkChangeEvents.xml"; String output = utils.getOutputDirectory() + "outputTestNetworkChangeEvents.xml"; final Network network = NetworkUtils.createNetwork(); NetworkFactory nf = network.getFactory(); nf.setLinkFactory(new VariableIntervalTimeVariantLinkFactory()); ((NetworkImpl)network).setFactory(nf); 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) 0, (double) 1000)); Node node3 = NetworkUtils.createAndAddNode(network, Id.create("3", Node.class), new Coord((double) 1000, (double) 2000)); NetworkUtils.createAndAddLink(network,Id.create("1", Link.class), node1, node2, (double) 1000, 1.667, (double) 3600, (double) 1 ); NetworkUtils.createAndAddLink(network,Id.create("2", Link.class), node2, node3, (double) 1500, 1.667, (double) 3600, (double) 1 ); List<NetworkChangeEvent> events = new ArrayList<>(); NetworkChangeEventsParser parser = new NetworkChangeEventsParser(network, events ); parser.readFile(input); new NetworkChangeEventsWriter().write(output, events); long checksum_ref = CRCChecksum.getCRCFromFile(input); long checksum_run = CRCChecksum.getCRCFromFile(output); assertEquals(checksum_ref, checksum_run); }
this.network.addNode(nodes[1] = f.createNode(this.nodeIds[1], new Coord((double) 100, (double) 200))); this.network.addNode(nodes[2] = f.createNode(this.nodeIds[2], new Coord((double) 200, (double) 200))); this.network.addNode(nodes[3] = f.createNode(this.nodeIds[3], new Coord((double) 0, (double) 0))); this.network.addNode(nodes[4] = f.createNode(this.nodeIds[4], new Coord((double) 100, (double) 100))); this.network.addNode(nodes[5] = f.createNode(this.nodeIds[5], new Coord((double) 200, (double) 100))); this.network.addNode(nodes[6] = f.createNode(this.nodeIds[6], new Coord((double) 300, (double) 100))); this.network.addNode(nodes[7] = f.createNode(this.nodeIds[7], new Coord((double) 100, (double) 0))); this.network.addNode(nodes[8] = f.createNode(this.nodeIds[8], new Coord((double) 200, (double) 0))); this.network.addLink(f.createLink(this.linkIds[1], nodes[4], nodes[1])); this.network.addLink(f.createLink(this.linkIds[2], nodes[1], nodes[2])); this.network.addLink(f.createLink(this.linkIds[3], nodes[2], nodes[5])); this.network.addLink(f.createLink(this.linkIds[4], nodes[3], nodes[4])); this.network.addLink(f.createLink(this.linkIds[5], nodes[4], nodes[5])); this.network.addLink(f.createLink(this.linkIds[6], nodes[5], nodes[6])); this.network.addLink(f.createLink(this.linkIds[7], nodes[4], nodes[7])); this.network.addLink(f.createLink(this.linkIds[8], nodes[7], nodes[8])); this.network.addLink(f.createLink(this.linkIds[9], nodes[8], nodes[5])); this.network.addLink(f.createLink(this.linkIds[10], nodes[5], nodes[8])); this.network.addLink(f.createLink(this.linkIds[11], nodes[8], nodes[7])); this.network.addLink(f.createLink(this.linkIds[12], nodes[7], nodes[4]));
private Node addNode(Network net, Node n){ Node newNode = net.getFactory().createNode(n.getId(), n.getCoord()); net.addNode(newNode); return newNode; }
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; } }
/** * Creates a network with three links of length 100 m, capacity 3600 veh/h * and freespeed 10 m/s. * * @author illenberger */ private static Network createNetwork(Scenario scenario) { // create a network NetworkFactory nf = (NetworkFactory) scenario.getNetwork().getFactory(); nf.setLinkFactory(new VariableIntervalTimeVariantLinkFactory()); final Network network = (Network) scenario.getNetwork(); network.setCapacityPeriod(3600.0); // the network has 4 nodes and 3 links, each link by default 100 long and freespeed = 10 --> freespeed travel time = 10.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) 100, (double) 0)); Node node3 = NetworkUtils.createAndAddNode(network, Id.create("3", Node.class), new Coord((double) 200, (double) 0)); Node node4 = NetworkUtils.createAndAddNode(network, Id.create("4", Node.class), new Coord((double) 300, (double) 0)); final Node fromNode = node1; final Node toNode = node2; NetworkUtils.createAndAddLink(network,Id.create("1", Link.class), fromNode, toNode, (double) 100, (double) 10, (double) 3600, (double) 1 ); final Node fromNode1 = node2; final Node toNode1 = node3; NetworkUtils.createAndAddLink(network,Id.create("2", Link.class), fromNode1, toNode1, (double) 100, (double) 10, (double) 3600, (double) 1 ); final Node fromNode2 = node3; final Node toNode2 = node4; NetworkUtils.createAndAddLink(network,Id.create("3", Link.class), fromNode2, toNode2, (double) 100, (double) 10, (double) 3600, (double) 1 ); return network; }
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); } }
fromNode = this.network.getFactory().createNode(Id.create(this.prefix + toFacility.getId(), Node.class), fromFacility.getCoord()); this.network.addNode(fromNode); this.nodes.put(toFacility, fromNode); toNode = this.network.getFactory().createNode(Id.create(this.prefix + toFacility.getId(), Node.class), toFacility.getCoord()); this.network.addNode(toNode); this.nodes.put(toFacility, toNode);
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; }
final Network network = NetworkUtils.createNetwork(); NetworkFactory nf = network.getFactory(); nf.setLinkFactory(lf); ((NetworkImpl)network).setFactory(nf); network.setCapacityPeriod(3600.0);
private void createFakeNetwork(Scenario scenario, Network network){ Coord coord = new Coord((double) 0, (double) 0); Node n1 = network.getFactory().createNode(Id.create(0, Node.class), coord); network.addNode( n1 ) ; Node n2 = network.getFactory().createNode(Id.create(1, Node.class), coord); network.addNode( n2 ) ; for (int i = 1; i <= linkCount; i++) { Link l = network.getFactory().createLink(Id.create(i, Link.class), n1, n2); network.addLink( l ) ; } }
final NetworkFactory factory = network.getFactory(); network.addNode(factory.createNode(this.nodeIds[ 1], new Coord((double) 0, (double) 100))); network.addNode(factory.createNode(this.nodeIds[ 2], new Coord((double) 0, (double) 0))); network.addNode(factory.createNode(this.nodeIds[ 3], new Coord((double) 100, (double) 0))); network.addNode(factory.createNode(this.nodeIds[ 4], new Coord((double) 100, (double) 100))); network.addNode(factory.createNode(this.nodeIds[ 5], new Coord((double) 100, (double) 200))); network.addNode(factory.createNode(this.nodeIds[ 6], new Coord((double) 200, (double) 200))); network.addNode(factory.createNode(this.nodeIds[ 7], new Coord((double) 200, (double) 100))); network.addNode(factory.createNode(this.nodeIds[ 8], new Coord((double) 200, (double) 0))); network.addNode(factory.createNode(this.nodeIds[ 9], new Coord((double) 300, (double) 0))); network.addNode(factory.createNode(this.nodeIds[10], new Coord((double) 300, (double) 100))); network.addNode(factory.createNode(this.nodeIds[11], new Coord((double) 300, (double) 200))); network.addNode(factory.createNode(this.nodeIds[12], new Coord((double) 400, (double) 200))); network.addNode(factory.createNode(this.nodeIds[13], new Coord((double) 400, (double) 100)));