Пример #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();
 }
  private void run() {
    this.transitSchedule = new TransitScheduleFactoryImpl().createTransitSchedule();
    int stopsAdded = 0;

    for (Link link : this.net.getLinks().values()) {
      if (link.getAllowedModes().contains(TransportMode.car)) {
        stopsAdded += addStopOnLink(link);
      }
    }

    log.info("Added " + stopsAdded + " additional stops for paratransit services");
  }
Пример #3
0
 /**
  * Removes all TransportMode.pt flags from the network
  *
  * @param network The network to be processed.
  * @return
  */
 public static Network removeAllPtTagsFromNetwork(Network network) {
   log.info("Untagging pt network links");
   int removedTags = 0;
   for (Link link : network.getLinks().values()) {
     Set<String> allowedModes = new TreeSet<String>(link.getAllowedModes());
     if (allowedModes.remove(TransportMode.pt)) {
       removedTags++;
     }
     link.setAllowedModes(allowedModes);
   }
   log.info("Finished - Removed " + removedTags + " tags from links.");
   return network;
 }
Пример #4
0
  /**
   * Adding TransportMode.pt flags to all links referred by transit schedule
   *
   * @param transitSchedule The transit schedule.
   * @param network The network to be tagged.
   * @return
   */
  public static Network tagTransitLinksInNetwork(TransitSchedule transitSchedule, Network network) {

    log.info("Tagging pt network links");

    if (transitSchedule == null) {
      log.info("No transit schedule given. Returning unmodified network...");
      return network;
    }

    for (TransitStopFacility stopFacitlity : transitSchedule.getFacilities().values()) {
      Set<String> allowedModes =
          new TreeSet<String>(network.getLinks().get(stopFacitlity.getLinkId()).getAllowedModes());
      allowedModes.add(TransportMode.pt);
      network.getLinks().get(stopFacitlity.getLinkId()).setAllowedModes(allowedModes);
    }

    for (TransitLine transitLine : transitSchedule.getTransitLines().values()) {
      for (TransitRoute transitRoute : transitLine.getRoutes().values()) {
        NetworkRoute route = transitRoute.getRoute();

        Set<String> allowedModes;

        allowedModes =
            new TreeSet<String>(network.getLinks().get(route.getStartLinkId()).getAllowedModes());
        allowedModes.add(TransportMode.pt);
        network.getLinks().get(route.getStartLinkId()).setAllowedModes(allowedModes);

        for (Id linkId : route.getLinkIds()) {
          allowedModes = new TreeSet<String>(network.getLinks().get(linkId).getAllowedModes());
          allowedModes.add(TransportMode.pt);
          network.getLinks().get(linkId).setAllowedModes(allowedModes);
        }

        allowedModes =
            new TreeSet<String>(network.getLinks().get(route.getEndLinkId()).getAllowedModes());
        allowedModes.add(TransportMode.pt);
        network.getLinks().get(route.getEndLinkId()).setAllowedModes(allowedModes);
      }
    }

    int taggedLinks = 0;
    for (Link link : network.getLinks().values()) {
      if (link.getAllowedModes().contains(TransportMode.pt)) {
        taggedLinks++;
      }
    }

    log.info("Finished - " + taggedLinks + " links were tagged");

    return network;
  }
Пример #5
0
 /**
  * Add to any link that is passed by any route a "pt" in the modes, if it hasn't already one...
  */
 private void prepareNetwork() {
   Map<Id<Link>, ? extends Link> networkLinks = network.getLinks();
   Set<Id<Link>> transitLinks = new HashSet<>();
   for (TransitLine line : this.schedule.getTransitLines().values()) {
     for (TransitRoute transitRoute : line.getRoutes().values()) {
       NetworkRoute networkRoute = transitRoute.getRoute();
       transitLinks.add(networkRoute.getStartLinkId());
       for (Id<Link> linkId : transitRoute.getRoute().getLinkIds()) {
         transitLinks.add(linkId);
       }
       transitLinks.add(networkRoute.getEndLinkId());
     }
   }
   for (Id<Link> transitLinkId : transitLinks) {
     Link transitLink = networkLinks.get(transitLinkId);
     if (!transitLink.getAllowedModes().contains(TransportMode.pt)) {
       Set<String> modes = new HashSet<>();
       modes.addAll(transitLink.getAllowedModes());
       modes.add(TransportMode.pt);
       transitLink.setAllowedModes(modes);
     }
   }
 }
