예제 #1
0
 public String allStopsWithCorrectLink() {
   for (StopTime stopTime : trip.getStopTimes().values()) {
     Stop stop = stops.get(stopTime.getStopId());
     Link link = network.getLinks().get(Id.create(stop.getLinkId(), Link.class));
     Point2D fromPoint =
         new Point2D(link.getFromNode().getCoord().getX(), link.getFromNode().getCoord().getY());
     Point2D toPoint =
         new Point2D(link.getToNode().getCoord().getX(), link.getToNode().getCoord().getY());
     Line2D linkLine = new Line2D(fromPoint, toPoint);
     Point2D point = new Point2D(stop.getPoint().getX(), stop.getPoint().getY());
     if (!linkLine.isNearestInside(point)) {
       int pos = getLinkPosition(link.getId().toString());
       if (pos == -1) return stopTime.getStopId();
       if (pos == links.size() - 1 || pos == 0) return "";
       Link link2 = links.get(pos + 1);
       fromPoint =
           new Point2D(
               link2.getFromNode().getCoord().getX(), link2.getFromNode().getCoord().getY());
       toPoint =
           new Point2D(link2.getToNode().getCoord().getX(), link2.getToNode().getCoord().getY());
       Line2D linkLine2 = new Line2D(fromPoint, toPoint);
       if (!(linkLine.getPointPosition(point).equals(Line2D.PointPosition.AFTER)
           && linkLine2.getPointPosition(point).equals(Line2D.PointPosition.BEFORE)))
         return stopTime.getStopId();
     }
   }
   return "";
 }
예제 #2
0
 public int isFirstLinkWithStop() {
   String firstStopLink =
       stops.get(trip.getStopTimes().values().iterator().next().getStopId()).getLinkId();
   if (!firstStopLink.equals(links.get(0).getId().toString()))
     return getLinkPosition(firstStopLink) - 1;
   return -1;
 }
예제 #3
0
 public int getIndexStop(String selectedStopId) {
   int i = 0;
   for (StopTime stopTime : trip.getStopTimes().values()) {
     if (stopTime.getStopId().equals(selectedStopId)) return i;
     i++;
   }
   return -1;
 }
예제 #4
0
 public String getStopId(int pos) {
   int i = 0;
   for (StopTime stopTime : trip.getStopTimes().values()) {
     if (i == pos) return stopTime.getStopId();
     i++;
   }
   return "";
 }
예제 #5
0
 public Collection<Link> getStopLinks() {
   Collection<Link> links = new ArrayList<Link>();
   for (StopTime stopTime : trip.getStopTimes().values()) {
     String linkId = stops.get(stopTime.getStopId()).getLinkId();
     if (linkId != null) links.add(network.getLinks().get(Id.create(linkId, Link.class)));
   }
   return links;
 }
예제 #6
0
 public String allStopsWithInRouteLink() {
   for (StopTime stopTime : trip.getStopTimes().values()) {
     Stop stop = stops.get(stopTime.getStopId());
     Link link = network.getLinks().get(Id.createLinkId(stop.getLinkId()));
     // Link link = network.getLinks().get(stop.getLinkId());
     if (!links.contains(link)) return stopTime.getStopId();
   }
   return "";
 }
예제 #7
0
 public String getIdNearestStop(double x, double y) {
   Coord coord = new Coord(x, y);
   String nearest = "";
   double nearestDistance = Double.POSITIVE_INFINITY;
   for (StopTime stopTime : trip.getStopTimes().values()) {
     double distance =
         CoordUtils.calcEuclideanDistance(stops.get(stopTime.getStopId()).getPoint(), coord);
     if (distance < nearestDistance) {
       nearest = stopTime.getStopId();
       nearestDistance = distance;
     }
   }
   return nearest;
 }
예제 #8
0
  public void setWithShapeCost() {
    withShapeCost = !withShapeCost;
    TravelDisutility travelMinCost = null;
    PreProcessEuclidean preProcessData = null;
    if (!withShapeCost || trip.getShape() == null) {
      travelMinCost =
          new TravelDisutility() {
            @Override
            public double getLinkTravelDisutility(
                final Link link, final double time, final Person person, final Vehicle vehicle) {
              return getLinkMinimumTravelDisutility(link);
            }

            @Override
            public double getLinkMinimumTravelDisutility(Link link) {
              return link.getLength() / link.getFreespeed();
            }
          };

    } else {
      travelMinCost =
          new TravelDisutility() {
            @Override
            public double getLinkTravelDisutility(
                final Link link, final double time, final Person person, final Vehicle vehicle) {
              return getLinkMinimumTravelDisutility(link);
            }

            @Override
            public double getLinkMinimumTravelDisutility(Link link) {
              return (link.getLength() / link.getFreespeed())
                  * Math.pow(trip.getShape().getDistance(link), 1);
            }
          };
    }
    preProcessData = new PreProcessEuclidean(travelMinCost);
    preProcessData.run(network);
    TravelTime timeFunction =
        new TravelTime() {

          @Override
          public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) {
            return link.getLength() / link.getFreespeed();
          }
        };
    leastCostPathCalculator = new AStarEuclidean(network, preProcessData, timeFunction);
  }
예제 #9
0
 public void initStops() {
   for (StopTime stopTime : trip.getStopTimes().values())
     stops.get(stopTime.getStopId()).setLinkId(null);
 }
예제 #10
0
 public String allStopsWithLink() {
   for (StopTime stopTime : trip.getStopTimes().values())
     if (stops.get(stopTime.getStopId()).getLinkId() == null) return stopTime.getStopId();
   return "";
 }
