Search in sources :

Example 26 with Direction

use of org.neo4j.graphdb.Direction in project neo4j by neo4j.

the class ParallelBatchImporterTest method assertDegrees.

private void assertDegrees(Node node) {
    for (RelationshipType type : node.getRelationshipTypes()) {
        for (Direction direction : Direction.values()) {
            long degree = node.getDegree(type, direction);
            long actualDegree = count(node.getRelationships(type, direction));
            assertEquals(actualDegree, degree);
        }
    }
}
Also used : RelationshipType(org.neo4j.graphdb.RelationshipType) Direction(org.neo4j.graphdb.Direction)

Example 27 with Direction

use of org.neo4j.graphdb.Direction in project neo4j by neo4j.

the class CompiledExpandUtils method connectingRelationships.

public static RelationshipIterator connectingRelationships(ReadOperations readOperations, long fromNode, Direction direction, long toNode, int[] relTypes) throws EntityNotFoundException {
    int fromDegree = calculateTotalDegree(readOperations, fromNode, direction, relTypes);
    if (fromDegree == 0) {
        return RelationshipIterator.EMPTY;
    }
    int toDegree = calculateTotalDegree(readOperations, toNode, direction.reverse(), relTypes);
    if (toDegree == 0) {
        return RelationshipIterator.EMPTY;
    }
    long startNode;
    long endNode;
    Direction relDirection;
    if (fromDegree < toDegree) {
        startNode = fromNode;
        endNode = toNode;
        relDirection = direction;
    } else {
        startNode = toNode;
        endNode = fromNode;
        relDirection = direction.reverse();
    }
    RelationshipIterator allRelationships = readOperations.nodeGetRelationships(startNode, relDirection, relTypes);
    return connectingRelationshipsIterator(allRelationships, startNode, endNode);
}
Also used : RelationshipIterator(org.neo4j.kernel.impl.api.store.RelationshipIterator) Direction(org.neo4j.graphdb.Direction)

Example 28 with Direction

use of org.neo4j.graphdb.Direction in project neo4j by neo4j.

the class EigenvectorCentralityTest method shouldHandleFirstNodeBeingOrphan.

@Test
public void shouldHandleFirstNodeBeingOrphan() {
    /*
         * Layout
         *
         * (o)
         *     ___________  _____
         *   v            \v     \
         * (a) -> (b) -> (c) -> (d)
         */
    // Degree 0
    Node orphan = graph.makeNode("o");
    Node a = graph.makeNode("a");
    Node b = graph.makeNode("b");
    Node c = graph.makeNode("c");
    Node d = graph.makeNode("d");
    Set<Node> nodeSet = new HashSet<>();
    nodeSet.add(orphan);
    nodeSet.add(a);
    nodeSet.add(b);
    nodeSet.add(c);
    nodeSet.add(d);
    Set<Relationship> relSet = new HashSet<>();
    relSet.add(graph.makeEdge("a", "b"));
    relSet.add(graph.makeEdge("b", "c"));
    relSet.add(graph.makeEdge("c", "d"));
    relSet.add(graph.makeEdge("d", "c"));
    relSet.add(graph.makeEdge("c", "a"));
    EigenvectorCentrality eigenvectorCentrality = getEigenvectorCentrality(Direction.OUTGOING, new CostEvaluator<Double>() {

        @Override
        public Double getCost(Relationship relationship, Direction direction) {
            return 1d;
        }
    }, nodeSet, relSet, 0.01);
    assertApproximateCentrality(eigenvectorCentrality, "o", 0d, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "a", 0.481, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "b", 0.363, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "c", 0.637, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "d", 0.481, 0.02);
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) EigenvectorCentrality(org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality) Direction(org.neo4j.graphdb.Direction) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 29 with Direction

use of org.neo4j.graphdb.Direction in project neo4j by neo4j.

the class EigenvectorCentralityTest method shouldHandleFirstNodeBeingOrphanInRelationshipSet.

