コード例 #1
0
            private static Tuple<int, double>[][] IOLinks_PostAdjust_BrainBrainLinks(Set2D[] brainSets)
            {
                // Get the AABB of the brain sets, and use the diagonal as the size
                var aabb = Math2D.GetAABB(brainSets.Select(o => o.Center));
                double maxDistance = (aabb.Item2 - aabb.Item1).Length;

                // Get links between the brains and distances of each link
                var links = Math2D.GetDelaunayTriangulation(brainSets.Select(o => o.Center).ToArray(), true).
                    Select(o => new { Brain1 = o.Item1, Brain2 = o.Item2, Distance = (brainSets[o.Item1].Center - brainSets[o.Item2].Center).Length }).

                    // break here, get stats on lengths, omit links that are excessively long

                    Select(o => new { Brain1 = o.Brain1, Brain2 = o.Brain2, Resistane = (o.Distance / maxDistance) * IOPOSTMERGE_LINKRESISTANCEMULT }).      // calculate the wire's resistance (in terms of burden)
                    ToArray();


                //string dots = string.Join("\r\n", brainSets.Select(o => string.Format("_linksIO2D.Add(AddDot(new Point({0}, {1}), Brushes.Black, Brushes.Gray));", o.Center.X, o.Center.Y)));
                //string lines = string.Join("\r\n", links.Select(o => string.Format("_linksIO2D.Add(AddLine(new Point({0}, {1}), new Point({2}, {3}), Brushes.White));", brainSets[o.Brain1].Center.X, brainSets[o.Brain1].Center.Y, brainSets[o.Brain2].Center.X, brainSets[o.Brain2].Center.Y)));
                //string combined = dots + "\r\n\r\n" + lines;

                Tuple<int, double>[][] retVal = new Tuple<int, double>[brainSets.Length][];

                for (int cntr = 0; cntr < brainSets.Length; cntr++)
                {
                    // Store all links for this brain
                    retVal[cntr] = links.
                        Where(o => o.Brain1 == cntr || o.Brain2 == cntr).       // find links between this brain and another
                        Select(o => Tuple.Create(o.Brain1 == cntr ? o.Brain2 : o.Brain1, o.Resistane)).     // store the link to the other brain and the resistance
                        ToArray();
                }

                return retVal;
            }
コード例 #2
0
            private static Tuple<int, double>[][] BrainBrainDistances(Set2D[] brainSets, double brainLinkResistanceMult)
            {
                // Get the AABB of the brain sets, and use the diagonal as the size
                var aabb = Math2D.GetAABB(brainSets.Select(o => o.Center));
                double maxDistance = (aabb.Item2 - aabb.Item1).Length;

                // Get links between the brains and distances of each link
                List<Tuple<int, int, double>> links2 = new List<Tuple<int, int, double>>();
                for (int outer = 0; outer < brainSets.Length - 1; outer++)
                {
                    for (int inner = outer + 1; inner < brainSets.Length; inner++)
                    {
                        double distance = (brainSets[outer].Center - brainSets[inner].Center).Length;
                        double resistance = (distance / maxDistance) * brainLinkResistanceMult;

                        links2.Add(Tuple.Create(outer, inner, resistance));
                    }
                }

                Tuple<int, double>[][] retVal = new Tuple<int, double>[brainSets.Length][];

                for (int cntr = 0; cntr < brainSets.Length; cntr++)
                {
                    // Store all links for this brain
                    retVal[cntr] = links2.
                        Where(o => o.Item1 == cntr || o.Item2 == cntr).       // find links between this brain and another
                        Select(o => Tuple.Create(o.Item1 == cntr ? o.Item2 : o.Item1, o.Item3)).     // store the link to the other brain and the resistance
                        OrderBy(o => o.Item2).
                        ToArray();
                }

                return retVal;
            }