Exemplo n.º 1
0
        static Node EquelNode(BranchNode root)
        {
            double currmoment = 0;

            for (int i = root.nodes.Count - 1; i >= 1; i--)
            {
                if (root.nodes.ElementAt(i - 1).Value is BranchNode)
                {
                    var equelnode = EquelNode(root.nodes.ElementAt(i - 1).Value as BranchNode);
                    root.nodes.ElementAt(i - 1).Value.power  = equelnode.power;
                    root.nodes.ElementAt(i - 1).Value.moment = equelnode.moment;
                }
                root.nodes.ElementAt(i - 1).Value.power += root.nodes.ElementAt(i).Value.power;
                currmoment += root.nodes.ElementAt(i).Value.power *root.nodes.ElementAt(i).Value.distance / 1000000;
                if (currmoment > root.nodes.ElementAt(i - 1).Value.moment)
                {
                    root.nodes.ElementAt(i - 1).Value.moment = currmoment;
                }
                else
                {
                    currmoment = root.nodes.ElementAt(i - 1).Value.moment;
                }
            }
            return(root.nodes.ElementAt(0).Value);
        }
Exemplo n.º 2
0
        public static double Moment(CableLine cable)
        {
            if (cable.polys.Count == 0 || cable.loads.Count == 0)
            {
                return(0);
            }

            var treelines = new List <BranchNode>();

            foreach (var poly in cable.polys)
            {
                var treeline = new BranchNode()
                {
                    poly = poly, nodes = new SortedDictionary <double, Node>()
                };
                treelines.Add(treeline);
            }

            for (int i = 0; i < treelines.Count; i++)
            {
                for (int j = 0; j < treelines.Count; j++)
                {
                    if (treelines[i].poly != treelines[j].poly && (Distance(treelines[i].poly.GetClosestPointTo(treelines[j].poly.StartPoint, false), treelines[j].poly.StartPoint) < 10 || Distance(treelines[i].poly.GetClosestPointTo(treelines[j].poly.EndPoint, false), treelines[j].poly.EndPoint) < 10))
                    {
                        if (Distance(treelines[i].poly.GetClosestPointTo(treelines[j].poly.EndPoint, false), treelines[j].poly.EndPoint) < 10)
                        {
                            ReversePoly(treelines[j].poly);
                        }
                        treelines[i].nodes.Add(treelines[i].poly.GetDistAtPoint(treelines[i].poly.GetClosestPointTo(treelines[j].poly.StartPoint, false)), treelines[j]);
                        treelines[j].ischild = true;
                    }
                }
            }
            foreach (var treeline in treelines)
            {
                foreach (var load in cable.loads)
                {
                    if (Distance(treeline.poly.GetClosestPointTo(load.position, false), load.position) < 10)
                    {
                        treeline.nodes.Add(treeline.poly.GetDistAtPoint(treeline.poly.GetClosestPointTo(load.position, false)), new Node {
                            power = load.power
                        });
                    }
                }
                treeline.nodes.Add(0, new Node());
            }

            foreach (var treeline in treelines)
            {
                treeline.nodes.ElementAt(0).Value.distance = treeline.nodes.ElementAt(0).Key;
                for (int i = 1; i < treeline.nodes.Count; i++)
                {
                    treeline.nodes.ElementAt(i).Value.distance = treeline.nodes.ElementAt(i).Key - treeline.nodes.ElementAt(i - 1).Key;
                }
            }

            var root = (from l in treelines where l.ischild == false select l).First();

            return(EquelNode(root).moment);
        }