public void setUp() throws Exception {

    context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
    graph = new Graph();

    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(graph);
    graph.putService(
        CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));

    String[] stops = {
      "agency:A",
      "agency:B",
      "agency:C",
      "agency:D",
      "agency:E",
      "agency:entrance_a",
      "agency:entrance_b"
    };
    for (int i = 0; i < stops.length; ++i) {
      TransitStop stop = (TransitStop) (graph.getVertex(stops[i]));

      IntersectionVertex front =
          new IntersectionVertex(
              graph, "near_1_" + stop.getStopId(), stop.getX() + 0.0001, stop.getY() + 0.0001);
      IntersectionVertex back =
          new IntersectionVertex(
              graph, "near_2_" + stop.getStopId(), stop.getX() - 0.0001, stop.getY() - 0.0001);

      StreetEdge street1 =
          new StreetEdge(
              front,
              back,
              GeometryUtils.makeLineString(
                  stop.getX() + 0.0001,
                  stop.getY() + 0.0001,
                  stop.getX() - 0.0001,
                  stop.getY() - 0.0001),
              "street",
              100,
              StreetTraversalPermission.ALL,
              false);
      StreetEdge street2 =
          new StreetEdge(
              back,
              front,
              GeometryUtils.makeLineString(
                  stop.getX() - 0.0001,
                  stop.getY() - 0.0001,
                  stop.getX() + 0.0001,
                  stop.getY() + 0.0001),
              "street",
              100,
              StreetTraversalPermission.ALL,
              true);
    }

    NetworkLinker nl = new NetworkLinker(graph);
    nl.createLinkage();
  }
Exemplo n.º 2
0
  private void makeEdges(StreetVertex v1, StreetVertex v2, String name) {
    LineString geometry =
        GeometryUtils.makeLineString(
            v1.getCoordinate().x, v1.getCoordinate().y, v2.getCoordinate().x, v2.getCoordinate().y);
    double length =
        SphericalDistanceLibrary.getInstance().distance(v1.getCoordinate(), v2.getCoordinate());
    new PlainStreetEdge(v1, v2, geometry, name, length, StreetTraversalPermission.ALL, false);

    geometry =
        GeometryUtils.makeLineString(
            v2.getCoordinate().x, v2.getCoordinate().y, v1.getCoordinate().x, v1.getCoordinate().y);
    new PlainStreetEdge(v2, v1, geometry, name, length, StreetTraversalPermission.ALL, true);
  }
Exemplo n.º 3
0
  public void setUp() {
    graph = new Graph();
    // a 0.1 degree x 0.1 degree square
    top =
        new StreetVertex(
            "top",
            GeometryUtils.makeLineString(-74.01, 40.01, -74.0, 40.01),
            "top",
            1500,
            false,
            null);
    bottom =
        new StreetVertex(
            "bottom",
            GeometryUtils.makeLineString(-74.01, 40.0, -74.0, 40.0),
            "bottom",
            1500,
            false,
            null);
    left =
        new StreetVertex(
            "left",
            GeometryUtils.makeLineString(-74.01, 40.0, -74.01, 40.01),
            "left",
            1500,
            false,
            null);
    right =
        new StreetVertex(
            "right",
            GeometryUtils.makeLineString(-74.0, 40.0, -74.0, 40.01),
            "right",
            1500,
            false,
            null);

    StreetVertex topBack =
        new StreetVertex(
            "topBack",
            GeometryUtils.makeLineString(-74.0, 40.01, -74.01, 40.01),
            "topBack",
            1500,
            true,
            null);
    StreetVertex bottomBack =
        new StreetVertex(
            "bottomBack",
            GeometryUtils.makeLineString(-74.0, 40.0, -74.01, 40.0),
            "bottomBack",
            1500,
            true,
            null);
    leftBack =
        new StreetVertex(
            "leftBack",
            GeometryUtils.makeLineString(-74.01, 40.01, -74.01, 40.0),
            "leftBack",
            1500,
            true,
            null);
    rightBack =
        new StreetVertex(
            "rightBack",
            GeometryUtils.makeLineString(-74.0, 40.01, -74.0, 40.0),
            "rightBack",
            1500,
            true,
            null);

    right.setPermission(StreetTraversalPermission.PEDESTRIAN);

    graph.addVertex(top);
    graph.addVertex(bottom);
    graph.addVertex(left);
    graph.addVertex(right);

    graph.addVertex(topBack);
    graph.addVertex(bottomBack);
    graph.addVertex(leftBack);
    graph.addVertex(rightBack);

    EndpointVertex tlIn =
        (EndpointVertex) graph.addVertex(new EndpointVertex("tl in", -74.01, 40.01));
    EndpointVertex trIn =
        (EndpointVertex) graph.addVertex(new EndpointVertex("tr in", -74.0, 40.01));
    EndpointVertex blIn =
        (EndpointVertex) graph.addVertex(new EndpointVertex("bl in", -74.0, 40.0));
    EndpointVertex brIn =
        (EndpointVertex) graph.addVertex(new EndpointVertex("br in", -74.01, 40.0));

    Vertex tlOut = graph.addVertex(new EndpointVertex("tl out", -74.01, 40.01));
    trOut = graph.addVertex(new EndpointVertex("tr out", -74.0, 40.01));
    Vertex blOut = graph.addVertex(new EndpointVertex("bl out", -74.0, 40.0));
    brOut = graph.addVertex(new EndpointVertex("br out", -74.01, 40.0));

    graph.addEdge(new FreeEdge(tlOut, top));
    graph.addEdge(new FreeEdge(tlOut, leftBack));

    graph.addEdge(new FreeEdge(trOut, topBack));
    graph.addEdge(new FreeEdge(trOut, rightBack));

    graph.addEdge(new FreeEdge(blOut, bottom));
    graph.addEdge(new FreeEdge(blOut, left));

    graph.addEdge(new FreeEdge(brOut, bottomBack));
    graph.addEdge(new FreeEdge(brOut, right));

    graph.addEdge(new OutEdge(topBack, tlIn));
    graph.addEdge(new OutEdge(left, tlIn));

    graph.addEdge(new OutEdge(top, trIn));
    graph.addEdge(new OutEdge(right, trIn));

    graph.addEdge(new OutEdge(bottomBack, blIn));
    graph.addEdge(new OutEdge(leftBack, blIn));

    graph.addEdge(new OutEdge(bottom, brIn));
    graph.addEdge(new OutEdge(rightBack, brIn));

    graph.addEdge(new TurnEdge(top, rightBack));
    graph.addEdge(new TurnEdge(rightBack, bottomBack));
    graph.addEdge(new TurnEdge(bottomBack, left));
    graph.addEdge(new TurnEdge(left, top));

    graph.addEdge(new TurnEdge(topBack, leftBack));
    graph.addEdge(new TurnEdge(leftBack, bottom));
    graph.addEdge(new TurnEdge(bottom, right));
    graph.addEdge(new TurnEdge(right, topBack));

    station1 =
        new TransitStop(
            "transitVertex 1",
            -74.005,
            40.0099999,
            "transitVertex 1",
            new AgencyAndId("A", "fleem station"),
            null);
    graph.addVertex(station1);
    station2 =
        new TransitStop(
            "transitVertex 2",
            -74.002,
            40.0099999,
            "transitVertex 2",
            new AgencyAndId("A", "morx station"),
            null);
    graph.addVertex(station2);
  }