Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void makeSureAMaxResultCountIsObeyed()
        public virtual void MakeSureAMaxResultCountIsObeyed()
        {
            // Layout:
            //
            //   (a)--(b)--(c)--(d)--(e)
            //    |                 / | \
            //   (f)--(g)---------(h) |  \
            //    |                   |   |
            //   (i)-----------------(j)  |
            //    |                       |
            //   (k)----------------------
            //
            Graph.makeEdgeChain("a,b,c,d,e");
            Graph.makeEdgeChain("a,f,g,h,e");
            Graph.makeEdgeChain("f,i,j,e");
            Graph.makeEdgeChain("i,k,e");
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Node a = graph.getNode("a");
            Node a = Graph.getNode("a");
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Node e = graph.getNode("e");
            Node e = Graph.getNode("e");
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.PathExpander expander = org.neo4j.graphdb.PathExpanders.forTypeAndDirection(R1, OUTGOING);
            PathExpander expander = PathExpanders.forTypeAndDirection(R1, OUTGOING);

            TestShortestPathFinder(finder => assertEquals(4, Iterables.count(finder.findAllPaths(a, e))), expander, 10, 10);
            for (int i = 4; i >= 1; i--)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int count = i;
                int count = i;
                TestShortestPathFinder(finder => assertEquals(count, Iterables.count(finder.findAllPaths(a, e))), expander, 10, count);
            }
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Parameterized.Parameters public static java.util.Collection<Object[]> data()
        public static ICollection <object[]> Data()
        {
            return(Arrays.asList(new object[][]
            {
                new object[]
                {
                    PathExpanders.allTypesAndDirections(), PathInterestFactory.All(), Uniqueness.NODE_PATH, new string[] { "a", "a,b", "a,c", "a,b,d", "a,b,c", "a,c,b", "a,c,b,d" }
                },
                new object[]
                {
                    PathExpanders.allTypesAndDirections(), PathInterestFactory.AllShortest(), Uniqueness.NODE_PATH, new string[] { "a", "a,b", "a,c", "a,b,d" }
                },
                new object[]
                {
                    PathExpanders.forDirection(Direction.OUTGOING), PathInterestFactory.All(), Uniqueness.NODE_PATH, new string[] { "a", "a,b", "a,c", "a,b,d", "a,c,b", "a,c,b,d" }
                },
                new object[]
                {
                    PathExpanders.allTypesAndDirections(), PathInterestFactory.All(), Uniqueness.NODE_GLOBAL, new string[] { "a", "a,b", "a,c", "a,b,d" }
                },
                new object[]
                {
                    PathExpanders.allTypesAndDirections(), PathInterestFactory.All(), Uniqueness.RELATIONSHIP_GLOBAL, new string[] { "a", "a,b", "a,c", "a,b,d", "a,b,c" }
                }
            }));
        }
