Пример #1
0
 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();
 }
Пример #2
0
 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;
 }
Пример #3
0
  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()));
  }
Пример #4
0
  /**
   * 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);
  }
Пример #5
0
 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);
  }
Пример #7
0
  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++;
      }
    }
  }