Пример #6
0
 private List<Link> getBestLinksMode(Network network, Coord coord, Shape shape) {
   List<Double> nearestDistances = new ArrayList<Double>();
   List<Link> nearestLinks = new ArrayList<Link>();
   for (double minDistance = this.minDistance;
       nearestLinks.size() < numCandidates;
       minDistance += MIN_DISTANCE_DELTA)
     for (Link link : network.getLinks().values())
       if (link.getAllowedModes().contains(mode)) {
         Point2D fromPoint =
             new Point2D(
                 link.getFromNode().getCoord().getX(), link.getFromNode().getCoord().getY());
         Point2D toPoint =
             new Point2D(link.getToNode().getCoord().getX(), link.getToNode().getCoord().getY());
         Vector2D linkVector = new Vector2D(fromPoint, toPoint);
         Line2D linkSegment = new Line2D(fromPoint, toPoint);
         if (!withInsideStops
             || linkSegment.isNearestInside(new Point2D(coord.getX(), coord.getY())))
           if (!withAngleShape
               || shape == null
               || linkVector.getAngleTo(shape.getVector(coord)) < Math.PI / 16) {
             double distance = ((LinkImpl) link).calcDistance(coord);
             if (distance < minDistance) {
               int i = 0;
               for (; i < nearestDistances.size() && distance < nearestDistances.get(i); i++) ;
               if (i > 0 || nearestLinks.size() < numCandidates) {
                 nearestDistances.add(i, distance);
                 nearestLinks.add(i, link);
                 if (nearestLinks.size() > numCandidates) {
                   nearestDistances.remove(0);
                   nearestLinks.remove(0);
                 }
               }
             }
           }
       }
   return nearestLinks;
 }
Пример #7
0
  public static void main(String[] args) {
    // Input file
    String networkFile = "D:/Workspace/container/demand/input/iv_counts/network.xml";

    // Get network, which is needed to calculate distances
    Config config = ConfigUtils.createConfig();
    Scenario scenario = ScenarioUtils.createScenario(config);
    MatsimNetworkReader networkReader = new MatsimNetworkReader(scenario);
    networkReader.readFile(networkFile);
    Network network = scenario.getNetwork();

    // Create needed objects
    int numberOfNodes = 0;
    int numberOfLinks = 0;

    Map<Double, Integer> capacityMap = new HashMap<Double, Integer>();

    int capacity0To1000 = 0;
    int capacity1000To2000 = 0;
    int capacity2000To3000 = 0;
    int capacity3000To4000 = 0;
    int capacity4000To5000 = 0;
    int capacity5000ToInf = 0;

    Map<Double, Integer> freeSpeedMap = new HashMap<Double, Integer>();
    Map<Double, Integer> numberOfLanesMap = new HashMap<Double, Integer>();

    int linksWithMoreThanOneMode = 0;

    double maxLength = Integer.MIN_VALUE;
    double minLength = Integer.MAX_VALUE;

    // Do calculations
    for (Node node : network.getNodes().values()) {
      numberOfNodes++;
    }

    for (Link link : network.getLinks().values()) {
      numberOfLinks++;

      double capacity = link.getCapacity();
      if (!capacityMap.containsKey(capacity)) {
        capacityMap.put(capacity, 1);
      } else {
        int quantityCapacity = capacityMap.get(capacity);
        capacityMap.put(capacity, quantityCapacity + 1);
      }
      if (capacity < 1000) {
        capacity0To1000++;
      } else if (capacity >= 1000 && capacity < 2000) {
        capacity1000To2000++;
      } else if (capacity >= 2000 && capacity < 3000) {
        capacity2000To3000++;
      } else if (capacity >= 3000 && capacity < 4000) {
        capacity3000To4000++;
      } else if (capacity >= 4000 && capacity < 5000) {
        capacity4000To5000++;
      } else if (capacity >= 5000) {
        capacity5000ToInf++;
      } else {
        System.err.println("Error!");
      }

      double freeSpeed = link.getFreespeed();
      if (!freeSpeedMap.containsKey(freeSpeed)) {
        freeSpeedMap.put(freeSpeed, 1);
      } else {
        int quantityFreeSpeed = freeSpeedMap.get(freeSpeed);
        freeSpeedMap.put(freeSpeed, quantityFreeSpeed + 1);
      }

      double numberOfLanes = link.getNumberOfLanes();
      if (!numberOfLanesMap.containsKey(numberOfLanes)) {
        numberOfLanesMap.put(numberOfLanes, 1);
      } else {
        int quantityNumberOfLanes = numberOfLanesMap.get(numberOfLanes);
        numberOfLanesMap.put(numberOfLanes, quantityNumberOfLanes + 1);
      }

      if (link.getAllowedModes().size() > 1) {
        linksWithMoreThanOneMode++;
      }

      double length = link.getLength();
      if (length > maxLength) {
        maxLength = length;
      }
      if (length < minLength) {
        minLength = length;
      }
    }

    // Write information to console
    System.out.println("Number of Nodes: " + numberOfNodes);
    System.out.println("Number of Links: " + numberOfLinks);

    for (Double capacity : capacityMap.keySet()) {
      System.out.println(capacityMap.get(capacity) + " links have a capacity of " + capacity + ".");
    }

    System.out.println(capacity0To1000 + " links have a capacity of less than 1000.");
    System.out.println(
        capacity1000To2000 + " links have a capacity of at least 1000 and less than 2000.");
    System.out.println(
        capacity2000To3000 + " links have a capacity of at least 2000 and less than 3000.");
    System.out.println(
        capacity3000To4000 + " links have a capacity of at least 3000 and less than 4000.");
    System.out.println(
        capacity4000To5000 + " links have a capacity of at least 4000 and less than 5000.");
    System.out.println(capacity5000ToInf + " links have a capacity of at least 5000.");

    for (Double freeSpeed : freeSpeedMap.keySet()) {
      System.out.println(
          freeSpeedMap.get(freeSpeed)
              + " links have a free speed of "
              + freeSpeed
              + " / "
              + freeSpeed * 3.6
              + ".");
    }

    for (Double numberOfLanes : numberOfLanesMap.keySet()) {
      System.out.println(
          numberOfLanesMap.get(numberOfLanes) + " links have " + numberOfLanes + " lanes.");
    }

    System.out.println(linksWithMoreThanOneMode + " links allow more than one mode.");

    System.out.println("Maximum link length is: " + maxLength);
    System.out.println("Minimum link length is: " + minLength);
  }
