@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()); } } } }
@Test public void TestCandidates() throws JSONException { Matcher filter = new Matcher(map, router, cost, spatial); { filter.setMaxRadius(100); Point sample = new Point(11.001, 48.001); Set<Tuple<MatcherCandidate, Double>> candidates = filter.candidates(new MatcherSample(0, sample)); assertEquals(0, candidates.size()); } { double radius = 200; filter.setMaxRadius(radius); Point sample = new Point(11.001, 48.001); Set<Tuple<MatcherCandidate, Double>> candidates = filter.candidates(new MatcherSample(0, sample)); Set<Long> refset = new HashSet<Long>(Arrays.asList(0L, 1L)); Set<Long> set = new HashSet<Long>(); for (Tuple<MatcherCandidate, Double> candidate : candidates) { assertTrue(refset.contains(candidate.one().point().edge().id())); assertCandidate(candidate, sample); set.add(candidate.one().point().edge().id()); } assertEquals(refset.size(), candidates.size()); assertTrue(set.containsAll(refset)); } { double radius = 200; filter.setMaxRadius(radius); Point sample = new Point(11.010, 48.000); Set<Tuple<MatcherCandidate, Double>> candidates = filter.candidates(new MatcherSample(0, sample)); Set<Long> refset = new HashSet<Long>(Arrays.asList(0L, 3L)); Set<Long> set = new HashSet<Long>(); for (Tuple<MatcherCandidate, Double> candidate : candidates) { assertTrue( Long.toString(candidate.one().point().edge().id()), refset.contains(candidate.one().point().edge().id())); assertCandidate(candidate, sample); set.add(candidate.one().point().edge().id()); } assertEquals(refset.size(), candidates.size()); assertTrue(set.containsAll(refset)); } { double radius = 200; filter.setMaxRadius(radius); Point sample = new Point(11.011, 48.001); Set<Tuple<MatcherCandidate, Double>> candidates = filter.candidates(new MatcherSample(0, sample)); Set<Long> refset = new HashSet<Long>(Arrays.asList(0L, 2L, 3L)); Set<Long> set = new HashSet<Long>(); for (Tuple<MatcherCandidate, Double> candidate : candidates) { assertTrue( Long.toString(candidate.one().point().edge().id()), refset.contains(candidate.one().point().edge().id())); assertCandidate(candidate, sample); set.add(candidate.one().point().edge().id()); } assertEquals(refset.size(), candidates.size()); assertTrue(set.containsAll(refset)); } { double radius = 300; filter.setMaxRadius(radius); Point sample = new Point(11.011, 48.001); Set<Tuple<MatcherCandidate, Double>> candidates = filter.candidates(new MatcherSample(0, sample)); Set<Long> refset = new HashSet<Long>(Arrays.asList(0L, 2L, 3L, 8L)); Set<Long> set = new HashSet<Long>(); for (Tuple<MatcherCandidate, Double> candidate : candidates) { assertTrue( Long.toString(candidate.one().point().edge().id()), refset.contains(candidate.one().point().edge().id())); assertCandidate(candidate, sample); set.add(candidate.one().point().edge().id()); } assertEquals(refset.size(), candidates.size()); assertTrue(set.containsAll(refset)); } { double radius = 200; filter.setMaxRadius(radius); Point sample = new Point(11.019, 48.001); Set<Tuple<MatcherCandidate, Double>> candidates = filter.candidates(new MatcherSample(0, sample)); Set<Long> refset = new HashSet<Long>(Arrays.asList(2L, 3L, 5L, 10L)); Set<Long> set = new HashSet<Long>(); for (Tuple<MatcherCandidate, Double> candidate : candidates) { assertTrue( Long.toString(candidate.one().point().edge().id()), refset.contains(candidate.one().point().edge().id())); assertCandidate(candidate, sample); set.add(candidate.one().point().edge().id()); } assertEquals(refset.size(), candidates.size()); assertTrue(set.containsAll(refset)); } }