use of org.neo4j.graphalgo.impl.util.DoubleAdder in project neo4j by neo4j.
the class ParallellCentralityCalculationTest method testPlusShape.
@Test
public void testPlusShape() {
// Make graph
graph.makeEdgeChain("a,b,c");
graph.makeEdgeChain("d,b,e");
SingleSourceShortestPath<Double> singleSourceShortestPath = getSingleSourceShortestPath();
ParallellCentralityCalculation<Double> pcc = new ParallellCentralityCalculation<Double>(singleSourceShortestPath, graph.getAllNodes());
BetweennessCentrality<Double> betweennessCentrality = new BetweennessCentrality<Double>(singleSourceShortestPath, graph.getAllNodes());
StressCentrality<Double> stressCentrality = new StressCentrality<Double>(singleSourceShortestPath, graph.getAllNodes());
ClosenessCentrality<Double> closenessCentrality = new ClosenessCentrality<Double>(singleSourceShortestPath, new DoubleAdder(), 0.0, graph.getAllNodes(), new CostDivider<Double>() {
public Double divideByCost(Double d, Double c) {
return d / c;
}
public Double divideCost(Double c, Double d) {
return c / d;
}
});
pcc.addCalculation(betweennessCentrality);
pcc.addCalculation(stressCentrality);
pcc.addCalculation(closenessCentrality);
pcc.calculate();
assertCentrality(betweennessCentrality, "a", 0.0);
assertCentrality(betweennessCentrality, "b", 6.0);
assertCentrality(betweennessCentrality, "c", 0.0);
assertCentrality(betweennessCentrality, "d", 0.0);
assertCentrality(betweennessCentrality, "e", 0.0);
assertCentrality(stressCentrality, "a", 0.0);
assertCentrality(stressCentrality, "b", 6.0);
assertCentrality(stressCentrality, "c", 0.0);
assertCentrality(stressCentrality, "d", 0.0);
assertCentrality(stressCentrality, "e", 0.0);
assertCentrality(closenessCentrality, "a", 1.0 / 7);
assertCentrality(closenessCentrality, "b", 1.0 / 4);
assertCentrality(closenessCentrality, "c", 1.0 / 7);
assertCentrality(closenessCentrality, "d", 1.0 / 7);
assertCentrality(closenessCentrality, "e", 1.0 / 7);
}
use of org.neo4j.graphalgo.impl.util.DoubleAdder 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.DoubleAdder 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.DoubleAdder in project graphdb by neo4j-attic.
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.DoubleAdder in project graphdb by neo4j-attic.
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);
}
Aggregations