Пример #8
0
  public QSimDensityDrawer(Scenario sc) {
    for (Link l : sc.getNetwork().getLinks().values()) {
      if (l.getId().toString().contains("jps")
          || l.getId().toString().contains("el")
          || l.getAllowedModes().contains("walk2d")
          || l.getCapacity() >= 100000
          || l.getFreespeed() > 100
          || l.getId().toString().contains("el")) {
        continue;
      }

      float width = (float) (l.getCapacity() / sc.getNetwork().getCapacityPeriod() / 1.3);

      boolean isCar = false;
      if (l.getFreespeed() > 1.35) {
        width = (float) (l.getNumberOfLanes() * 3.5);
        isCar = true;
      } else {
        width = (float) (width);
      }

      double dx = l.getToNode().getCoord().getX() - l.getFromNode().getCoord().getX();
      double dy = l.getToNode().getCoord().getY() - l.getFromNode().getCoord().getY();
      double length = Math.sqrt(dx * dx + dy * dy);
      dx /= length;
      dy /= length;
      LinkInfo info = new LinkInfo();

      info.id = l.getId();
      info.cap =
          (l.getLength() / ((NetworkImpl) sc.getNetwork()).getEffectiveCellSize())
              * l.getNumberOfLanes();

      double x0 = l.getFromNode().getCoord().getX();
      double y0 = l.getFromNode().getCoord().getY();

      double x1 = l.getToNode().getCoord().getX();
      double y1 = l.getToNode().getCoord().getY();

      x0 += dy * width / 2;
      x1 += dy * width / 2;
      y0 -= dx * width / 2;
      y1 -= dx * width / 2;

      info.width = width;
      info.x0 = x0;
      info.x1 = x1;
      info.y0 = y0;
      info.y1 = y1;

      double tan = dx / dy;
      double atan = Math.atan(tan);
      if (atan > 0) {
        atan -= Math.PI / 2;
      } else {
        atan += Math.PI / 2;
      }

      double offsetX = dy * .075;
      double offsetY = -dx * .075;
      if (dx > 0) {
        offsetX *= -1;
        offsetY *= -1;
      }

      info.tx = (x0 + x1) / 2 + offsetX;
      info.ty = (y0 + y1) / 2 + offsetY;
      info.text = "0";
      info.atan = atan;
      info.isCar = isCar;
      if (isCar) {
        info.cap = l.getLength() / 7.5 * l.getNumberOfLanes();
      }

      this.links.add(info);
      this.map.put(l.getId(), info);
    }
  }