Esempio n. 3
0
        public virtual Path PathToReference(Node me)
        {
            PathFinder <Path> finder = GraphAlgoFactory.shortestPath(PathExpanders.allTypesAndDirections(), 6);

            using (Transaction tx = me.GraphDatabase.beginTx())
            {
                Node other;
                if (me.hasRelationship(RelationshipType.withName("friend")))
                {
                    ResourceIterable <Relationship> relationships = (ResourceIterable <Relationship>)me.getRelationships(RelationshipType.withName("friend"));
                    using (ResourceIterator <Relationship> resourceIterator = relationships.GetEnumerator())
                    {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                        other = resourceIterator.next().getOtherNode(me);
                    }
                }
                else
                {
                    other = me.GraphDatabase.createNode();
                }
                Path path = finder.FindSinglePath(other, me);

                tx.Success();
                return(path);
            }
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void canGetPathsInTriangleGraph()
		 public virtual void CanGetPathsInTriangleGraph()
		 {
			  /* NODE (NAME/INDEX)
			   *
			   * (A/0) ------- 2 -----> (B/1)
			   *   \                     /
			   *    - 10 -> (C/2) <- 3 -
			   */
			  Node nodeA = Graph.makeNode( "A" );
			  Node nodeB = Graph.makeNode( "B" );
			  Node nodeC = Graph.makeNode( "C" );
			  Graph.makeEdge( "A", "B", "length", 2d );
			  Graph.makeEdge( "B", "C", "length", 3L );
			  Graph.makeEdge( "A", "C", "length", ( sbyte )10 );

			  PathFinder finder = factory.dijkstra( PathExpanders.allTypesAndDirections() );
			  IEnumerator<WeightedPath> paths = finder.findAllPaths( nodeA, nodeC ).GetEnumerator();
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
			  assertTrue( "expected at least one path", paths.hasNext() );
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
			  assertPath( paths.next(), nodeA, nodeB, nodeC );
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
			  assertFalse( "expected at most one path", paths.hasNext() );

			  AssertPath( finder.findSinglePath( nodeA, nodeC ), nodeA, nodeB, nodeC );
		 }
Esempio n. 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void canContinueGettingPathsByDiminishingCost()
		 public virtual void CanContinueGettingPathsByDiminishingCost()
		 {
			  /*
			   * NODE (NAME/INDEX)
			   *
			   * (A)-*2->(B)-*3->(C)-*1->(D)
			   *  |        \             ^ ^
			   *  |          ----*5-----/  |
			   *   \                       |
			   *     ---------*6-----------
			   */

			  Node nodeA = Graph.makeNode( "A" );
								Graph.makeNode( "B" );
								Graph.makeNode( "C" );
			  Node nodeD = Graph.makeNode( "D" );

			  // Path "1"
			  Graph.makeEdge( "A", "B", "length", 2d );
			  Graph.makeEdge( "B", "C", "length", 3L );
			  Graph.makeEdge( "C", "D", "length", ( sbyte )1 ); // = 6

			  // Path "2"
			  Graph.makeEdge( "B", "D", "length", ( short )5 ); // = 7

			  // Path "3"
			  Graph.makeEdge( "A", "D", "length", ( float )6 ); // = 6

			  PathFinder finder = factory.dijkstra( PathExpanders.allTypesAndDirections() );
			  AssertPaths( finder.findAllPaths( nodeA, nodeD ), "A,B,C,D", "A,D" );
		 }
Esempio n. 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testExactDepthFinder()
        public virtual void TestExactDepthFinder()
        {
            // Layout (a to k):
            //
            //     (a)--(c)--(g)--(k)
            //    /                /
            //  (b)-----(d)------(j)
            //   |        \      /
            //  (e)--(f)--(h)--(i)
            //
            Graph.makeEdgeChain("a,c,g,k");
            Graph.makeEdgeChain("a,b,d,j,k");
            Graph.makeEdgeChain("b,e,f,h,i,j");
            Graph.makeEdgeChain("d,h");
            PathExpander <object> expander = PathExpanders.forTypeAndDirection(MyRelTypes.R1, Direction.OUTGOING);
            Node a = Graph.getNode("a");
            Node k = Graph.getNode("k");

            AssertPaths(GraphAlgoFactory.pathsWithLength(expander, 3).findAllPaths(a, k), "a,c,g,k");
            AssertPaths(GraphAlgoFactory.pathsWithLength(expander, 4).findAllPaths(a, k), "a,b,d,j,k");
            AssertPaths(GraphAlgoFactory.pathsWithLength(expander, 5).findAllPaths(a, k));
            AssertPaths(GraphAlgoFactory.pathsWithLength(expander, 6).findAllPaths(a, k), "a,b,d,h,i,j,k");
            AssertPaths(GraphAlgoFactory.pathsWithLength(expander, 7).findAllPaths(a, k), "a,b,e,f,h,i,j,k");
            AssertPaths(GraphAlgoFactory.pathsWithLength(expander, 8).findAllPaths(a, k));
        }
Esempio n. 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void betterTentativePath()
        public virtual void BetterTentativePath()
        {
            // GIVEN
            EstimateEvaluator <double> estimator = (node, goal) => ( double? )node.getProperty("estimate");
            PathFinder <WeightedPath>  finder    = aStar(PathExpanders.allTypesAndDirections(), doubleCostEvaluator("weight", 0d), estimator);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Node node1 = graph.makeNode("1", "estimate", 0.003d);
            Node node1 = Graph.makeNode("1", "estimate", 0.003d);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Node node2 = graph.makeNode("2", "estimate", 0.002d);
            Node node2 = Graph.makeNode("2", "estimate", 0.002d);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Node node3 = graph.makeNode("3", "estimate", 0.001d);
            Node node3 = Graph.makeNode("3", "estimate", 0.001d);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Node node4 = graph.makeNode("4", "estimate", 0d);
            Node node4 = Graph.makeNode("4", "estimate", 0d);

            Graph.makeEdge("1", "3", "weight", 0.253d);
            Graph.makeEdge("1", "2", "weight", 0.018d);
            Graph.makeEdge("2", "4", "weight", 0.210d);
            Graph.makeEdge("2", "3", "weight", 0.180d);
            Graph.makeEdge("2", "3", "weight", 0.024d);
            Graph.makeEdge("3", "4", "weight", 0.135d);
            Graph.makeEdge("3", "4", "weight", 0.013d);

            // WHEN
            WeightedPath best14 = finder.FindSinglePath(node1, node4);

            // THEN
            assertPath(best14, node1, node2, node3, node4);
        }
Esempio n. 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Parameters public static java.util.Collection<Object[]> data()
        public static ICollection <object[]> Data()
        {
            return(Arrays.asList(new object[][]
            {
                new object[] { GraphAlgoFactory.aStar(PathExpanders.allTypesAndDirections(), doubleCostEvaluator("length"), EstimateEvaluator) },
                new object[] { new TraversalAStar(PathExpanders.allTypesAndDirections(), doubleCostEvaluator("length"), EstimateEvaluator) }
            }));
        }
Esempio n. 9
0
        public virtual Stream <NodeResult> GraphAlgosDijkstra(Node start, Node end, string relType, string weightProperty)
        {
            PathFinder <WeightedPath> pathFinder = GraphAlgoFactory.dijkstra(PathExpanders.forTypeAndDirection(RelationshipType.withName(relType), Direction.BOTH), weightProperty);

            WeightedPath path = pathFinder.FindSinglePath(start, end);

//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
            return(StreamSupport.stream(path.Nodes().spliterator(), false).map(NodeResult::new));
        }
Esempio n. 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnPathsInIncreasingOrderOfCost()
        public virtual void ShouldReturnPathsInIncreasingOrderOfCost()
        {
            /*
             *
             *      ----- (e) - 1 - (f) ---
             *    /                         \
             *   /    ------- (a) --------   \
             *  1   /            \         \  2
             *  |  2              0         0 |
             *  | /                \         \|
             * (s) - 1 - (c) - 1 - (d) - 1 - (t)
             *   \                 /
             *    -- 1 - (b) - 1 -
             *
             */

            Node s = Graph.makeNode("s");
            Node t = Graph.makeNode("t");

            Graph.makeEdgeChain("s,e,f", "length", 1.0);
            Graph.makeEdge("f", "t", "length", 2);
            Graph.makeEdge("s", "a", "length", 2);
            Graph.makeEdge("a", "t", "length", 0);
            Graph.makeEdge("s", "c", "length", 1);
            Graph.makeEdge("c", "d", "length", 1);
            Graph.makeEdge("s", "b", "length", 1);
            Graph.makeEdge("b", "d", "length", 1);
            Graph.makeEdge("d", "a", "length", 0);
            Graph.makeEdge("d", "t", "length", 1);

            PathExpander expander = PathExpanders.allTypesAndDirections();
            Dijkstra     algo     = new Dijkstra(expander, CommonEvaluators.doubleCostEvaluator("length"), PathInterestFactory.all(NoneStrictMath.EPSILON));

            IEnumerator <WeightedPath> paths = algo.FindAllPaths(s, t).GetEnumerator();

            for (int i = 1; i <= 3; i++)
            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue("Expected at least " + i + " path(s)", paths.hasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue("Expected 3 paths of cost 2", NoneStrictMath.Equals(paths.next().weight(), 2));
            }
            for (int i = 1; i <= 3; i++)
            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue("Expected at least " + i + " path(s)", paths.hasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue("Expected 3 paths of cost 3", NoneStrictMath.Equals(paths.next().weight(), 3));
            }
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertTrue("Expected at least 7 paths", paths.hasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertTrue("Expected 1 path of cost 4", NoneStrictMath.Equals(paths.next().weight(), 4));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse("Expected exactly 7 paths", paths.hasNext());
        }
Esempio n. 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleSimpleChainOddDepth()
        public virtual void ShouldHandleSimpleChainOddDepth()
        {
            // (a) - (b) - (c) - (d)
            Graph.makeEdgeChain("a,b,c,d");
            Node a = Graph.getNode("a");
            Node d = Graph.getNode("d");

            AssertPaths((new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 3, int.MaxValue, false)).findAllPaths(a, d), "a,b,c,d");
            AssertPaths((new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 3, int.MaxValue, false)).findAllPaths(a, d), "a,b,c,d");
        }
