public static Network createNetwork() { return new NetworkImpl(); }
/** * Sets the network change events and replaces existing events. Before * events are applied to their corresponding links, all links are reset to * their initial state. Pass an empty event list to reset the complete network. * * @param events a list of events. */ @Override public void setNetworkChangeEvents(final List<NetworkChangeEvent> events) { this.networkChangeEvents.clear(); for(Link link : getLinks().values()) { if (link instanceof TimeVariantLinkImpl) { ((TimeVariantLinkImpl)link).clearEvents(); } // Presumably, there is no exception here if this fails because it can be interpreted: maybe only some links are time-dependent // and others are not, and it is sufficient if the time-dependent ones can be configured by the addNetworkChangeEvent method. // kai, jul'16 } for (NetworkChangeEvent event : events) { this.addNetworkChangeEvent(event); } }
@Override public Link getNearestLinkExactly(final Coord coord) { if (this.linkQuadTree == null) { buildLinkQuadTree(); } return this.linkQuadTree.getNearest(coord.getX(), coord.getY()); }
@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); }
/** * @param capPeriod the capacity-period in seconds */ @Override public void setCapacityPeriod(final double capPeriod) { testForLocked() ; this.capacityPeriod = (int) capPeriod; } @Override
/** * finds the nodes within distance to <code>coord</code> * * @param coord the coordinate around which nodes should be located * @param distance the maximum distance a node can have to <code>coord</code> to be found * @return all nodes within distance to <code>coord</code> */ @Override public Collection<Node> getNearestNodes(final Coord coord, final double distance) { if (this.nodeQuadTree == null) { buildQuadTree(); } return this.nodeQuadTree.getDisk(coord.getX(), coord.getY(), distance); }
@Override public Node removeNode(final Id<Node> nodeId) { Node n = this.nodes.remove(nodeId); if (n == null) { return null; } HashSet<Link> links1 = new HashSet<>(); links1.addAll(n.getInLinks().values()); links1.addAll(n.getOutLinks().values()); for (Link l : links1) { removeLink(l.getId()); } if (this.nodeQuadTree != null) { this.nodeQuadTree.remove(n.getCoord().getX(),n.getCoord().getY(),n); } return n; }
if (this.counter2 % this.nextMsg2 == 0) { this.nextMsg2 *= 4; printNodesCount();
if (this.counter % this.nextMsg == 0) { this.nextMsg *= 4; printLinksCount();
NetworkFactory nf = network.getFactory(); nf.setLinkFactory(lf); ((NetworkImpl)network).setFactory(nf); network.setCapacityPeriod(3600.0);
@Override public void setEffectiveLaneWidth(final double effectiveLaneWidth) { testForLocked() ; if (!Double.isNaN(this.effectiveLaneWidth) && this.effectiveLaneWidth != effectiveLaneWidth) { log.warn(this + "[effectiveLaneWidth=" + this.effectiveLaneWidth + " already set. Will be overwritten with " + effectiveLaneWidth + "]"); } this.effectiveLaneWidth = effectiveLaneWidth; }
/** * finds the node nearest to <code>coord</code> * * @param coord the coordinate to which the closest node should be found * @return the closest node found, null if none */ @Override public Node getNearestNode(final Coord coord) { if (this.nodeQuadTree == null) { buildQuadTree(); } return this.nodeQuadTree.getClosest(coord.getX(), coord.getY()); }
@Override public Network getEmptyTestNetwork() { return new NetworkImpl(); }
NetworkFactory nf = network.getFactory(); nf.setLinkFactory(lf); ((NetworkImpl)network).setFactory(nf); network.setCapacityPeriod(3600.0);
@Override public void setEffectiveCellSize(final double effectiveCellSize) { testForLocked() ; if (this.effectiveCellSize != effectiveCellSize) { if (effectiveCellSize != DEFAULT_EFFECTIVE_CELL_SIZE) { log.warn("Setting effectiveCellSize to a non-default value of " + effectiveCellSize); } else { log.info("Setting effectiveCellSize to " + effectiveCellSize); } this.effectiveCellSize = effectiveCellSize; } } @Override
public static Network createNetwork(NetworkConfigGroup networkConfigGroup) { Network network = new NetworkImpl(); if (networkConfigGroup.isTimeVariantNetwork()) { network.getFactory().setLinkFactory(new VariableIntervalTimeVariantLinkFactory()); } return network; }
NetworkFactory nf = network.getFactory(); nf.setLinkFactory(lf); ((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));
Network network = new NetworkImpl(); Node n1 = NetworkUtils.createAndAddNode(network, Id.create(1, Node.class), new Coord((double) 0, (double) 0)); Node n2 = NetworkUtils.createAndAddNode(network, Id.create(2, Node.class), new Coord((double) 1000, (double) 0));
NetworkFactory nf = network.getFactory(); nf.setLinkFactory(lf); ((NetworkImpl)network).setFactory(nf); network.setCapacityPeriod(3600.0);
@Test public void testAddNode_existingId() { Network network = new NetworkImpl(); Node node1 = NetworkUtils.createNode(Id.create(1, Node.class), new Coord((double) 0, (double) 0)); Node node2 = NetworkUtils.createNode(Id.create(2, Node.class), new Coord((double) 1000, (double) 0)); Node node3 = NetworkUtils.createNode(Id.create(3, Node.class), new Coord((double) 2000, (double) 500)); Node node1b = NetworkUtils.createNode(Id.create(1, Node.class), new Coord((double) 2000, (double) 0)); network.addNode(node1); network.addNode(node2); Assert.assertEquals(2, network.getNodes().size()); try { network.addNode(node1b); Assert.fail("missing exception. Should not be able to add different node with existing id."); } catch (IllegalArgumentException e) { log.info("catched expected exception.", e); } Assert.assertEquals(2, network.getNodes().size()); network.addNode(node1); // adding the same node again should just be ignored Assert.assertEquals(2, network.getNodes().size()); network.addNode(node3); Assert.assertEquals(3, network.getNodes().size()); }