@Test
public void shouldHandleFirstNodeBeingOrphanInRelationshipSet() {
    /*
         * Layout
         *
         * (o)
         *  ^
         *  |
         *  x
         *  |  ___________  _____
         *  |v            \v     \
         * (a) -> (b) -> (c) -> (d)
         */
    Node orphan = graph.makeNode("o");
    Node a = graph.makeNode("a");
    Node b = graph.makeNode("b");
    Node c = graph.makeNode("c");
    Node d = graph.makeNode("d");
    Set<Node> nodeSet = new HashSet<>();
    nodeSet.add(orphan);
    nodeSet.add(a);
    nodeSet.add(b);
    nodeSet.add(c);
    nodeSet.add(d);
    Set<Relationship> relSet = new HashSet<>();
    relSet.add(graph.makeEdge("a", "b"));
    relSet.add(graph.makeEdge("b", "c"));
    relSet.add(graph.makeEdge("c", "d"));
    relSet.add(graph.makeEdge("d", "c"));
    relSet.add(graph.makeEdge("c", "a"));
    // Edge not included in rel set
    graph.makeEdge("a", "o");
    EigenvectorCentrality eigenvectorCentrality = getEigenvectorCentrality(Direction.OUTGOING, new CostEvaluator<Double>() {

        @Override
        public Double getCost(Relationship relationship, Direction direction) {
            return 1d;
        }
    }, nodeSet, relSet, 0.01);
    assertApproximateCentrality(eigenvectorCentrality, "o", 0d, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "a", 0.481, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "b", 0.363, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "c", 0.637, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "d", 0.481, 0.02);
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) EigenvectorCentrality(org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality) Direction(org.neo4j.graphdb.Direction) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 30 with Direction

use of org.neo4j.graphdb.Direction in project neo4j by neo4j.

the class EigenvectorCentralityTest method shouldHandleIsolatedCommunities.

@Test
public void shouldHandleIsolatedCommunities() {
    /*
         * Layout
         *
         * (a) -> (b)
         *
         *   ___________   _____
         *  v            \v     \
         * (c) -> (d) -> (e) -> (f)
         *
         */
    Set<Node> nodeSet = new HashSet<>();
    nodeSet.add(graph.makeNode("a"));
    nodeSet.add(graph.makeNode("b"));
    nodeSet.add(graph.makeNode("c"));
    nodeSet.add(graph.makeNode("d"));
    nodeSet.add(graph.makeNode("e"));
    nodeSet.add(graph.makeNode("f"));
    Set<Relationship> relSet = new HashSet<>();
    relSet.add(graph.makeEdge("a", "b"));
    relSet.add(graph.makeEdge("c", "d"));
    relSet.add(graph.makeEdge("d", "e"));
    relSet.add(graph.makeEdge("e", "f"));
    relSet.add(graph.makeEdge("e", "c"));
    relSet.add(graph.makeEdge("f", "e"));
    EigenvectorCentrality eigenvectorCentrality = getEigenvectorCentrality(Direction.OUTGOING, new CostEvaluator<Double>() {

        @Override
        public Double getCost(Relationship relationship, Direction direction) {
            return 1d;
        }
    }, nodeSet, relSet, 0.001);
    assertApproximateCentrality(eigenvectorCentrality, "a", 0d, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "b", 0d, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "c", 0.48, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "d", 0.36, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "e", 0.64, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "f", 0.48, 0.02);
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) EigenvectorCentrality(org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality) Direction(org.neo4j.graphdb.Direction) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Direction (org.neo4j.graphdb.Direction)42 Relationship (org.neo4j.graphdb.Relationship)25 Test (org.junit.Test)21 RelationshipType (org.neo4j.graphdb.RelationshipType)14 Node (org.neo4j.graphdb.Node)11 EigenvectorCentrality (org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality)10 HashMap (java.util.HashMap)6 Dijkstra (org.neo4j.graphalgo.impl.shortestpath.Dijkstra)6 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 List (java.util.List)4 DoubleAdder (org.neo4j.graphalgo.impl.util.DoubleAdder)4 DoubleComparator (org.neo4j.graphalgo.impl.util.DoubleComparator)4 EnumMap (java.util.EnumMap)3 PropertyContainer (org.neo4j.graphdb.PropertyContainer)3 NestingIterator (org.neo4j.helpers.collection.NestingIterator)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Stack (java.util.Stack)2 TreeMap (java.util.TreeMap)2