示例#1
0
            public override string ToString()
            {
                string type = "internal node";

                if (IsRoot())
                {
                    type = "root";
                }
                if (IsLeaf())
                {
                    type = "leaf";
                }

                string childIds = string.Join(", ", Array.ConvertAll(ChildIds.ToArray(), (i) => { return(i.ToString()); }));

                return(string.Format(
                           "node {0}: parent = {1}, depth = {2}, {3}, [{4}]", Id, ParentId, Depth, type, childIds
                           ));
            }
示例#2
0
 public bool IsLeaf()
 {
     return(!IsRoot() && ChildIds.Count() == 0);
 }
示例#3
0
 public int LeftChildId()
 {
     return((ChildIds.Count() > 0) ? ChildIds[0] : -1);
 }
示例#4
0
        public ClustersState(ClusterSourceLine[] lines, State state)
        {
            ClusterIds = new Map <int[]>(state.Map.SizeX, state.Map.SizeY);
            Unwrapped  = new Dictionary <(int level, int clusterId), int>();
            Wrapped    = new Dictionary <(int level, int clusterId), int>();
            WrappedSq  = new Dictionary <(int level, int clusterId), int>();
            ChildIds   = new Dictionary <(int level, int clusterId), HashSet <int> >();
            RootIds    = new HashSet <int>();
            Path       = null;

            RootLevel = lines[0].cluster_hierarchy.Length - 1;

            foreach (var line in lines)
            {
                var p = new V(line.X, line.Y);
                ClusterIds[p] = line.cluster_hierarchy;
                if (state.Map[p] != CellState.Obstacle)
                {
                    for (int level = 0; level < line.cluster_hierarchy.Length; level++)
                    {
                        var clusterId  = line.cluster_hierarchy[level];
                        var clusterKey = (level, clusterId);

                        if (!Unwrapped.ContainsKey(clusterKey))
                        {
                            Unwrapped[clusterKey] = 0;
                        }
                        if (!Wrapped.ContainsKey(clusterKey))
                        {
                            Wrapped[clusterKey] = 0;
                        }
                        if (!WrappedSq.ContainsKey(clusterKey))
                        {
                            WrappedSq[clusterKey] = 0;
                        }

                        if (level == 0)
                        {
                            if (state.Map[p] == CellState.Void)
                            {
                                Unwrapped[clusterKey]++;
                            }
                            else
                            {
                                Wrapped[clusterKey]++;
                            }
                        }

                        if (state.Map[p] == CellState.Wrapped)
                        {
                            WrappedSq[clusterKey]++;
                        }

                        if (level == line.cluster_hierarchy.Length - 1)
                        {
                            RootIds.Add(clusterId);
                        }
                        else
                        {
                            var parentKey = (level + 1, line.cluster_hierarchy[level + 1]);
                            if (!ChildIds.ContainsKey(parentKey))
                            {
                                ChildIds[parentKey] = new HashSet <int>();
                            }
                            ChildIds[parentKey].Add(clusterId);
                        }
                    }
                }
            }

            for (int level = 1; level < lines[0].cluster_hierarchy.Length; level++)
            {
                foreach (var kvp in Unwrapped.Where(x => x.Key.level == level).ToList())
                {
                    Unwrapped[kvp.Key] = ChildIds[kvp.Key].Count(childId => Unwrapped[(level - 1, childId)] > 0);