예제 #11
0
 public void calculatePath() {
   links.clear();
   Iterator<StopTime> prev = trip.getStopTimes().values().iterator(),
       next = trip.getStopTimes().values().iterator();
   List<Link> prevLL, nextLL;
   Link prevL = null, nextL = null;
   next.next();
   Stop prevStop = null, nextStop = null;
   if (next.hasNext()) {
     Path bestPath = null;
     prevStop = stops.get(prev.next().getStopId());
     nextStop = stops.get(next.next().getStopId());
     if (prevStop.getLinkId() != null) {
       prevLL = new ArrayList<Link>();
       prevLL.add(network.getLinks().get(Id.create(prevStop.getLinkId(), Link.class)));
     } else prevLL = getBestLinksMode(network, prevStop.getPoint(), trip.getShape());
     if (nextStop.getLinkId() != null) {
       nextLL = new ArrayList<Link>();
       nextLL.add(network.getLinks().get(Id.create(nextStop.getLinkId(), Link.class)));
     } else nextLL = getBestLinksMode(network, nextStop.getPoint(), trip.getShape());
     List<Tuple<Path, Link[]>> paths = new ArrayList<Tuple<Path, Link[]>>();
     for (int i = 0; i < prevLL.size(); i++)
       for (int j = 0; j < nextLL.size(); j++) {
         prevL = prevLL.get(i);
         nextL = nextLL.get(j);
         Path path;
         if (prevL == nextL)
           path = new Path(new ArrayList<Node>(), new ArrayList<Link>(), 0.0, 0.0);
         else {
           path =
               leastCostPathCalculator.calcLeastCostPath(
                   prevL.getToNode(), nextL.getFromNode(), 0, null, null);
           if (path == null)
             path = new Path(new ArrayList<Node>(), new ArrayList<Link>(), 0.0, 0.0);
           path.links.add(0, prevL);
         }
         path.links.add(nextL);
         paths.add(new Tuple<Path, Link[]>(path, new Link[] {prevL, nextLL.get(j)}));
       }
     double shortestDistance = Double.POSITIVE_INFINITY;
     for (Tuple<Path, Link[]> tuple : paths) {
       if (tuple.getFirst().links.size() > 0) {
         double distance =
             calculateDistance(tuple.getFirst(), prevStop.getPoint(), nextStop.getPoint());
         if (bestPath == null || distance <= shortestDistance) {
           shortestDistance = distance;
           bestPath = tuple.getFirst();
           prevStop.setLinkId(tuple.getSecond()[0].getId().toString());
           nextStop.setLinkId(tuple.getSecond()[1].getId().toString());
         }
       }
     }
     prevL = bestPath.links.get(bestPath.links.size() - 1);
     links.addAll(bestPath.links);
     prevStop = nextStop;
   }
   for (; next.hasNext(); ) {
     Path bestPath = null;
     nextStop = stops.get(next.next().getStopId());
     if (nextStop.getLinkId() != null) {
       nextL = network.getLinks().get(Id.create(nextStop.getLinkId(), Link.class));
       if (prevL.equals(nextL))
         bestPath = new Path(new ArrayList<Node>(), new ArrayList<Link>(), 0.0, 0.0);
       else {
         bestPath =
             leastCostPathCalculator.calcLeastCostPath(
                 prevL.getToNode(), nextL.getFromNode(), 0, null, null);
         if (bestPath == null)
           bestPath = new Path(new ArrayList<Node>(), new ArrayList<Link>(), 0.0, 0.0);
         else bestPath.links.add(0, prevL);
       }
       bestPath.links.add(nextL);
     } else {
       nextLL = getBestLinksMode(network, nextStop.getPoint(), trip.getShape());
       List<Tuple<Path, Link>> paths = new ArrayList<Tuple<Path, Link>>();
       for (int i = 0; i < nextLL.size(); i++) {
         nextL = nextLL.get(i);
         Path path;
         if (prevL.equals(nextL))
           path = new Path(new ArrayList<Node>(), new ArrayList<Link>(), 0.0, 0.0);
         else {
           path =
               leastCostPathCalculator.calcLeastCostPath(
                   prevL.getToNode(), nextL.getFromNode(), 0, null, null);
           if (path == null)
             path = new Path(new ArrayList<Node>(), new ArrayList<Link>(), 0.0, 0.0);
           else path.links.add(0, prevL);
         }
         path.links.add(nextL);
         paths.add(new Tuple<Path, Link>(path, nextL));
       }
       double shortestDistance = Double.POSITIVE_INFINITY;
       for (Tuple<Path, Link> tuple : paths) {
         double distance =
             calculateDistance(tuple.getFirst(), prevStop.getPoint(), nextStop.getPoint());
         if (bestPath == null || distance <= shortestDistance) {
           shortestDistance = distance;
           bestPath = tuple.getFirst();
           nextStop.setLinkId(tuple.getSecond().getId().toString());
         }
       }
     }
     prevL = bestPath.links.get(bestPath.links.size() - 1);
     bestPath.links.remove(0);
     links.addAll(bestPath.links);
     prevStop = nextStop;
   }
 }
예제 #12
0
 public Collection<Coord> getStopPoints() {
   Collection<Coord> points = new ArrayList<Coord>();
   for (StopTime stopTime : trip.getStopTimes().values())
     points.add(stops.get(stopTime.getStopId()).getPoint());
   return points;
 }
예제 #13
0
 public SortedMap<Integer, Coord> getShapePoints() {
   if (trip.getShape() != null) return trip.getShape().getPoints();
   else return new TreeMap<Integer, Coord>();
 }