Ejemplo n.º 1
0
Archivo: NBS.cs Proyecto: Treff/NBS
 public NBS(double epsilon = 1d)
 {
     _forwardHeuristic  = null;
     _backwardHeuristic = null;
     _counts            = new Dictionary <double, int>();
     _queue             = new NBSQueue <TState>(epsilon);
     ResetNodeCount();
 }
Ejemplo n.º 2
0
 public int CompareTo(Node other)
 {
     _priorityCache = FCost.CompareTo(other.FCost);  // A* first comparison F Cost
     if (_priorityCache == 0)
     {
         _priorityCache = HCost.CompareTo(other.HCost);
     }
     return(-_priorityCache); // Negative since the 1 meaning that the cost has a higher integer value and we are trying to find the lower cost
 }
Ejemplo n.º 3
0
    public int CompareTo(PathNode nodeToCompare)
    {
        int compare = FCost.CompareTo(nodeToCompare.FCost);

        if (compare == 0) // 2 fcost are equal.
        {
            compare = HCost.CompareTo(nodeToCompare.HCost);
        }
        return(-compare);
    }
Ejemplo n.º 4
0
        public int CompareTo(AstarNode other)
        {
            var compare = FCost.CompareTo(other.FCost);

            if (compare == 0)
            {
                compare = HCost.CompareTo(other.HCost);
            }
            return(-compare);
        }
Ejemplo n.º 5
0
        public int CompareTo(Node nodeToCompare)
        {
            int compare = FCost.CompareTo(nodeToCompare.FCost);

            if (compare == 0)
            {
                compare = HCost.CompareTo(nodeToCompare.HCost);
            }
            return(-compare);
        }
Ejemplo n.º 6
0
    public override int CompareTo(Node other)
    {
        int compare = FCost.CompareTo(other.FCost);

        if (compare == 0)
        {
            compare = HCost.CompareTo(other.HCost);
        }

        return(-compare);
    }
Ejemplo n.º 7
0
    public int CompareTo(GridTile other)
    {
        int compare = FCost.CompareTo(other.FCost);

        if (compare == 0)
        {
            compare = HCost.CompareTo(other.HCost);
        }

        return(-compare);
    }
Ejemplo n.º 8
0
    public int CompareTo(AbstractAStarNode other)
    {
        int compare = FCost.CompareTo(other.FCost);

        if (compare == 0)
        {
            compare = HCost.CompareTo(other.HCost);
        }

        return(compare);
    }
Ejemplo n.º 9
0
    //odradi ovo preko delegata
    public int CompareTo(Field other)
    {
        int compare = FCost.CompareTo(other.FCost);

        if (compare == 0)
        {
            compare = HCost.CompareTo(other.HCost);
        }
        //1 curent item is lower priority
        return(-compare);
    }
Ejemplo n.º 10
0
    public int CompareTo(PathNode other)
    {
        int compare = FCost.CompareTo(other.FCost);

        if (compare == 0)
        {
            compare = HCost.CompareTo(other.HCost); //remember, hCost is the tiebreaker
        }
        //CompareTo on integers treats higher as better. Because this is a pathing algorithm, our problem instead is minimization. So therefore, we return _negative_ compare.
        return(-compare);
    }
Ejemplo n.º 11
0
    public int CompareTo(PathfindingNode other)
    {
        var compare = FCost.CompareTo(other.FCost);

        if (compare == 0)
        {
            compare = HCost.CompareTo(other.HCost);
        }

        return(-compare);
    }
Ejemplo n.º 12
0
    public int CompareTo(Node other)
    {
        var comparison = FCost.CompareTo(other.FCost);

        if (comparison == 0)
        {
            comparison = HCost.CompareTo(other.HCost);
        }

        return(-comparison);
    }
Ejemplo n.º 13
0
        public int CompareTo(GridNodeAStar other)
        {
            var compare = FCost.CompareTo(other.FCost);

            if (compare == 0)
            {
                compare = HCost.CompareTo(other.HCost);
            }

            return(-compare);
        }
Ejemplo n.º 14
0
        public int CompareTo(INode other)
        {
            int fCostCompare = -FCost.CompareTo(other.FCost);

            if (fCostCompare == 0)
            {
                return(-HCost.CompareTo(other.HCost));
            }

            return(fCostCompare);
        }