Esempio n. 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = 5000) public void testForLoops()
        public virtual void TestForLoops()
        {
            /*
             *
             *            (b)
             *           /  \         0
             *          0    0       / \            - 0 - (c1) - 0 -
             *           \  /        \/           /                 \
             * (s) - 1 - (a1) - 1 - (a2) - 1 - (a3)                (a4) - 1 - (t)
             *                                    \                 /
             *                                     - 0 - (c2) - 0 -
             *
             */

            using (Transaction tx = GraphDb.beginTx())
            {
                Node s = Graph.makeNode("s");
                Node t = Graph.makeNode("t");

                // Blob loop
                Graph.makeEdge("s", "a1", "length", 1);
                Graph.makeEdge("a1", "b", "length", 0);
                Graph.makeEdge("b", "a1", "length", 0);

                // Self loop
                Graph.makeEdge("a1", "a2", "length", 1);
                Graph.makeEdge("a2", "a2", "length", 0);

                // Diamond loop
                Graph.makeEdge("a2", "a3", "length", 1);
                Graph.makeEdge("a3", "c1", "length", 0);
                Graph.makeEdge("a3", "c2", "length", 0);
                Graph.makeEdge("c1", "a4", "length", 0);
                Graph.makeEdge("c1", "a4", "length", 0);
                Graph.makeEdge("a4", "t", "length", 1);

                PathExpander expander = PathExpanders.allTypesAndDirections();
                Dijkstra     algo     = new Dijkstra(expander, CommonEvaluators.doubleCostEvaluator("length"), PathInterestFactory.all(NoneStrictMath.EPSILON));

                IEnumerator <WeightedPath> paths = algo.FindAllPaths(s, t).GetEnumerator();

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue("Expected at least one path", paths.hasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals("Expected first path of length 6", 6, paths.next().length());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertTrue("Expected at least two paths", paths.hasNext());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals("Expected second path of length 6", 6, paths.next().length());
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse("Expected exactly two paths", paths.hasNext());

                tx.Success();
            }
        }
Esempio n. 13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testKShortestPaths()
        public virtual void TestKShortestPaths()
        {
            /*
             *      ----- (e) - 3 - (f) ---
             *    /                         \
             *   /    ------- (a) --------   \
             *  3   /            \         \  3
             *  |  2              0         0 |
             *  | /                \         \|
             * (s) - 1 - (c) - 1 - (d) - 1 - (t)
             *   \                 /
             *    -- 1 - (b) - 1 -
             *
             */
            Node s = Graph.makeNode("s");
            Node t = Graph.makeNode("t");

            Graph.makeEdge("s", "a", "length", 2);
            Graph.makeEdge("s", "b", "length", 1);
            Graph.makeEdge("s", "c", "length", 1);
            Graph.makeEdge("s", "e", "length", 3);
            Graph.makeEdge("a", "t", "length", 0);
            Graph.makeEdge("b", "d", "length", 1);
            Graph.makeEdge("c", "d", "length", 1);
            Graph.makeEdge("d", "a", "length", 0);
            Graph.makeEdge("d", "t", "length", 1);
            Graph.makeEdge("e", "f", "length", 3);
            Graph.makeEdge("f", "t", "length", 3);

            PathExpander expander          = PathExpanders.allTypesAndDirections();
            PathFinder <WeightedPath> algo = new Dijkstra(expander, CommonEvaluators.doubleCostEvaluator("length"), PathInterestFactory.numberOfShortest(NoneStrictMath.EPSILON, 6));

            IEnumerator <WeightedPath> paths = algo.FindAllPaths(s, t).GetEnumerator();

            int count = 0;

            while (paths.MoveNext())
            {
                count++;
                WeightedPath path = paths.Current;
                double       expectedWeight;
                if (count <= 3)
                {
                    expectedWeight = 2.0;
                }
                else
                {
                    expectedWeight = 3.0;
                }
                assertTrue("Expected path number " + count + " to have weight of " + expectedWeight, NoneStrictMath.Equals(path.Weight(), expectedWeight));
            }
            assertEquals("Expected exactly 6 returned paths", 6, count);
        }
Esempio n. 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void canFindNeighbour()
		 public virtual void CanFindNeighbour()
		 {
			  /*
			   * (A) - 1 -(B)
			   */
			  Node nodeA = Graph.makeNode( "A" );
			  Node nodeB = Graph.makeNode( "B" );
			  Graph.makeEdge( "A", "B", "length", 1 );

			  PathFinder finder = factory.dijkstra( PathExpanders.allTypesAndDirections() );
			  AssertPaths( finder.findAllPaths( nodeA, nodeB ), "A,B" );
		 }
Esempio n. 15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleNeighbouringNodes()
        public virtual void ShouldHandleNeighbouringNodes()
        {
            // (a) - (b)
            Graph.makeEdgeChain("a,b");
            Node a = Graph.getNode("a");
            Node b = Graph.getNode("b");
            ExactDepthPathFinder pathFinder = new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, int.MaxValue, false);
            IEnumerable <Path>   allPaths   = pathFinder.FindAllPaths(a, b);

            AssertPaths((new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, int.MaxValue, false)).findAllPaths(a, b), "a,b");
            AssertPaths((new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, int.MaxValue, false)).findAllPaths(a, b), "a,b");
        }
