Ejemplo n.º 1
0
  public static void CheckGraphLoader(String File, int Size) {
    int[][] ArrA = CreateArr(Size);

    GraphLoader Loader = new GraphLoader(File), Saver = new GraphLoader(File);

    Saver.setGraph(ArrA);
    Saver.Save();

    Loader.Load();

    if (CompareArray(ArrA, Loader.getGraph())) System.out.println("true");
    else System.out.println("false");
  }
Ejemplo n.º 2
0
  public OsmTrack findRoute(OsmPos startPos, OsmPos endPos, String startTime, int alternativeIdx)
      throws Exception {
    OsmTrack track = null;

    start = graph.matchNodeForPosition(startPos, rc.expctxWay);
    if (start == null) throw new IllegalArgumentException("unmatched start: " + startPos);
    end = graph.matchNodeForPosition(endPos, rc.expctxWay);
    if (end == null) throw new IllegalArgumentException("unmatched end: " + endPos);

    //		SimpleDateFormat df = new SimpleDateFormat( "dd.MM.yyyy-HH:mm" );
    //		time0 = df.parse(startTime).getTime();
    time0 = System.currentTimeMillis() + (long) (rc.starttimeoffset * 60000L);
    long minutes0 = (time0 + 59999L) / 60000L;
    time0 = minutes0 * 60000L;

    OffsetSet finishedOffsets = OffsetSet.emptySet();

    OsmLinkP startLink = new OsmLinkP(null, start);

    ScheduledTrip startTrip = new ScheduledTrip(OffsetSet.fullSet(), startLink, null, null);
    openSet.add(0, startTrip);
    for (; ; ) {
      if (re.isTerminated()) {
        throw new RuntimeException("operation terminated");
      }
      if (linksProcessed + linksReProcessed > 5000000) {
        throw new RuntimeException("5 Million links limit reached");
      }

      // get cheapest trip from heap
      ScheduledTrip trip = openSet.popLowestKeyValue();
      if (trip == null) {
        break;
      }
      OsmLinkP currentLink = trip.link;
      OsmNodeP currentNode = trip.getTargetNode();
      if (currentNode == null) {
        System.out.println("ups: " + trip);
        continue;
      }

      if (currentLink.isVirgin()) {
        linksProcessed++;
      } else {
        linksReProcessed++;
      }

      // check global closure
      OffsetSet offsets = finishedOffsets.filter(trip.offsets);
      if (offsets == null) continue;

      // check local closure for links:
      offsets =
          currentLink.filterAndClose(offsets, trip.arrival, currentLink instanceof ScheduledLink);
      if (offsets == null) continue;

      // check for arrival
      if (currentNode == end) {
        for (int offset = 0; offset < trip.offsets.size(); offset++) {
          if (trip.offsets.contains(offset)) {
            track = compileTrip(trip, offset);
            System.out.println("---- begin route ------ (cost " + track.cost + ")");
            for (String s : track.iternity) System.out.println(s);
            System.out.println("---- end route ------");
            break; // + plus more offsets..
          }
        }
        finishedOffsets = finishedOffsets.add(offsets);
        if (solutionCount++ >= alternativeIdx) return track;
      }
      for (OsmLinkP link = currentNode.getFirstLink();
          link != null;
          link = link.getNext(currentNode)) {
        addNextTripsForLink(trip, currentNode, currentLink, link, offsets, 0);
      }
    }
    return track;
  }