コード例 #1
0
        protected GraphNodeMetaData <T> GetMeta(T node, bool onlyExisting = false)
        {
            if (MetaDict.TryGetValue(node, out var meta))
            {
                return(meta);
            }
            if (onlyExisting)
            {
                throw new InvalidOperationException($"MetaDict data not found for {node}. The Equals or GetHashCode function on {typeof(T).Name} is likely invalid");
            }
            var fromCost = Traverser.RealCost(CurrentMetaData.Node, node);

            meta = new GraphNodeMetaData <T>(node, _nextGraphNodeId++)
            {
                ToCost     = Traverser.EstimatedCost(node, Destination),
                FromCost   = CurrentMetaData.FromCost + fromCost,
                Parent     = CurrentMetaData,
                PathLength = CurrentMetaData.PathLength + 1
            };
            MetaDict.Add(node, meta);
            // If the fromCost has a negative value, it is not actually traversable so
            // close the node to prevent it from being searched further.
            // TODO determine if this should actually be the case
            if (fromCost < 0)
            {
                meta.Status = NodeStatus.Closed;
            }
            return(meta);
        }
コード例 #2
0
        protected virtual void ProcessNeighbor(GraphNodeMetaData <T> neighborMetaData)
        {
            if (neighborMetaData.Status != NodeStatus.New)
            {
                return;
            }
            neighborMetaData.Status = NodeStatus.Open;
            var didAdd = OpenNodes.Add(ref neighborMetaData.Handle, neighborMetaData);

            Debug.Assert(didAdd, "Failed to add neighborNode to open nodes list. The comparer is probably invalid.");
        }
コード例 #3
0
 private void SetCurrentNode()
 {
     // get the best node, remove from open nodes, set to closed
     CurrentMetaData = OpenNodes.DeleteMin();
     ClosedCount++;
     CurrentMetaData.Status = NodeStatus.Closed;
     // check if this node is closest to the target
     if (CurrentMetaData.ToCost < _closest.ToCost)
     {
         _closest = CurrentMetaData;
     }
 }
コード例 #4
0
        protected SolverBase(T origin, T destination, INodeTraverser <T> traverser = null)
        {
            Origin      = origin ?? throw new ArgumentNullException(nameof(origin));
            Destination = destination ?? throw new ArgumentNullException(nameof(destination));
            Traverser   = traverser ??
                          GetDefaultTraverser(origin) ??
                          throw new ArgumentException("Either Traverser needs to be passed, or T must be an ITraversableNode", nameof(traverser));

            // create the origin node metadata manually as the "GetMeta" method
            // needs to use the CurrentMetaData
            CurrentMetaData = new GraphNodeMetaData <T>(origin, 0)
            {
                ToCost     = Traverser.EstimatedCost(origin, Destination),
                PathLength = 0,
            };
            OpenNodes = new C5.IntervalHeap <GraphNodeMetaData <T> >(this)
            {
                CurrentMetaData
            };
            _closest = CurrentMetaData;
            // set to 1 because the origin is node 0
            _nextGraphNodeId = 1;
        }
コード例 #5
0
 public bool Equals(GraphNodeMetaData <T> other) => other != null && Node.Equals(other.Node);
コード例 #6
0
 public abstract int Compare(GraphNodeMetaData <T> x, GraphNodeMetaData <T> y);