Esempio n. 16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void pathToSelfReturnsZero()
		 public virtual void PathToSelfReturnsZero()
		 {
			  // GIVEN
			  Node start = Graph.makeNode( "A" );

			  // WHEN
			  PathFinder<WeightedPath> finder = factory.dijkstra( PathExpanders.allTypesAndDirections() );
			  WeightedPath path = finder.FindSinglePath( start, start );
			  // THEN
			  assertNotNull( path );
			  assertEquals( start, path.StartNode() );
			  assertEquals( start, path.EndNode() );
			  assertEquals( 0, path.Length() );
		 }
Esempio n. 17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testExactDepthPathsLoopsAllowed()
        public virtual void TestExactDepthPathsLoopsAllowed()
        {
            // Layout:
            //
            // (a)-->(b)==>(c)-->(e)
            //        ^    /
            //         \  v
            //         (d)
            //
            Graph.makeEdgeChain("a,b,c,d,b,c,e");
            Node a = Graph.getNode("a");
            Node e = Graph.getNode("e");

            AssertPaths((new ExactDepthPathFinder(PathExpanders.forDirection(Direction.OUTGOING), 6, int.MaxValue, true)).findAllPaths(a, e), "a,b,c,d,b,c,e");
        }
Esempio n. 18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void canFindOrphanGraph()
		 public virtual void CanFindOrphanGraph()
		 {
			  /*
			   *
			   * (A)=1   (relationship to self)
			   *
			   * Should not find (A)-(A). Should find (A)
			   */

			  Node nodeA = Graph.makeNode( "A" );
			  Graph.makeEdge( "A", "A", "length", 1d );

			  PathFinder finder = factory.dijkstra( PathExpanders.allTypesAndDirections() );
			  AssertPaths( finder.findAllPaths( nodeA, nodeA ), "A" );
		 }
