Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void withState()
        public virtual void WithState()
        {
            /* Graph
             *
             * (a)-[1]->(b)-[2]->(c)-[5]->(d)
             */

            Graph.makeEdgeChain("a,b,c,d");
            SetWeight("a", "b", 1);
            SetWeight("b", "c", 2);
            SetWeight("c", "d", 5);

            InitialBranchState <int> state = new Org.Neo4j.Graphdb.traversal.InitialBranchState_State <int>(0, 0);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Map<org.neo4j.graphdb.Node, int> encounteredState = new java.util.HashMap<>();
            IDictionary <Node, int> encounteredState = new Dictionary <Node, int>();
            PathExpander <int>      expander         = new PathExpanderAnonymousInnerClass(this, state, encounteredState);

            PathFinder <WeightedPath> finder = new Dijkstra(expander, state, CommonEvaluators.doubleCostEvaluator("weight"));

            AssertPaths(finder.FindAllPaths(Graph.getNode("a"), Graph.getNode("d")), "a,b,c,d");
            assertEquals(1, encounteredState[Graph.getNode("b")]);
            assertEquals(3, encounteredState[Graph.getNode("c")]);
            assertEquals(8, encounteredState[Graph.getNode("d")]);
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void canUseBranchState()
        public virtual void CanUseBranchState()
        {
            // This test doesn't use the predefined finder, which only means an unnecessary instantiation
            // if such an object. And this test will be run twice (once for each finder type in data()).
            /// <summary>
            /// <pre>
            ///   012345    A - B:  2
            ///  +------>y  A - B:  2
            /// 0|A         B - C:  3
            /// 1|          A - C:  10
            /// 2| B
            /// 3|
            /// 4|
            /// 5|
            /// 6|
            /// 7|C
            ///  V
            ///  x
            ///
            /// </pre>
            /// </summary>
            Node nodeA = Graph.makeNode("A", "x", 0d, "y", 0d);
            Node nodeB = Graph.makeNode("B", "x", 2d, "y", 1d);
            Node nodeC = Graph.makeNode("C", "x", 7d, "y", 0d);

            Graph.makeEdge("A", "B", "length", 2d);
            Graph.makeEdge("A", "B", "length", 2d);
            Graph.makeEdge("B", "C", "length", 3d);
            Graph.makeEdge("A", "C", "length", 10d);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Map<org.neo4j.graphdb.Node, double> seenBranchStates = new java.util.HashMap<>();
            IDictionary <Node, double> seenBranchStates = new Dictionary <Node, double>();
            PathExpander <double>      expander         = new PathExpanderAnonymousInnerClass(this, seenBranchStates);

            double initialStateValue = 0D;
            PathFinder <WeightedPath> traversalFinder = new TraversalAStar(expander, new Org.Neo4j.Graphdb.traversal.InitialBranchState_State(initialStateValue, initialStateValue), doubleCostEvaluator("length"), EstimateEvaluator);
            WeightedPath path = traversalFinder.FindSinglePath(nodeA, nodeC);

            assertEquals(( double? )5.0D, ( double? )path.Weight());
            AssertPathDef(path, "A", "B", "C");
            assertEquals(MapUtil.genericMap <Node, double>(nodeA, 0D, nodeB, 2D), seenBranchStates);
        }