use of org.neo4j.graphalgo.impl.util.DoubleComparator in project neo4j by neo4j.
the class NetworkDiameterTest method testBox.
@Test
public void testBox() {
graph.makeEdgeChain("a,b,c,d,a");
NetworkDiameter<Double> diameter = new NetworkDiameter<Double>(getSingleSourceShortestPath(), 0.0, graph.getAllNodes(), new DoubleComparator());
assertTrue(diameter.getCentrality(null) == 2.0);
}
use of org.neo4j.graphalgo.impl.util.DoubleComparator in project neo4j by neo4j.
the class DijkstraMultiplePathsTest method test8.
@Test
public void test8() {
Relationship edgeAB = graph.makeEdge("a", "b");
Relationship edgeBC = graph.makeEdge("b", "c");
Relationship edgeCD = graph.makeEdge("c", "d");
Relationship edgeDE = graph.makeEdge("d", "e");
Relationship edgeAB2 = graph.makeEdge("a", "b2");
Relationship edgeB2C = graph.makeEdge("b2", "c");
Relationship edgeCD2 = graph.makeEdge("c", "d2");
Relationship edgeD2E = graph.makeEdge("d2", "e");
Dijkstra<Double> dijkstra = new Dijkstra<Double>(0.0, graph.getNode("a"), graph.getNode("e"), new CostEvaluator<Double>() {
public Double getCost(Relationship relationship, Direction direction) {
return 1.0;
}
}, new DoubleAdder(), new DoubleComparator(), Direction.OUTGOING, MyRelTypes.R1);
// path discovery flags
boolean pathBD = false;
boolean pathB2D = false;
boolean pathBD2 = false;
boolean pathB2D2 = false;
List<List<Relationship>> paths = dijkstra.getPathsAsRelationships();
assertTrue(paths.size() == 4);
for (List<Relationship> path : paths) {
assertTrue(path.size() == 4);
// first choice
if (path.get(0).equals(edgeAB)) {
assertTrue(path.get(1).equals(edgeBC));
} else {
assertTrue(path.get(0).equals(edgeAB2));
assertTrue(path.get(1).equals(edgeB2C));
}
// second choice
if (path.get(2).equals(edgeCD)) {
assertTrue(path.get(3).equals(edgeDE));
} else {
assertTrue(path.get(2).equals(edgeCD2));
assertTrue(path.get(3).equals(edgeD2E));
}
// combinations
if (path.get(0).equals(edgeAB)) {
if (path.get(2).equals(edgeCD)) {
pathBD = true;
} else if (path.get(2).equals(edgeCD2)) {
pathBD2 = true;
}
} else {
if (path.get(2).equals(edgeCD)) {
pathB2D = true;
} else if (path.get(2).equals(edgeCD2)) {
pathB2D2 = true;
}
}
}
assertTrue(pathBD);
assertTrue(pathB2D);
assertTrue(pathBD2);
assertTrue(pathB2D2);
}
use of org.neo4j.graphalgo.impl.util.DoubleComparator in project neo4j by neo4j.
the class DijkstraMultiplePathsTest method test7.
@Test
public void test7() {
Relationship edgeAB = graph.makeEdge("a", "b");
Relationship edgeBC = graph.makeEdge("b", "c");
Relationship edgeCD = graph.makeEdge("c", "d");
Relationship edgeDE = graph.makeEdge("d", "e");
Relationship edgeAB2 = graph.makeEdge("a", "b2");
Relationship edgeB2C = graph.makeEdge("b2", "c");
Relationship edgeCD2 = graph.makeEdge("c", "d2");
Relationship edgeD2E = graph.makeEdge("d2", "e");
Dijkstra<Double> dijkstra = new Dijkstra<Double>(0.0, graph.getNode("a"), graph.getNode("e"), new CostEvaluator<Double>() {
public Double getCost(Relationship relationship, Direction direction) {
return 1.0;
}
}, new DoubleAdder(), new DoubleComparator(), Direction.OUTGOING, MyRelTypes.R1);
// path discovery flags
boolean pathBD = false;
boolean pathB2D = false;
boolean pathBD2 = false;
boolean pathB2D2 = false;
List<List<PropertyContainer>> paths = dijkstra.getPaths();
assertTrue(paths.size() == 4);
for (List<PropertyContainer> path : paths) {
assertTrue(path.size() == 9);
assertTrue(path.get(0).equals(graph.getNode("a")));
assertTrue(path.get(4).equals(graph.getNode("c")));
assertTrue(path.get(8).equals(graph.getNode("e")));
// first choice
if (path.get(2).equals(graph.getNode("b"))) {
assertTrue(path.get(1).equals(edgeAB));
assertTrue(path.get(3).equals(edgeBC));
} else {
assertTrue(path.get(1).equals(edgeAB2));
assertTrue(path.get(2).equals(graph.getNode("b2")));
assertTrue(path.get(3).equals(edgeB2C));
}
// second choice
if (path.get(6).equals(graph.getNode("d"))) {
assertTrue(path.get(5).equals(edgeCD));
assertTrue(path.get(7).equals(edgeDE));
} else {
assertTrue(path.get(5).equals(edgeCD2));
assertTrue(path.get(6).equals(graph.getNode("d2")));
assertTrue(path.get(7).equals(edgeD2E));
}
// combinations
if (path.get(2).equals(graph.getNode("b"))) {
if (path.get(6).equals(graph.getNode("d"))) {
pathBD = true;
} else if (path.get(6).equals(graph.getNode("d2"))) {
pathBD2 = true;
}
} else {
if (path.get(6).equals(graph.getNode("d"))) {
pathB2D = true;
} else if (path.get(6).equals(graph.getNode("d2"))) {
pathB2D2 = true;
}
}
}
assertTrue(pathBD);
assertTrue(pathB2D);
assertTrue(pathBD2);
assertTrue(pathB2D2);
}
use of org.neo4j.graphalgo.impl.util.DoubleComparator in project neo4j by neo4j.
the class NetworkDiameterTest method testChain.
@Test
public void testChain() {
graph.makeEdgeChain("a,b,c,d,e");
NetworkDiameter<Double> diameter = new NetworkDiameter<Double>(getSingleSourceShortestPath(), 0.0, graph.getAllNodes(), new DoubleComparator());
assertTrue(diameter.getCentrality(null) == 4.0);
}
use of org.neo4j.graphalgo.impl.util.DoubleComparator in project neo4j by neo4j.
the class NetworkDiameterTest method testPlusShape.
@Test
public void testPlusShape() {
graph.makeEdgeChain("a,b,c");
graph.makeEdgeChain("d,b,e");
NetworkDiameter<Double> diameter = new NetworkDiameter<Double>(getSingleSourceShortestPath(), 0.0, graph.getAllNodes(), new DoubleComparator());
assertTrue(diameter.getCentrality(null) == 2.0);
}
Aggregations