Esempio n. 19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testSimplestGraph()
        public virtual void TestSimplestGraph()
        {
            // Layout:
            //    __
            //   /  \
            // (s)  (t)
            //   \__/
            Graph.makeEdge("s", "t");
            Graph.makeEdge("s", "t");
            TestShortestPathFinder(finder =>
            {
                IEnumerable <Path> paths = finder.findAllPaths(Graph.getNode("s"), Graph.getNode("t"));
                AssertPaths(paths, "s,t", "s,t");
                AssertPaths(asList(finder.findSinglePath(Graph.getNode("s"), Graph.getNode("t"))), "s,t");
            }, PathExpanders.forTypeAndDirection(R1, BOTH), 1);
        }
Esempio n. 20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void makeSureShortestPathsReturnsNoLoops()
        public virtual void MakeSureShortestPathsReturnsNoLoops()
        {
            // Layout:
            //
            // (a)-->(b)==>(c)-->(e)
            //        ^    /
            //         \  v
            //         (d)
            //
            Graph.makeEdgeChain("a,b,c,d,b,c,e");
            TestShortestPathFinder(finder =>
            {
                Node a = Graph.getNode("a");
                Node e = Graph.getNode("e");
                AssertPaths(finder.findAllPaths(a, e), "a,b,c,e", "a,b,c,e");
            }, PathExpanders.forTypeAndDirection(R1, BOTH), 6);
        }
