Example #1
0
  @Test
  public void TestTransitions() throws JSONException {
    Matcher filter = new Matcher(map, router, cost, spatial);
    filter.setMaxRadius(200);
    {
      MatcherSample sample1 = new MatcherSample(0, new Point(11.001, 48.001));
      MatcherSample sample2 = new MatcherSample(60000, new Point(11.019, 48.001));

      Set<MatcherCandidate> predecessors = new HashSet<MatcherCandidate>();
      Set<MatcherCandidate> candidates = new HashSet<MatcherCandidate>();

      for (Tuple<MatcherCandidate, Double> candidate : filter.candidates(sample1)) {
        predecessors.add(candidate.one());
      }

      for (Tuple<MatcherCandidate, Double> candidate : filter.candidates(sample2)) {
        candidates.add(candidate.one());
      }

      assertEquals(2, predecessors.size());
      assertEquals(4, candidates.size());

      Map<MatcherCandidate, Map<MatcherCandidate, Tuple<MatcherTransition, Double>>> transitions =
          filter.transitions(
              new Tuple<MatcherSample, Set<MatcherCandidate>>(sample1, predecessors),
              new Tuple<MatcherSample, Set<MatcherCandidate>>(sample2, candidates));

      assertEquals(2, transitions.size());

      for (Entry<MatcherCandidate, Map<MatcherCandidate, Tuple<MatcherTransition, Double>>> source :
          transitions.entrySet()) {
        assertEquals(4, source.getValue().size());

        for (Entry<MatcherCandidate, Tuple<MatcherTransition, Double>> target :
            source.getValue().entrySet()) {
          assertTransition(
              target.getValue(),
              new Tuple<MatcherCandidate, MatcherSample>(source.getKey(), sample1),
              new Tuple<MatcherCandidate, MatcherSample>(target.getKey(), sample2),
              filter.getLambda());
        }
      }
    }
    {
      MatcherSample sample1 = new MatcherSample(0, new Point(11.019, 48.001));
      MatcherSample sample2 = new MatcherSample(60000, new Point(11.001, 48.001));

      Set<MatcherCandidate> predecessors = new HashSet<MatcherCandidate>();
      Set<MatcherCandidate> candidates = new HashSet<MatcherCandidate>();

      for (Tuple<MatcherCandidate, Double> candidate : filter.candidates(sample1)) {
        predecessors.add(candidate.one());
      }

      for (Tuple<MatcherCandidate, Double> candidate : filter.candidates(sample2)) {
        candidates.add(candidate.one());
      }

      assertEquals(4, predecessors.size());
      assertEquals(2, candidates.size());

      Map<MatcherCandidate, Map<MatcherCandidate, Tuple<MatcherTransition, Double>>> transitions =
          filter.transitions(
              new Tuple<MatcherSample, Set<MatcherCandidate>>(sample1, predecessors),
              new Tuple<MatcherSample, Set<MatcherCandidate>>(sample2, candidates));

      assertEquals(4, transitions.size());

      for (Entry<MatcherCandidate, Map<MatcherCandidate, Tuple<MatcherTransition, Double>>> source :
          transitions.entrySet()) {
        if (source.getKey().point().edge().id() == 10) {
          assertEquals(0, source.getValue().size());
        } else {
          assertEquals(2, source.getValue().size());
        }

        for (Entry<MatcherCandidate, Tuple<MatcherTransition, Double>> target :
            source.getValue().entrySet()) {
          assertTransition(
              target.getValue(),
              new Tuple<MatcherCandidate, MatcherSample>(source.getKey(), sample1),
              new Tuple<MatcherCandidate, MatcherSample>(target.getKey(), sample2),
              filter.getLambda());
        }
      }
    }
  }