Ejemplo n.º 15
0
Archivo: NBS.cs Proyecto: Treff/NBS
        public void GetPath(TState from, TState to, GetStateHash <TState> getHash, GetSuccessors <TState> getSuccessors,
                            GCost <TState> gCost, HCost <TState> forward, HCost <TState> backward, List <TState> thePath)
        {
            if (InitializeSearch(from, to, getHash, getSuccessors, gCost, forward, backward, thePath) == false)
            {
                return;
            }

            while (!ExpandAPair(thePath))
            {
            }
        }
Ejemplo n.º 16
0
    public int CompareTo(Node toCompare)
    {
        int compare = FCost.CompareTo(toCompare.FCost);

        if (compare == 0)
        {
            compare = HCost.CompareTo(toCompare.HCost);
        }

        //less fcost - higher priority (for heap class)
        return(-compare);
    }
Ejemplo n.º 17
0
        public int CompareTo(PathfindingNode inNodeToCompare)
        {
            int compare = FCost.CompareTo(inNodeToCompare.FCost);

            if (compare == 0)
            {
                compare = HCost.CompareTo(inNodeToCompare.HCost);
            }

            // Flip the compare because we want to sort from lowest to highest.
            return(-compare);
        }
Ejemplo n.º 18
0
        // --CURRENTLY UNUSED--
        public int CompareTo(Node n)
        {
            int compare = FCost.CompareTo(n.FCost);

            if (compare == 0)
            {
                compare = HCost.CompareTo(n.HCost);
            }

            // Need to flip the sign otherwise we get the wrong result!
            return(compare * -1);
        }
Ejemplo n.º 19
0
        /// <summary>
        ///     The <c>CompareTo</c> method compares the <see cref="Node" />'s priority in a <see cref="Heap{T}" />.
        ///     This is based on the <see cref="Node.FCost" /> and <see cref="Node.HCost" />.
        /// </summary>
        /// <param name="other">The <see cref="Node" /> that it has to be compared to.</param>
        /// <returns>
        ///     Returns <c>1</c> if it has a higher priority, <c>0</c> if the priority is the same and <c>-1</c> if it has a
        ///     lower priority.
        /// </returns>
        public int CompareTo(Node other)
        {
            // First compare the FCost between the nodes.
            int compare = FCost.CompareTo(other.FCost);

            // If both nodes have the same F-cost, take the H-cost in consideration.
            if (compare == 0)
            {
                compare = HCost.CompareTo(other.HCost);
            }

            // Compare returns 1 if the value is higher, in this case we want to return 1 if the node has a higher priority and thus a lower compare value.
            // So we need to invert the compare value and return it.
            return(-compare);
        }
Ejemplo n.º 20
0
Archivo: NBS.cs Proyecto: Treff/NBS
        public bool InitializeSearch(TState from, TState to, GetStateHash <TState> getHash, GetSuccessors <TState> getSuccessors,
                                     GCost <TState> gCost, HCost <TState> forward, HCost <TState> backward, List <TState> thePath)
        {
            _getStateHash      = getHash;
            _gCost             = gCost;
            _getSuccessors     = getSuccessors;
            _forwardHeuristic  = forward;
            _backwardHeuristic = backward;
            _currentCost       = double.MaxValue;
            _queue.Reset();
            ResetNodeCount();
            thePath.Clear();
            _start = from;
            _goal  = to;

            if (_start.Equals(_goal))
            {
                return(false);
            }
            _queue.ForwardQueue.AddOpenNode(_start, _getStateHash(_start), 0, _forwardHeuristic(_start, _goal));
            _queue.BackwardQueue.AddOpenNode(_goal, _getStateHash(_goal), 0, _backwardHeuristic(_goal, _start));
            return(true);
        }