Esempio n. 21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testExactDepthPathsReturnsNoLoops()
        public virtual void TestExactDepthPathsReturnsNoLoops()
        {
            // Layout:
            //
            // (a)-->(b)==>(c)-->(e)
            //        ^    /
            //         \  v
            //         (d)
            //
            Graph.makeEdgeChain("a,b,c,d,b,c,e");
            Node a = Graph.getNode("a");
            Node e = Graph.getNode("e");

            AssertPaths(GraphAlgoFactory.pathsWithLength(PathExpanders.forType(MyRelTypes.R1), 3).findAllPaths(a, e), "a,b,c,e", "a,b,c,e");
            AssertPaths(GraphAlgoFactory.pathsWithLength(PathExpanders.forType(MyRelTypes.R1), 4).findAllPaths(a, e), "a,b,d,c,e");
            AssertPaths(GraphAlgoFactory.pathsWithLength(PathExpanders.forType(MyRelTypes.R1), 6).findAllPaths(a, e));
        }
Esempio n. 22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleNondirectedGraph()
        public virtual void ShouldHandleNondirectedGraph()
        {
            //     (b) ----------------- (c)      length 3
            //   /                          \
            // (a) - (h) - (i) - (j) - (k) - (g)  length 5
            //   \                          /
            //     (d) - (e) ------------ (f)     length 4
            Graph.makeEdgeChain("a,b,c,g");
            Graph.makeEdgeChain("a,d,e,f,g");
            Graph.makeEdgeChain("a,h,i,j,k,g");
            Node a = Graph.getNode("a");
            Node g = Graph.getNode("g");

            AssertPaths((new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 3, int.MaxValue, false)).findAllPaths(a, g), "a,b,c,g");
            AssertPaths((new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 4, int.MaxValue, false)).findAllPaths(a, g), "a,d,e,f,g");
            AssertPaths((new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 5, int.MaxValue, false)).findAllPaths(a, g), "a,h,i,j,k,g");
        }
Esempio n. 23
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldOnlyFindTheShortestPaths()
		 public virtual void ShouldOnlyFindTheShortestPaths()
		 {
			  /*
			   *
			   *      ----- (e) - 1 - (f) ---
			   *    /                         \
			   *   /    ------- (a) --------   \
			   *  1   /            \         \  2
			   *  |  2              0         0 |
			   *  | /                \         \|
			   * (s) - 1 - (c) - 1 - (d) - 1 - (t)
			   *   \                 /
			   *    -- 1 - (b) - 1 -
			   *
			   */

			  Node s = Graph.makeNode( "s" );
			  Node t = Graph.makeNode( "t" );
			  Node a = Graph.makeNode( "a" );
			  Node b = Graph.makeNode( "b" );
			  Node c = Graph.makeNode( "c" );

			  Graph.makeEdgeChain( "s,e,f", "length", 1.0 );
			  Graph.makeEdge( "f", "t", "length", 2 );
			  Graph.makeEdge( "s","a", "length", 2 );
			  Graph.makeEdge( "a","t", "length", 0 );
			  Graph.makeEdge( "s", "c", "length", 1 );
			  Graph.makeEdge( "c","d", "length", 1 );
			  Graph.makeEdge( "s","b", "length", 1 );
			  Graph.makeEdge( "b","d", "length", 1 );
			  Graph.makeEdge( "d","a", "length", 0 );
			  Graph.makeEdge( "d","t", "length", 1 );

			  PathFinder finder = factory.dijkstra( PathExpanders.allTypesAndDirections() );
			  IEnumerator<WeightedPath> paths = finder.findAllPaths( s, t ).GetEnumerator();

			  for ( int i = 1; i <= 3; i++ )
			  {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
					assertTrue( "Expected at least " + i + " path(s)", paths.hasNext() );
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
					assertTrue( "Expected 3 paths of cost 2", NoneStrictMath.Equals( paths.next().weight(), 2 ) );
			  }
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
			  assertFalse( "Expected exactly 3 paths", paths.hasNext() );
		 }
