コード例 #1
0
        public static IEnumerable <IPathNode <N> > GetReachableNodes <N>(N start, float maxCost) where N : INode <N>
        {
            C5.IDictionary <N, PathNode <N> > nodeDictionary = new C5.HashDictionary <N, PathNode <N> >();
            C5.IPriorityQueue <PathNode <N> > openSet        = new C5.IntervalHeap <PathNode <N> >(new PathNodeComparer <N>(), C5.MemoryType.Normal);
            C5.ICollection <N>            closedSet          = new C5.HashSet <N>();
            C5.ArrayList <IPathNode <N> > res = new C5.ArrayList <IPathNode <N> >(C5.MemoryType.Normal);


            PathNode <N> curNode = new PathNode <N>(start);

            curNode.g = 0;
            nodeDictionary.Add(start, curNode);
            while (true)
            {
                res.Add(curNode);
                foreach (IEdge <N> edge in curNode.node)
                {
                    N other = edge.GetEnd();
                    if (!closedSet.Contains(other))
                    {
                        PathNode <N> otherNode = null;
                        if (!nodeDictionary.Find(ref other, out otherNode))
                        {
                            otherNode = new PathNode <N>(other);
                            nodeDictionary.Add(other, otherNode);
                        }
                        float newG = edge.GetCost() + curNode.g;
                        if (otherNode.g > newG)
                        {
                            otherNode.g = newG;
                            if (otherNode.queueHandle != null)
                            {
                                openSet.Replace(otherNode.queueHandle, otherNode);
                            }
                            otherNode.prev = curNode;
                        }
                        if (otherNode.queueHandle == null)
                        {
                            C5.IPriorityQueueHandle <PathNode <N> > handle = null;
                            openSet.Add(ref handle, otherNode);
                            otherNode.queueHandle = handle;
                        }
                    }
                }
                if (openSet.IsEmpty)
                {
                    return(res);
                }
                closedSet.Add(curNode.node);
                curNode = openSet.DeleteMin();
                if (curNode.g > maxCost)
                {
                    return(res);
                }
            }
        }
コード例 #2
0
 static DocNet()
 {
     longtype2short    = new C5.HashDictionary <string, string>();
     cachedDocComments = new C5.HashDictionary <string, XmlNode>();
     longtype2short.Add("System.Boolean", "bool");
     longtype2short.Add("System.Byte", "byte");
     longtype2short.Add("System.Int32", "int");
     longtype2short.Add("System.Double", "double");
     longtype2short.Add("System.Void", "void");
     longtype2short.Add("System.Object", "object");
     longtype2short.Add("System.String", "string");
     longtype2short.Add("System.Collections.Generic.IEnumerable{T}", "IEnumerable{T}");
     longtype2short.Add("System.Collections.Generic.IEnumerable{U}", "IEnumerable{U}");
     //longtype2short.Add("", "");
 }
コード例 #3
0
        private HashSet <ISimEventHandle> GetEventsTo(ISimEntity simEntity)
        {
            HashSet <ISimEventHandle> hSet;

            if (_to2set.Contains(simEntity))
            {
                hSet = (HashSet <ISimEventHandle>)_to2set[simEntity];
            }
            else
            {
                hSet = new HashSet <ISimEventHandle>();
                _to2set.Add(simEntity, hSet);
            }
            return(hSet);
        }
コード例 #4
0
        DocNet(string a, string x, string defaultNamespace)
        {
            this.defaultNamespace = defaultNamespace;
            assembly = Assembly.LoadFrom(a, null);
            XmlDocument xml = new XmlDocument();

            xml.Load(x);
            assemblyName = xml.SelectSingleNode("doc/assembly/name").InnerXml;

            if (!assembly.FullName.StartsWith(assemblyName + ","))
            {
                throw new Exception("Wrong assembly specified!\n>> " + assembly.FullName + "\n>> " + assemblyName);
            }

            foreach (XmlNode node in xml.SelectNodes("doc/members/member"))
            {
                cachedDocComments.Add(node.SelectNodes("@name").Item(0).Value, node);
            }
        }
コード例 #5
0
 public void Add(K key, T value)
 {
     KToTMap.Add(key, value);
     TToKMap.Add(value, key);
 }
コード例 #6
0
ファイル: AStar.cs プロジェクト: v-free/hexMap
        public static IEnumerable <IPathNode <N> > GetShortestPath <N>(N start, N goal, IHeuristic <N> heuristic) where N : INode <N>
        {
            C5.IDictionary <N, PathNode <N> > nodeDictionary = new C5.HashDictionary <N, PathNode <N> >();
            C5.IPriorityQueue <PathNode <N> > openSet        = new C5.IntervalHeap <PathNode <N> >(new PathNodeComparer <N>());
            C5.ICollection <N> closedSet = new C5.HashSet <N>();

            PathNode <N> curNode = new PathNode <N>(start);

            curNode.g = 0;
            nodeDictionary.Add(start, curNode);
            while (true)
            {
                foreach (IEdge <N> edge in curNode.Node)
                {
                    N other = edge.GetEnd();
                    if (!closedSet.Contains(other))
                    {
                        PathNode <N> otherNode = null;
                        if (!nodeDictionary.Find(ref other, out otherNode))
                        {
                            otherNode = new PathNode <N>(other);
                            nodeDictionary.Add(other, otherNode);
                        }
                        float newG = edge.GetCost() + curNode.g;
                        if (otherNode.g > newG)
                        {
                            otherNode.g = newG;
                            if (otherNode.queueHandle != null)
                            {
                                openSet.Replace(otherNode.queueHandle, otherNode);
                            }
                            otherNode.prev = curNode;
                        }
                        if (otherNode.queueHandle == null)
                        {
                            otherNode.h = heuristic.MinDist(other, goal);
                            C5.IPriorityQueueHandle <PathNode <N> > handle = null;
                            openSet.Add(ref handle, otherNode);
                            otherNode.queueHandle = handle;
                        }
                    }
                }
                if (openSet.IsEmpty)
                {
                    return(null);
                }
                closedSet.Add(curNode.Node);
                curNode = openSet.DeleteMin();
                if (curNode.Node.Equals(goal))
                {
                    C5.ArrayList <IPathNode <N> > res = new C5.ArrayList <IPathNode <N> >();
                    do
                    {
                        res.Add(curNode);
                        curNode = curNode.prev;
                    } while (curNode != null);

                    res.Reverse();
                    return(res);
                }
            }
        }