Beispiel #1
0
            public override Evaluation Evaluate(Path path, BranchState <double> state)
            {
                double nextState = state.State;

                if (path.Length() > 0)
                {
                    nextState  += CostEvaluator.getCost(path.LastRelationship(), OUTGOING);
                    state.State = nextState;
                }
                return(Evaluation.EXCLUDE_AND_CONTINUE);
            }
Beispiel #2
0
            public override Evaluation Evaluate(Path path, BranchState <double> state)
            {
                double nextState = state.State;

                if (path.Length() > 0)
                {
                    nextState  += CostEvaluator.getCost(path.LastRelationship(), OUTGOING);
                    state.State = nextState;
                }
                if (path.EndNode().Equals(EndNode))
                {
                    ShortestSoFar.Value = Math.Min(ShortestSoFar.doubleValue(), nextState);
                    return(Evaluation.INCLUDE_AND_PRUNE);
                }
                return(Evaluation.EXCLUDE_AND_CONTINUE);
            }
Beispiel #3
0
 protected internal override double?CalculateValue(TraversalBranch next)
 {
     return(next.Length() == 0 ? 0d : _evaluator.getCost(next.LastRelationship(), OUTGOING));
 }
Beispiel #4
0
        /// <summary>
        /// Internal calculate method that will do the calculation. This can however
        /// be called externally to manually trigger the calculation.
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") public void calculate()
        public virtual void Calculate()
        {
            // Don't do it more than once
            if (DoneCalculation)
            {
                return;
            }
            DoneCalculation = true;
            // Build initial matrix
            int n = NodeSet.Count;

//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: CostMatrix = (CostType[][]) new object[n][n];
            CostMatrix = ( CostType[][] )RectangularArrays.RectangularObjectArray(n, n);
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: Predecessors = new System.Nullable<int>[n][n];
            Predecessors = RectangularArrays.RectangularSystemNullableArray <int>(n, n);
            IndexedNodes = new Node[n];
            NodeIndexes  = new Dictionary <Node, int>();
            for (int i = 0; i < n; ++i)
            {
                for (int j = 0; j < n; ++j)
                {
                    CostMatrix[i][j] = InfinitelyBad;
                }
                CostMatrix[i][i] = StartCost;
            }
            int nodeIndex = 0;

            foreach (Node node in NodeSet)
            {
                NodeIndexes[node]       = nodeIndex;
                IndexedNodes[nodeIndex] = node;
                ++nodeIndex;
            }
            // Put the relationships in there
            foreach (Relationship relationship in RelationshipSet)
            {
                int?i1 = NodeIndexes[relationship.StartNode];
                int?i2 = NodeIndexes[relationship.EndNode];
                if (i1 == null || i2 == null)
                {
                    // TODO: what to do here? pretend nothing happened? cast
                    // exception?
                    continue;
                }
                if (RelationDirection.Equals(Direction.BOTH) || RelationDirection.Equals(Direction.OUTGOING))
                {
                    CostMatrix[i1][i2]   = CostEvaluator.getCost(relationship, Direction.OUTGOING);
                    Predecessors[i1][i2] = i1;
                }
                if (RelationDirection.Equals(Direction.BOTH) || RelationDirection.Equals(Direction.INCOMING))
                {
                    CostMatrix[i2][i1]   = CostEvaluator.getCost(relationship, Direction.INCOMING);
                    Predecessors[i2][i1] = i2;
                }
            }
            // Do it!
            for (int v = 0; v < n; ++v)
            {
                for (int i = 0; i < n; ++i)
                {
                    for (int j = 0; j < n; ++j)
                    {
                        CostType alternative = CostAccumulator.addCosts(CostMatrix[i][v], CostMatrix[v][j]);
                        if (CostComparator.Compare(CostMatrix[i][j], alternative) > 0)
                        {
                            CostMatrix[i][j]   = alternative;
                            Predecessors[i][j] = Predecessors[v][j];
                        }
                    }
                }
            }
            // TODO: detect negative cycles?
        }
Beispiel #5
0
 protected internal override int?calculateValue(TraversalBranch next)
 {
     return(next.Length() == 0 ? 0 : evaluator.getCost(next.LastRelationship(), Direction.BOTH));
 }