Esempio n. 24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void allPathsToSelfReturnsZero()
		 public virtual void AllPathsToSelfReturnsZero()
		 {
			  // GIVEN
			  Node start = Graph.makeNode( "A" );

			  // WHEN
			  PathFinder<WeightedPath> finder = factory.dijkstra( PathExpanders.allTypesAndDirections() );
			  IEnumerable<WeightedPath> paths = finder.FindAllPaths( start, start );

			  // THEN
			  foreach ( WeightedPath path in paths )
			  {
					assertNotNull( path );
					assertEquals( start, path.StartNode() );
					assertEquals( start, path.EndNode() );
					assertEquals( 0, path.Length() );
			  }
		 }
Esempio n. 25
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleDirectionalGraph()
        public virtual void ShouldHandleDirectionalGraph()
        {
            // ALL DIRECTED from (a) towards (g)
            //     (b) ----------------- (c)      length 3
            //   /                          \
            // (a) - (h) - (i) - (j) - (k) - (g)  length 5
            //   \                          /
            //     (d) - (e) ------------ (f)     length 4
            Graph.makeEdgeChain("a,b,c,g");
            Graph.makeEdgeChain("a,d,e,f,g");
            Graph.makeEdgeChain("a,h,i,j,k,g");
            Node a = Graph.getNode("a");
            Node g = Graph.getNode("g");

            AssertPaths((new ExactDepthPathFinder(PathExpanders.forDirection(Direction.OUTGOING), 3, int.MaxValue, false)).findAllPaths(a, g), "a,b,c,g");
            AssertPaths((new ExactDepthPathFinder(PathExpanders.forDirection(Direction.OUTGOING), 4, int.MaxValue, false)).findAllPaths(a, g), "a,d,e,f,g");
            AssertPaths((new ExactDepthPathFinder(PathExpanders.forDirection(Direction.OUTGOING), 5, int.MaxValue, false)).findAllPaths(a, g), "a,h,i,j,k,g");
        }
Esempio n. 26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void canGetMultiplePathsInTriangleGraph()
		 public virtual void CanGetMultiplePathsInTriangleGraph()
		 {
			  /* NODE (NAME/INDEX)
			   * ==> (two relationships)
			   *
			   * (A/0) ====== 1 =====> (B/1)
			   *   \                    /
			   *    - 5 -> (C/2) <- 2 -
			   */
			  Node nodeA = Graph.makeNode( "A" );
			  Node nodeB = Graph.makeNode( "B" );
			  Node nodeC = Graph.makeNode( "C" );
			  ISet<Relationship> expectedFirsts = new HashSet<Relationship>();
			  expectedFirsts.Add( Graph.makeEdge( "A", "B", "length", 1d ) );
			  expectedFirsts.Add( Graph.makeEdge( "A", "B", "length", 1 ) );
			  Relationship expectedSecond = Graph.makeEdge( "B", "C", "length", 2L );
			  Graph.makeEdge( "A", "C", "length", 5d );

			  PathFinder finder = factory.dijkstra( PathExpanders.allTypesAndDirections() );
			  IEnumerator<WeightedPath> paths = finder.findAllPaths( nodeA, nodeC ).GetEnumerator();
			  for ( int i = 0; i < 2; i++ )
			  {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
					assertTrue( "expected more paths", paths.hasNext() );
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
					Path path = paths.next();
					AssertPath( path, nodeA, nodeB, nodeC );

					IEnumerator<Relationship> relationships = path.Relationships().GetEnumerator();
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
					assertTrue( "found shorter path than expected", relationships.hasNext() );
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
					assertTrue( "path contained unexpected relationship", expectedFirsts.remove( relationships.next() ) );
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
					assertTrue( "found shorter path than expected", relationships.hasNext() );
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
					assertEquals( expectedSecond, relationships.next() );
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
					assertFalse( "found longer path than expected", relationships.hasNext() );
			  }
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
			  assertFalse( "expected at most two paths", paths.hasNext() );
		 }
