/*package*/ void addConnectorLinks() { QuadTree<Node> quadTree = getNodesQuadTree(); NetworkFactory factory = network.getFactory(); /* * Try to use the centroid of the polygon. If that does not lie within * the polygon, use an interior point. */ for (Entry<Integer, SimpleFeature> entry : zonesMap.entrySet()) { int zoneId = entry.getKey(); SimpleFeature zone = entry.getValue(); if (SpecialZones.skipZone(zone)) continue; Geometry polygon = (Geometry) zone.getDefaultGeometry(); Point point = polygon.getCentroid(); if (!polygon.contains(point)) point = polygon.getInteriorPoint(); /* * Convert coordinate from WGS84 to EPSG:28992 (Netherlands Projection) */ Coord wgs84Coord = new Coord(point.getCoordinate().x, point.getCoordinate().y); Coord nodeCoord = ct.transform(wgs84Coord); Id<Node> nodeId = Id.create(String.valueOf(zoneId), Node.class); network.addNode(factory.createNode(nodeId, nodeCoord)); Node networkConnectorNode = quadTree.getClosest(nodeCoord.getX(), nodeCoord.getY()); Id<Node> networkConnectorNodeId = networkConnectorNode.getId(); double length = CoordUtils.calcDistance(nodeCoord, networkConnectorNode.getCoord()); Id<Link> linkFromId = Id.create(String.valueOf(zoneId) + "from", Link.class); Link fromLink = factory.createLink(linkFromId, nodeId, networkConnectorNodeId); fromLink.setLength(length); fromLink.setCapacity(this.connectorCapacity); fromLink.setFreespeed(this.connectorLinkFreeSpeed); network.addLink(fromLink); Id<Link> linkToId = Id.create(String.valueOf(zoneId) + "to", Link.class); Link toLink = factory.createLink(linkToId, networkConnectorNodeId, nodeId); toLink.setLength(length); toLink.setCapacity(this.connectorCapacity); toLink.setFreespeed(this.connectorLinkFreeSpeed); network.addLink(toLink); } }
private void createAndAddLinks( Id<Link> linkId, Id<Link> backLinkId, Id<Node> fromNodeId, Id<Node> toNodeId, Network net) { NetworkFactory fac = net.getFactory(); Link l = fac.createLink(linkId, net.getNodes().get(fromNodeId), net.getNodes().get(toNodeId)); l.setCapacity(capacity); l.setFreespeed(fs); l.setLength(linkLength); net.addLink(l); l = fac.createLink(backLinkId, net.getNodes().get(toNodeId), net.getNodes().get(fromNodeId)); l.setCapacity(capacity); l.setFreespeed(fs); l.setLength(linkLength); net.addLink(l); }
public void add() { List<Link> links = ((BusLaneAdderPanel) layersPanels.get(PanelIds.ONE)).getLinks(); Node prevNode = links.get(0).getFromNode(); for (Link link : links) if (!link.getAllowedModes().contains("bus")) { exitSave(); JOptionPane.showMessageDialog(this, "Wrong path, network saved"); } for (int i = 0; i < links.size(); i++) { Link link = links.get(i); Node node = null; if (link.getNumberOfLanes() == 1) { Set<String> modes = new HashSet<String>(); modes.add("bus"); link.setAllowedModes(modes); node = link.getToNode(); } else { Node oldNode = link.getToNode(); if (i == links.size() - 1 || oldNode.getInLinks().size() + oldNode.getOutLinks().size() > 2) node = oldNode; else { node = network .getFactory() .createNode( Id.createNodeId("fl" + oldNode.getId().toString()), oldNode.getCoord()); network.addNode(node); } LinkImpl newLink = (LinkImpl) network .getFactory() .createLink(Id.createLinkId("fl" + link.getId().toString()), prevNode, node); Set<String> modes = new HashSet<String>(); modes.add("car"); newLink.setAllowedModes(modes); newLink.setCapacity(link.getCapacity()); newLink.setFreespeed(link.getFreespeed()); newLink.setLength(link.getLength()); newLink.setNumberOfLanes(link.getNumberOfLanes() - 1); newLink.setOrigId(((LinkImpl) link).getOrigId()); newLink.setType(((LinkImpl) link).getType()); network.addLink(newLink); Set<String> modes2 = new HashSet<String>(); modes2.add("bus"); link.setAllowedModes(modes2); link.setCapacity(900); link.setNumberOfLanes(1); } prevNode = node; } ((BusLaneAdderPanel) layersPanels.get(PanelIds.ONE)).clearSelection(); }
private final void convertPseudoNetwork() { List<Id> nodeIds = new ArrayList<Id>(scenario.getNetwork().getNodes().keySet()); for (Id id : nodeIds) { scenario.getNetwork().removeNode(id); } new CreatePseudoNetwork(scenario.getTransitSchedule(), scenario.getNetwork(), "") .createNetwork(); for (Link l : scenario.getNetwork().getLinks().values()) { l.setCapacity(WagonSimConstants.DEFAULT_CAPACITY); l.setFreespeed(WagonSimConstants.DEFAULT_FREESPEED); } }
private Link getNewLink(Node fromNode, Node toNode) { Link link = networkFactory.createLink( Id.create(prefix + linkIdCounter++, Link.class), fromNode, toNode); if (fromNode == toNode) { link.setLength(50); } else { link.setLength(CoordUtils.calcDistance(fromNode.getCoord(), toNode.getCoord())); } link.setFreespeed(80.0 / 3.6); link.setCapacity(10000); link.setNumberOfLanes(1); link.setAllowedModes(this.transitModes); return link; }
private void assignProps(Collection<Link> links, Link link) { double capacity = 0; double freespeed = 0; double lanes = 0; for (Link origLink : links) { capacity += origLink.getCapacity(); freespeed = Math.max(freespeed, origLink.getFreespeed()); lanes += origLink.getNumberOfLanes(); } link.setCapacity(capacity); link.setFreespeed(freespeed); link.setNumberOfLanes(lanes); link.setLength( NetworkUtils.getEuclideanDistance( link.getFromNode().getCoord(), link.getToNode().getCoord())); }
/** * Tests that a custom scoring function factory doesn't get overwritten in the initialization * process of the Controler. * * @author mrieser */ @Test public void testSetScoringFunctionFactory() { final Config config = this.utils.loadConfig(null); config.controler().setLastIteration(0); ScenarioImpl scenario = (ScenarioImpl) ScenarioUtils.createScenario(config); // create a very simple network with one link only and an empty population Network network = scenario.getNetwork(); Node node1 = network.getFactory().createNode(Id.create(1, Node.class), new Coord(0, 0)); Node node2 = network.getFactory().createNode(Id.create(2, Node.class), new Coord(100, 0)); network.addNode(node1); network.addNode(node2); Link link = network.getFactory().createLink(Id.create(1, Link.class), node1, node2); link.setLength(100); link.setFreespeed(1); link.setCapacity(3600.0); link.setNumberOfLanes(1); final Controler controler = new Controler(scenario); controler.getConfig().controler().setCreateGraphs(false); controler.getConfig().controler().setWriteEventsInterval(0); controler.setScoringFunctionFactory(new DummyScoringFunctionFactory()); controler.addOverridingModule( new AbstractModule() { @Override public void install() { bindMobsim() .toProvider( new Provider<Mobsim>() { @Override public Mobsim get() { return new FakeMobsim(); } }); } }); controler.setDumpDataAtEnd(false); controler.run(); assertTrue( "Custom ScoringFunctionFactory was not set.", controler.getScoringFunctionFactory() instanceof DummyScoringFunctionFactory); }
public static void changePropertiesGroupLinksCSVFile(Network network, String fileName) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(new File(fileName))); reader.readLine(); String line = reader.readLine(); while (line != null) { String[] parts = line.split(CSV_SEPARATOR); double[] values = new double[parts.length]; for (int i = 0; i < parts.length; i++) values[i] = Double.parseDouble(parts[i]); for (Link link : network.getLinks().values()) if (isLinkOfType(link, values[0], values[1], values[2])) { link.setFreespeed(values[3]); link.setCapacity(values[4]); link.setNumberOfLanes(values[5]); } line = reader.readLine(); } reader.close(); }
@Before public void setUp() throws Exception { scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); this.population = scenario.getPopulation(); Person person = PopulationUtils.getFactory().createPerson(DEFAULT_PERSON_ID); this.population.addPerson(person); Plan plan = PersonUtils.createAndAddPlan(person, true); PopulationUtils.createAndAddActivityFromCoord(plan, "act1", new Coord(100.0, 100.0)); PopulationUtils.createAndAddLeg(plan, "undefined"); PopulationUtils.createAndAddActivityFromCoord(plan, "act2", new Coord(200.0, 200.0)); PopulationUtils.createAndAddLeg(plan, "undefined"); PopulationUtils.createAndAddActivityFromCoord(plan, "act3", new Coord(200.0, 200.0)); PopulationUtils.createAndAddLeg(plan, "undefined"); PopulationUtils.createAndAddActivityFromCoord(plan, "act4", new Coord(200.0, 200.0)); PopulationUtils.createAndAddLeg(plan, "undefined"); PopulationUtils.createAndAddActivityFromCoord(plan, "act5", new Coord(200.0, 200.0)); plan.setScore(12.); this.network = scenario.getNetwork(); Node fromNode = this.network .getFactory() .createNode(Id.create("123456", Node.class), new Coord(100.0, 100.0)); this.network.addNode(fromNode); Node toNode = this.network .getFactory() .createNode(Id.create("789012", Node.class), new Coord(200.0, 200.0)); this.network.addNode(toNode); Link link = this.network.getFactory().createLink(DEFAULT_LINK_ID, fromNode, toNode); link.setLength(Math.sqrt(20000.0)); link.setFreespeed(13.333); link.setCapacity(2000); link.setNumberOfLanes(1); this.network.addLink(link); }
public static void main(String[] args) { roadTypeAndHBEFARoadType = new TreeMap<String, String[]>(); roadTypeAndHBEFARoadType.put("motorway", new String[] {"1", "RUR/MW/120"}); roadTypeAndHBEFARoadType.put("motorway_link", new String[] {"2", "URB/MW-Nat./80"}); roadTypeAndHBEFARoadType.put("trunk", new String[] {"3", "URB/MW-City/80"}); roadTypeAndHBEFARoadType.put("trunk_link", new String[] {"4", "URB/Trunk-City/50"}); roadTypeAndHBEFARoadType.put("primary", new String[] {"5", "URB/Trunk-Nat./80"}); roadTypeAndHBEFARoadType.put("primary_link", new String[] {"6", "RUR/Distr-sin./60"}); roadTypeAndHBEFARoadType.put("secondary", new String[] {"7", "URB/Distr/60"}); roadTypeAndHBEFARoadType.put("tertiary", new String[] {"8", "URB/Local/50"}); roadTypeAndHBEFARoadType.put("unclassified", new String[] {"9", "URB/Access/50"}); roadTypeAndHBEFARoadType.put("residential", new String[] {"10", "URB/Access/30"}); Scenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); final Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()) .readFile("./input/baseCase/SiouxFalls_network_fromOSM.xml"); writer = IOUtils.getBufferedWriter("./input/emissionFiles/SiouxFalls_roadTypeMapping.txt"); for (Link link : network.getLinks().values()) { String linkIdentifier = link.getId().toString().split("___")[1]; if (roadTypeAndHBEFARoadType.containsKey(linkIdentifier)) { ((LinkImpl) link).setType(roadTypeAndHBEFARoadType.get(linkIdentifier)[0]); } else { throw new RuntimeException("Road Category " + linkIdentifier + " is not defined."); } link.setCapacity(link.getCapacity()); network.addLink( link); // This will give warning for duplicat of link in network which can be ignored as // same link is added with type of linkImpl. } new NetworkWriter(network).write("./input/baseCase/SiouxFalls_networkWithRoadType.xml.gz"); writeRoadTypeMappingFile(); }
private static void createNetwork(Scenario sc) { Network net = sc.getNetwork(); NetworkFactory fac = net.getFactory(); double length = 60; double width = 20; int id = 0; Node n0 = fac.createNode(Id.createNodeId(id++), CoordUtils.createCoord(0, 0)); Node n1 = fac.createNode(Id.createNodeId(id++), CoordUtils.createCoord(length, 0)); Node n2 = fac.createNode(Id.createNodeId(id++), CoordUtils.createCoord(length, length)); Node n3 = fac.createNode(Id.createNodeId(id++), CoordUtils.createCoord(0, length)); net.addNode(n0); net.addNode(n1); net.addNode(n2); net.addNode(n3); id = 0; { Link l0 = fac.createLink(Id.createLinkId(id++), n0, n1); net.addLink(l0); l0.setCapacity(width); l0.setLength(length); } { Link l0 = fac.createLink(Id.createLinkId(id++), n1, n2); net.addLink(l0); l0.setCapacity(width); l0.setLength(length); } { Link l0 = fac.createLink(Id.createLinkId(id++), n2, n3); net.addLink(l0); l0.setCapacity(width); l0.setLength(length); } { Link l0 = fac.createLink(Id.createLinkId(id++), n3, n0); net.addLink(l0); l0.setCapacity(width); l0.setLength(length); } { Link l0 = fac.createLink(Id.createLinkId(id++), n1, n0); net.addLink(l0); l0.setCapacity(width); l0.setLength(length); } { Link l0 = fac.createLink(Id.createLinkId(id++), n2, n1); net.addLink(l0); l0.setCapacity(width); l0.setLength(length); } { Link l0 = fac.createLink(Id.createLinkId(id++), n3, n2); net.addLink(l0); l0.setCapacity(width); l0.setLength(length); } { Link l0 = fac.createLink(Id.createLinkId(id++), n0, n3); net.addLink(l0); l0.setCapacity(width); l0.setLength(length); } }
public static void main(String[] args) throws IOException { List<Setting> settings = new ArrayList<>(); for (double w = 2.9; w < 3; w += 0.05) { settings.add(new Setting(w, 3, 3, 500, 0, w, w)); } for (double w = .4; w < 3; w += 0.2) { settings.add(new Setting(3, 3, w, 500, 0, w, w)); } for (double w = 0.8; w <= 3; w += 0.2) { settings.add(new Setting(w, 3, 3, 500, 0, w, w)); } AbstractCANetwork.EMIT_VIS_EVENTS = false; USE_SPH = true; for (int R = 12; R <= 12; R++) { CASingleLaneDensityEstimatorSPH.H = R; CAMultiLaneDensityEstimatorSPH.H = R; CASingleLaneDensityEstimatorSPA.RANGE = R; CASingleLaneDensityEstimatorSPHII.H = R; CASingleLaneDensityEstimatorSPAII.RANGE = R; try { bw = new BufferedWriter( new FileWriter(new File("/Users/laemmel/devel/bipedca/ant/uni" + R))); } catch (IOException e) { e.printStackTrace(); } for (Setting s : settings) { System.out.println(s); Config c = ConfigUtils.createConfig(); c.global().setCoordinateSystem("EPSG:3395"); Scenario sc = ScenarioUtils.createScenario(c); // VIS only Sim2DConfig conf2d = Sim2DConfigUtils.createConfig(); Sim2DScenario sc2d = Sim2DScenarioUtils.createSim2dScenario(conf2d); sc.addScenarioElement(Sim2DScenario.ELEMENT_NAME, sc2d); Network net = sc.getNetwork(); ((NetworkImpl) net).setCapacityPeriod(1); NetworkFactory fac = net.getFactory(); int l = 8; int res = 20; Node n0 = fac.createNode(Id.createNodeId("0"), new CoordImpl(20 - res, 0)); Node n1 = fac.createNode(Id.createNodeId("1"), new CoordImpl(20, 0)); Node n2 = fac.createNode(Id.createNodeId("2"), new CoordImpl(24, 0)); Node n2ex = fac.createNode(Id.createNodeId("2ex"), new CoordImpl(24, 20)); Node n3 = fac.createNode(Id.createNodeId("3"), new CoordImpl(24 + l, 0)); Node n3ex = fac.createNode(Id.createNodeId("3ex"), new CoordImpl(24 + l, -20)); Node n4 = fac.createNode(Id.createNodeId("4"), new CoordImpl(24 + 4 + l, 0)); Node n5 = fac.createNode(Id.createNodeId("5"), new CoordImpl(24 + 4 + res + l, 0)); net.addNode(n5); net.addNode(n4); net.addNode(n3ex); net.addNode(n3); net.addNode(n2ex); net.addNode(n2); net.addNode(n1); net.addNode(n0); Link l0 = fac.createLink(Id.createLinkId("0"), n0, n1); Link l0rev = fac.createLink(Id.createLinkId("0rev"), n1, n0); Link l1 = fac.createLink(Id.createLinkId("1"), n1, n2); Link l1rev = fac.createLink(Id.createLinkId("1rev"), n2, n1); Link l2 = fac.createLink(Id.createLinkId("2"), n2, n3); Link l2rev = fac.createLink(Id.createLinkId("2rev"), n3, n2); Link l2ex = fac.createLink(Id.createLinkId("2ex"), n2, n2ex); Link l3 = fac.createLink(Id.createLinkId("3"), n3, n4); Link l3ex = fac.createLink(Id.createLinkId("3ex"), n3, n3ex); Link l3rev = fac.createLink(Id.createLinkId("3rev"), n4, n3); Link l4 = fac.createLink(Id.createLinkId("4"), n4, n5); Link l4rev = fac.createLink(Id.createLinkId("4rev"), n5, n4); l0.setLength(res); l1.setLength(4); l0rev.setLength(res); l1rev.setLength(4); l2rev.setLength(l); l2.setLength(l); l3rev.setLength(4); l3.setLength(4); l4rev.setLength(res); l4.setLength(res); l3ex.setLength(20); l2ex.setLength(20); net.addLink(l4); net.addLink(l4rev); net.addLink(l1); net.addLink(l0); net.addLink(l2); net.addLink(l2rev); net.addLink(l1rev); net.addLink(l0rev); net.addLink(l3rev); net.addLink(l3); net.addLink(l3ex); net.addLink(l2ex); double bl = s.bL; double bc = s.bCor; double br = s.bR; double bexR = s.bexR; double bexL = s.bexL; l0.setCapacity(5); l0rev.setCapacity(5); l1.setCapacity(bl); l1rev.setCapacity(bl); l2.setCapacity(bc); l2rev.setCapacity(bc); l3.setCapacity(br); l3rev.setCapacity(br); l4.setCapacity(5); l4rev.setCapacity(5); l3ex.setCapacity(bexR); l2ex.setCapacity(bexL); List<Link> linksLR = new ArrayList<Link>(); linksLR.add(l0); linksLR.add(l1); linksLR.add(l2); linksLR.add(l3ex); List<Link> linksRL = new ArrayList<Link>(); linksRL.add(l4rev); linksRL.add(l3rev); linksRL.add(l2rev); linksRL.add(l2ex); for (int i = 0; i < 1; i++) { for (double th = 1; th <= 1; th += 0.15) { runIt(net, linksLR, linksRL, sc, th, s); } // for (double th = .26; th <= .4; th += 0.01) { // runIt(net, linksLR, sc, th); // } // for (double th = .45; th < .5; th += 0.05) { // runIt(net, linksLR, sc, th); // } // for (double th = .5; th <= 1.; th += 0.1) { // runIt(net, linksLR, sc, th); // } } } bw.close(); } }
private void createLink( final Network network, final OsmWay way, final OsmNode fromNode, final OsmNode toNode, final double length) { double nofLanes; double laneCapacity; double freespeed; double freespeedFactor; boolean oneway; boolean onewayReverse = false; // load defaults String highway = way.tags.get(TAG_HIGHWAY); String railway = way.tags.get(TAG_RAILWAY); String ptway = way.tags.get(TAG_PT_WAYS); OsmHighwayDefaults defaults; if (highway != null) { defaults = this.highwayDefaults.get(highway); if (defaults == null) { this.unknownHighways.add(highway); return; } } else if (railway != null) { defaults = this.railwayDefaults.get(railway); if (defaults == null) { this.unknownRailways.add(railway); return; } } else if (ptway != null) { defaults = this.ptDefaults.get(ptway); if (defaults == null) { this.unknownPTs.add(ptway); return; } } else { this.unknownWays.add(way.tags.values().toString()); return; } nofLanes = defaults.lanes; laneCapacity = defaults.laneCapacity; freespeed = defaults.freespeed; freespeedFactor = defaults.freespeedFactor; oneway = defaults.oneway; // check if there are tags that overwrite defaults // - check tag "junction" if ("roundabout".equals(way.tags.get(TAG_JUNCTION))) { // if "junction" is not set in tags, get() returns null and equals() evaluates to false oneway = true; } // - check tag "oneway" String onewayTag = way.tags.get(TAG_ONEWAY); if (onewayTag != null) { if ("yes".equals(onewayTag)) { oneway = true; } else if ("true".equals(onewayTag)) { oneway = true; } else if ("1".equals(onewayTag)) { oneway = true; } else if ("-1".equals(onewayTag)) { onewayReverse = true; oneway = false; } else if ("no".equals(onewayTag)) { oneway = false; // may be used to overwrite defaults } } // - check tag "oneway" with trunks, primary and secondary roads // (if they are marked as such, the default number of lanes should be two instead of one) if (highway != null) { if (highway.equalsIgnoreCase("trunk") || highway.equalsIgnoreCase("primary") || highway.equalsIgnoreCase("secondary")) { if (oneway && nofLanes == 1.0) { nofLanes = 2.0; } } } // - ckeck tag "maxspeed" String maxspeedTag = way.tags.get(TAG_MAXSPEED); if (maxspeedTag != null) { try { freespeed = Double.parseDouble(maxspeedTag) / 3.6; // convert km/h to m/s } catch (NumberFormatException e) { if (!this.unknownMaxspeedTags.contains(maxspeedTag)) { this.unknownMaxspeedTags.add(maxspeedTag); log.warn("Could not parse maxspeed tag:" + e.getMessage() + ". Ignoring it."); } } } // - check tag "lanes" String lanesTag = way.tags.get(TAG_LANES); if (lanesTag != null) { try { double tmp = Double.parseDouble(lanesTag); if (tmp > 0) { nofLanes = tmp; } } catch (Exception e) { if (!this.unknownLanesTags.contains(lanesTag)) { this.unknownLanesTags.add(lanesTag); log.warn("Could not parse lanes tag:" + e.getMessage() + ". Ignoring it."); } } } // define the links' capacity and freespeed double capacity = nofLanes * laneCapacity; if (this.scaleMaxSpeed) { freespeed = freespeed * freespeedFactor; } // define modes allowed on link(s) // basic type: Set<String> modes = new HashSet<String>(); if (highway != null) { modes.add("car"); } if (railway != null) { modes.add(railway); } if (ptway != null) { modes.add(ptway); } if (modes.isEmpty()) { modes.add("unknownStreetType"); } // public transport: for (OsmRelation relation : this.relations.values()) { for (OsmParser.OsmRelationMember member : relation.members) { if ((member.type == OsmParser.OsmRelationMemberType.WAY) && (member.refId == way.id)) { String mode = relation.tags.get("name"); // mark that it is a link used by any pt: if (mode == null) { break; } else { modes.add("pt"); } if (mode.indexOf(":") > 0 && mode.indexOf(" ") > 0 && mode.indexOf(" ") < mode.indexOf(":")) { modes.add(mode.toLowerCase().substring(mode.indexOf(" "), mode.indexOf(":")).trim()); } // modes.add(relation.tags.get("name")); break; } } } // only create link, if both nodes were found, node could be null, since nodes outside a layer // were dropped Id<Node> fromId = Id.create(fromNode.id, Node.class); Id<Node> toId = Id.create(toNode.id, Node.class); if (network.getNodes().get(fromId) != null && network.getNodes().get(toId) != null) { String origId = Long.toString(way.id); if (!onewayReverse) { Link l = network .getFactory() .createLink( Id.create(this.id, Link.class), network.getNodes().get(fromId), network.getNodes().get(toId)); l.setLength(length); l.setFreespeed(freespeed); l.setCapacity(capacity); l.setNumberOfLanes(nofLanes); l.setAllowedModes(modes); if (l instanceof Link) { final String id1 = origId; NetworkUtils.setOrigId(((Link) l), id1); } network.addLink(l); this.id++; } if (!oneway) { Link l = network .getFactory() .createLink( Id.create(this.id, Link.class), network.getNodes().get(toId), network.getNodes().get(fromId)); l.setLength(length); l.setFreespeed(freespeed); l.setCapacity(capacity); l.setNumberOfLanes(nofLanes); l.setAllowedModes(modes); if (l instanceof Link) { final String id1 = origId; NetworkUtils.setOrigId(((Link) l), id1); } network.addLink(l); this.id++; } } }
public void run(NetworkImpl network) { log.info("running " + this.getClass().getName() + " module..."); for (Link l : network.getLinks().values()) { double cap = l.getCapacity(); // set standard caps if (cap < 1000) { l.setCapacity(500); } else if (cap < 2000) { l.setCapacity(1000); } else if (cap < 4000) { l.setCapacity(2000); } else if (cap < 6000) { l.setCapacity(4000); } else if (cap < 8000) { l.setCapacity(6000); } else if (cap < 10000) { l.setCapacity(8000); } else { l.setCapacity(10000); } // move links with teleatlas type 3 and higher to the next lower cap class cap = l.getCapacity(); String type = ((LinkImpl) l).getType(); if (type.startsWith("3-") || type.startsWith("4-") || type.startsWith("5-") || type.startsWith("6-") || type.startsWith("7-")) { if (cap == 500) {; } else if (cap == 1000) { l.setCapacity(500); } else if (cap == 2000) { l.setCapacity(1000); } else if (cap == 4000) { l.setCapacity(2000); } else if (cap == 6000) { l.setCapacity(4000); } else if (cap == 8000) { l.setCapacity(6000); } else if (cap == 10000) { l.setCapacity(8000); } else { throw new RuntimeException("capacity not known!"); } } } log.info("done. (" + this.getClass().getName() + ")"); }
private static int createNetwork(Scenario sc) { Network net = sc.getNetwork(); NetworkFactory fac = net.getFactory(); double length = 30; double width = 20; int id = 0; Node n0 = fac.createNode(Id.createNodeId(id++), CoordUtils.createCoord(0, 0)); Node n1 = fac.createNode(Id.createNodeId(id++), CoordUtils.createCoord(length, 0)); net.addNode(n0); net.addNode(n1); List<Node> someNodes = new ArrayList<>(); for (double y = -30; y <= 30; y += 10) { Node n = fac.createNode(Id.createNodeId(id++), CoordUtils.createCoord(length * 3, y)); net.addNode(n); someNodes.add(n); } Node n2 = fac.createNode(Id.createNodeId(id++), CoordUtils.createCoord(length * 4, 0)); Node n3 = fac.createNode(Id.createNodeId(id++), CoordUtils.createCoord(length * 5, 0)); net.addNode(n2); net.addNode(n3); id = 0; { Link l0 = fac.createLink(Id.createLinkId(id++), n0, n1); net.addLink(l0); l0.setCapacity(width); l0.setLength(length); Link l0Rev = fac.createLink(Id.createLinkId(id++), n1, n0); net.addLink(l0Rev); l0Rev.setCapacity(width); l0Rev.setLength(length); } int cnt = 0; for (Node n : someNodes) { { Link l0 = fac.createLink(Id.createLinkId(id++), n1, n); net.addLink(l0); l0.setCapacity(width / someNodes.size()); l0.setLength(length * 2); // ?check!! if (cnt++ % 2 != 0) { Link l0Rev = fac.createLink(Id.createLinkId(id++), n, n1); net.addLink(l0Rev); l0Rev.setCapacity(width / someNodes.size()); l0Rev.setLength(length * 2); } } { Link l0 = fac.createLink(Id.createLinkId(id++), n, n2); net.addLink(l0); l0.setCapacity(width / someNodes.size()); l0.setLength(length); // ?check!! Link l0Rev = fac.createLink(Id.createLinkId(id++), n2, n); net.addLink(l0Rev); l0Rev.setCapacity(width / someNodes.size()); l0Rev.setLength(length); } } int ret; { ret = id++; Link l0 = fac.createLink(Id.createLinkId(ret), n2, n3); net.addLink(l0); l0.setCapacity(width); l0.setLength(length); } { Link l0 = fac.createLink(Id.createLinkId(id++), n3, n2); net.addLink(l0); l0.setCapacity(width); l0.setLength(length); } Set<String> modes = new HashSet<>(); modes.add("walkct"); for (Link l : net.getLinks().values()) { l.setAllowedModes(modes); l.setFreespeed(20); } return ret; }