Exemple #1
0
        public static string PrintTreeLevelWise(Common.Node <int> root)
        {
            var queue = new Queue <Node <int> >();

            queue.Enqueue(root);

            var builder = new StringBuilder();

            while (queue.Any())
            {
                var current = queue.Dequeue();

                builder.Append($"{current.Value} ");

                if (current.Left != null)
                {
                    queue.Enqueue(current.Left);
                }

                if (current.Right != null)
                {
                    queue.Enqueue(current.Right);
                }
            }

            return(builder.ToString().Trim());
        }
        public Path getAveragedCentroid()
        {
            // first, make a copy of all the paths in the cluster...
            List <Path> interpolatedPaths = new List <Path>();

            foreach (Path p in this)
            {
                interpolatedPaths.Add(new Path(p));                 // make a copy
            }

            double maxTime = Double.NegativeInfinity;

            foreach (Path p in this)
            {             // find the highest time value over all paths in this cluster
                foreach (Node n in p.points)
                {
                    if (n.tD > maxTime)
                    {
                        maxTime = n.tD;
                    }
                }
            }


            Node[] averagedNodes = new Node[interpolatedPaths[0].points.Count()];
            for (int count = 0; count < interpolatedPaths[0].points.Count(); count++)
            {
                averagedNodes[count] = new Node(0, 0, 0);
            }
            float avgDanger = 0f, avgLOS = 0f, avgNM = 0f;

            foreach (Path p in interpolatedPaths)
            {
                for (int count = 0; count < p.points.Count; count++)
                {
                    averagedNodes[count].x  += Math.Abs(p.points[count].x);
                    averagedNodes[count].y  += Math.Abs(p.points[count].y);
                    averagedNodes[count].t  += Math.Abs(p.points[count].t);
                    averagedNodes[count].xD += Math.Abs(p.points[count].xD);
                    averagedNodes[count].yD += Math.Abs(p.points[count].yD);
                    averagedNodes[count].tD += Math.Abs(p.points[count].tD);
                }
            }

            avgDanger /= interpolatedPaths.Count;
            avgLOS    /= interpolatedPaths.Count;
            avgNM     /= interpolatedPaths.Count;
            foreach (Node n in averagedNodes)
            {
                n.x  /= interpolatedPaths.Count;
                n.y  /= interpolatedPaths.Count;
                n.t  /= interpolatedPaths.Count;
                n.xD /= interpolatedPaths.Count;
                n.yD /= interpolatedPaths.Count;
                n.tD /= interpolatedPaths.Count;
            }

            Path averagedPath = new Path(new List <Node>(averagedNodes));

            return(averagedPath);
        }