Esempio n. 27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testFinderShouldNotFindAnythingBeyondLimit()
        public virtual void TestFinderShouldNotFindAnythingBeyondLimit()
        {
            // Layout:
            //
            // (a)-->(b)-->(c)-->(d)-->(e)
            //
            Graph.makeEdgeChain("a,b,c,d,e");
            TestShortestPathFinder(finder => assertPaths(finder.findAllPaths(Graph.getNode("a"), Graph.getNode("b"))), PathExpanders.allTypesAndDirections(), 0);
            TestShortestPathFinder(finder =>
            {
                AssertPaths(finder.findAllPaths(Graph.getNode("a"), Graph.getNode("c")));
                AssertPaths(finder.findAllPaths(Graph.getNode("a"), Graph.getNode("d")));
            }, PathExpanders.allTypesAndDirections(), 1);
            TestShortestPathFinder(finder =>
            {
                AssertPaths(finder.findAllPaths(Graph.getNode("a"), Graph.getNode("d")));
                AssertPaths(finder.findAllPaths(Graph.getNode("a"), Graph.getNode("e")));
            }, PathExpanders.allTypesAndDirections(), 2);
        }
Esempio n. 28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void makeSureRelationshipNotConnectedIssueNotThere()
        public virtual void MakeSureRelationshipNotConnectedIssueNotThere()
        {
            /*
             *                                  (g)
             *                                  / ^
             *                                 v   \
             * (a)<--(b)<--(c)<--(d)<--(e)<--(f)   (i)
             *                                 ^   /
             *                                  \ v
             *                                  (h)
             */
            Graph.makeEdgeChain("i,g,f,e,d,c,b,a");
            Graph.makeEdgeChain("i,h,f");
            TestShortestPathFinder(finder =>
            {
                Node start = Graph.getNode("a");
                Node end   = Graph.getNode("i");
                AssertPaths(finder.findAllPaths(start, end), "a,b,c,d,e,f,g,i", "a,b,c,d,e,f,h,i");
            }, PathExpanders.forTypeAndDirection(R1, INCOMING), 10);
        }
Esempio n. 29
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testSmallGraphWithDefaults()
		 public virtual void TestSmallGraphWithDefaults()
		 {
			  Relationship shortCTOXRelationship = CreateGraph( true );

			  PathFinder<WeightedPath> finder = factory.dijkstra( PathExpanders.forTypeAndDirection( MyRelTypes.R1, Direction.OUTGOING ), CommonEvaluators.doubleCostEvaluator( "cost", 1.0d ) );

			  // Assert that there are two matching paths
			  Node startNode = Graph.getNode( "start" );
			  Node endNode = Graph.getNode( "x" );
			  AssertPaths( finder.FindAllPaths( startNode, endNode ), "start,a,b,c,x", "start,a,b,c,d,e,x" );

			  // Assert that for the shorter one it picked the correct relationship
			  // of the two from (c) --> (x)
			  foreach ( WeightedPath path in finder.FindAllPaths( startNode, endNode ) )
			  {
					if ( GetPathDef( path ).Equals( "start,a,b,c,x" ) )
					{
						 AssertContainsRelationship( path, shortCTOXRelationship );
					}
			  }
		 }
Esempio n. 30
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testAnotherSimpleGraph()
        public virtual void TestAnotherSimpleGraph()
        {
            // Layout:
            //   (m)
            //   /  \
            // (s)  (o)---(t)
            //   \  /       \
            //   (n)---(p)---(q)
            Graph.makeEdge("s", "m");
            Graph.makeEdge("m", "o");
            Graph.makeEdge("s", "n");
            Graph.makeEdge("n", "p");
            Graph.makeEdge("p", "q");
            Graph.makeEdge("q", "t");
            Graph.makeEdge("n", "o");
            Graph.makeEdge("o", "t");
            TestShortestPathFinder(finder =>
            {
                IEnumerable <Path> paths = finder.findAllPaths(Graph.getNode("s"), Graph.getNode("t"));
                AssertPaths(paths, "s,m,o,t", "s,n,o,t");
            }, PathExpanders.forTypeAndDirection(R1, BOTH), 6);
        }