AbsoluteOneCenter { public PointOnEdge<V, E> getCenter() { LocalCenter<V, E> localCenter = new LocalCenter<V, E>(d_graph, d_edgeLength, d_distance, d_comparator); Center<V, E> c = null; for (E e : d_graph.getEdges()) { Center<V, E> lc = localCenter.transform(e); if (c == null || lc.getRadius() < c.getRadius() || (lc.getRadius() == c.getRadius() && compareEdge(lc.getEdge(), c.getEdge()) < 0)) { c = lc; } } return c; } AbsoluteOneCenter(final UndirectedGraph<V, E> graph);  AbsoluteOneCenter(final UndirectedGraph<V, E> graph, final Comparator<V> comparator);  AbsoluteOneCenter(final UndirectedGraph<V, E> graph, final Transformer<E, Number> edgeLength);  AbsoluteOneCenter(final UndirectedGraph<V, E> graph, final Transformer<E, Number> edgeLength, final Comparator<V> comparator);  AbsoluteOneCenter(final UndirectedGraph<V, E> graph, final Transformer<E, Number> edgeLength, final Distance<V> distance);  AbsoluteOneCenter(final UndirectedGraph<V, E> graph, final Transformer<E, Number> edgeLength, final Distance<V> distance, final Comparator<V> comparator); PointOnEdge<V, E> getCenter();  }
@Test public void testSimpleVertexCenter() { final UndirectedGraph<String, Integer> g = new UndirectedSparseGraph<String, Integer>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); g.addVertex("D"); g.addEdge(1, "A", "B"); g.addEdge(2, "B", "C"); g.addEdge(3, "B", "D"); final AbsoluteOneCenter<String, Integer> absoluteOneCenter = new AbsoluteOneCenter<String, Integer>(g); final PointOnEdge<String, Integer> center = absoluteOneCenter.getCenter(); assertTrue(center.getVertex0().equals("B") || center.getVertex1().equals("B")); if (center.getVertex0().equals("B")) { assertEquals(0.0, center.getDistance(), EPSILON); } else { assertEquals(1.0, center.getDistance(), EPSILON); } }
@Test public void testSimplePointCenter() { final UndirectedGraph<String, Integer> g = new UndirectedSparseGraph<String, Integer>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); g.addVertex("D"); g.addEdge(1, "A", "B"); g.addEdge(2, "B", "C"); g.addEdge(3, "C", "D"); final AbsoluteOneCenter<String, Integer> absoluteOneCenter = new AbsoluteOneCenter<String, Integer>(g); final PointOnEdge<String, Integer> center = absoluteOneCenter.getCenter(); assertEquals(2, center.getEdge().intValue()); assertEquals("B", center.getVertex0()); assertEquals("C", center.getVertex1()); assertEquals(0.5, center.getDistance(), EPSILON); }
@Test public void testCenterWithCycles() { final UndirectedGraph<String, Integer> g = new UndirectedSparseGraph<String, Integer>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); g.addVertex("D"); g.addVertex("E"); g.addEdge(1, "A", "B"); g.addEdge(2, "A", "C"); g.addEdge(3, "A", "D"); g.addEdge(4, "A", "E"); g.addEdge(5, "B", "C"); g.addEdge(6, "C", "D"); g.addEdge(7, "D", "E"); final AbsoluteOneCenter<String, Integer> absoluteOneCenter = new AbsoluteOneCenter<String, Integer>(g); final PointOnEdge<String, Integer> center = absoluteOneCenter.getCenter(); assertTrue(center.getVertex0().equals("A") || center.getVertex1().equals("A")); if (center.getVertex0().equals("A")) { assertEquals(0.0, center.getDistance(), EPSILON); } else { assertEquals(1.0, center.getDistance(), EPSILON); } }