use of org.neo4j.graphdb.Direction in project graphdb by neo4j-attic.
the class OldTraverserWrapper method toExpander.
private static RelationshipExpander toExpander(Object[] relationshipTypesAndDirections) {
Stack<Object[]> entries = new Stack<Object[]>();
for (int i = 0; i < relationshipTypesAndDirections.length; i += 2) {
Object relType = relationshipTypesAndDirections[i];
if (relType == null) {
throw new IllegalArgumentException("Null relationship type at " + i);
}
if (!(relType instanceof RelationshipType)) {
throw new IllegalArgumentException("Expected RelationshipType at var args pos " + i + ", found " + relType);
}
Object direction = relationshipTypesAndDirections[i + 1];
if (direction == null) {
throw new IllegalArgumentException("Null direction at " + (i + 1));
}
if (!(direction instanceof Direction)) {
throw new IllegalArgumentException("Expected Direction at var args pos " + (i + 1) + ", found " + direction);
}
entries.push(new Object[] { relType, direction });
}
OrderedByTypeExpander expander = new OrderedByTypeExpander();
while (!entries.isEmpty()) {
Object[] entry = entries.pop();
expander = (OrderedByTypeExpander) expander.add((RelationshipType) entry[0], (Direction) entry[1]);
}
return expander;
}
use of org.neo4j.graphdb.Direction in project neo4j-mobile-android by neo4j-contrib.
the class OldTraverserWrapper method toExpander.
private static RelationshipExpander toExpander(Object[] relationshipTypesAndDirections) {
Stack<Object[]> entries = new Stack<Object[]>();
for (int i = 0; i < relationshipTypesAndDirections.length; i += 2) {
Object relType = relationshipTypesAndDirections[i];
if (relType == null) {
throw new IllegalArgumentException("Null relationship type at " + i);
}
if (!(relType instanceof RelationshipType)) {
throw new IllegalArgumentException("Expected RelationshipType at var args pos " + i + ", found " + relType);
}
Object direction = relationshipTypesAndDirections[i + 1];
if (direction == null) {
throw new IllegalArgumentException("Null direction at " + (i + 1));
}
if (!(direction instanceof Direction)) {
throw new IllegalArgumentException("Expected Direction at var args pos " + (i + 1) + ", found " + direction);
}
entries.push(new Object[] { relType, direction });
}
OrderedByTypeExpander expander = new OrderedByTypeExpander();
while (!entries.isEmpty()) {
Object[] entry = entries.pop();
expander = (OrderedByTypeExpander) expander.add((RelationshipType) entry[0], (Direction) entry[1]);
}
return expander;
}
use of org.neo4j.graphdb.Direction 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.graphdb.Direction 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);
}
use of org.neo4j.graphdb.Direction in project graphdb by neo4j-attic.
the class EigenvectorCentralityTest method testDirection.
/**
* Same as above, but inverted direction.
*/
@Test
public void testDirection() {
graph.makeEdgeChain("d,c,b,a");
graph.makeEdges("a,b,a,c");
EigenvectorCentrality eigenvectorCentrality = getEigenvectorCentrality(Direction.INCOMING, new CostEvaluator<Double>() {
public Double getCost(Relationship relationship, Direction direction) {
return 1.0;
}
}, graph.getAllNodes(), graph.getAllEdges(), 0.01);
// eigenvectorCentrality.setMaxIterations( 100 );
assertApproximateCentrality(eigenvectorCentrality, "a", 0.693, 0.01);
assertApproximateCentrality(eigenvectorCentrality, "b", 0.523, 0.01);
assertApproximateCentrality(eigenvectorCentrality, "c", 0.395, 0.01);
assertApproximateCentrality(eigenvectorCentrality, "d", 0.298, 0.01);
}
Aggregations