Ejemplo n.º 21
0
Archivo: NBS.cs Proyecto: Treff/NBS
        private void Expand(int nextID, BDOpenClosed <TState> current,
                            BDOpenClosed <TState> opposite, HCost <TState> heuristic, TState target)
        {
            current.Close();

            //this can happen when we expand a single node instead of a pair
            if (FPUtil.GreaterEq(current.Lookup(nextID).G + current.Lookup(nextID).H, _currentCost))
            {
                return;
            }

            _nodesExpanded++;
            IEnumerable <TState> neighbors = _getSuccessors(current.Lookup(nextID).Data);

            foreach (TState succ in neighbors)
            {
                _nodesTouched++;
                StateLocation loc = current.Lookup(_getStateHash(succ), out int childID);

                // screening
                double edgeCost = _gCost(current.Lookup(nextID).Data, succ);
                if (FPUtil.GreaterEq(current.Lookup(nextID).G + edgeCost, _currentCost))
                {
                    continue;
                }

                switch (loc)
                {
                case StateLocation.Closed:     // ignore
                    break;

                case StateLocation.OpenReady:     // update cost if needed
                case StateLocation.OpenWaiting:
                {
                    if (FPUtil.Less(current.Lookup(nextID).G + edgeCost, current.Lookup(childID).G))
                    {
                        double oldGCost = current.Lookup(childID).G;
                        current.Lookup(childID).ParentID = nextID;
                        current.Lookup(childID).G        = current.Lookup(nextID).G + edgeCost;
                        current.KeyChanged(childID);

                        StateLocation loc2 = opposite.Lookup(_getStateHash(succ), out int reverseLoc);
                        if (loc2 == StateLocation.OpenReady || loc2 == StateLocation.OpenWaiting)
                        {
                            if (FPUtil.Less(current.Lookup(nextID).G + edgeCost + opposite.Lookup(reverseLoc).G, _currentCost))
                            {
                                _currentCost = current.Lookup(nextID).G + edgeCost + opposite.Lookup(reverseLoc).G;
                                _middleNode  = succ;
                            }
                        }
                        else if (loc == StateLocation.Closed)
                        {
                            current.Remove(childID);
                        }
                    }
                }
                break;

                case StateLocation.Unseen:
                {
                    StateLocation locReverse = opposite.Lookup(_getStateHash(succ), out int reverseLoc);
                    if (locReverse != StateLocation.Closed)
                    {
                        double newNodeF = current.Lookup(nextID).G + edgeCost + heuristic(succ, target);
                        if (FPUtil.Less(newNodeF, _currentCost))
                        {
                            if (FPUtil.Less(newNodeF, _queue.GetLowerBound()))
                            {
                                current.AddOpenNode(succ,
                                                    _getStateHash(succ),
                                                    current.Lookup(nextID).G + edgeCost,
                                                    heuristic(succ, target),
                                                    nextID, StateLocation.OpenReady);
                            }
                            else
                            {
                                current.AddOpenNode(succ,
                                                    _getStateHash(succ),
                                                    current.Lookup(nextID).G + edgeCost,
                                                    heuristic(succ, target),
                                                    nextID, StateLocation.OpenWaiting);
                            }

                            if (locReverse == StateLocation.OpenReady || locReverse == StateLocation.OpenWaiting)
                            {
                                if (FPUtil.Less(current.Lookup(nextID).G + edgeCost + opposite.Lookup(reverseLoc).G, _currentCost))
                                {
                                    _currentCost = current.Lookup(nextID).G + edgeCost + opposite.Lookup(reverseLoc).G;
                                    _middleNode  = succ;
                                }
                            }
                        }
                    }
                }
                break;
                }
            }
        }
Ejemplo n.º 22
0
Archivo: NBS.cs Proyecto: Treff/NBS
 public void SetForwardHeuristic(HCost <TState> h)
 {
     _forwardHeuristic = h;
 }
Ejemplo n.º 23
0
Archivo: NBS.cs Proyecto: Treff/NBS
 public void SetBackwardHeuristic(HCost <TState> h)
 {
     _backwardHeuristic = h;
 }
Ejemplo n.º 24
0
 public override int GetHashCode()
 {
     return((GCost.GetHashCode() + HCost.GetHashCode() + FCost.GetHashCode() + Position.GetHashCode()) * 26);
 }
Ejemplo n.º 25
0
        public int CompareTo(AStarNode other)
        {
            var dif = FCost.CompareTo(other.FCost);

            return(dif == 0 ? HCost.CompareTo(other.HCost) : dif);
        }