Search in sources :

Example 11 with Dijkstra

use of org.neo4j.graphalgo.impl.shortestpath.Dijkstra in project neo4j by neo4j.

the class DijkstraMultiplePathsTest method test6.

@Test
void test6() {
    try (Transaction transaction = graphDb.beginTx()) {
        graph.makeEdgeChain(transaction, "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,z", "cost", (double) 1);
        graph.makeEdge(transaction, "a", "b2", "cost", (double) 4);
        graph.makeEdge(transaction, "b2", "c", "cost", -2);
        Dijkstra<Double> dijkstra = new Dijkstra<>(0.0, graph.getNode(transaction, "a"), graph.getNode(transaction, "z"), CommonEvaluators.doubleCostEvaluator("cost"), new DoubleAdder(), Double::compareTo, Direction.OUTGOING, MyRelTypes.R1);
        List<List<Node>> paths = dijkstra.getPathsAsNodes();
        assertEquals(2, paths.size());
        transaction.commit();
    }
}
Also used : DoubleAdder(org.neo4j.graphalgo.impl.util.DoubleAdder) Transaction(org.neo4j.graphdb.Transaction) List(java.util.List) Dijkstra(org.neo4j.graphalgo.impl.shortestpath.Dijkstra) Test(org.junit.jupiter.api.Test)

Aggregations

Dijkstra (org.neo4j.graphalgo.impl.shortestpath.Dijkstra)11 DoubleAdder (org.neo4j.graphalgo.impl.util.DoubleAdder)10 Relationship (org.neo4j.graphdb.Relationship)8 List (java.util.List)7 Test (org.junit.jupiter.api.Test)7 Transaction (org.neo4j.graphdb.Transaction)7 Direction (org.neo4j.graphdb.Direction)6 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 DoubleComparator (org.neo4j.graphalgo.impl.util.DoubleComparator)3 Neo4jAlgoTestCase (common.Neo4jAlgoTestCase)2 Map (java.util.Map)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 CostEvaluator (org.neo4j.graphalgo.CostEvaluator)2 Entity (org.neo4j.graphdb.Entity)1 Node (org.neo4j.graphdb.Node)1 PropertyContainer (org.neo4j.graphdb.PropertyContainer)1