Пример #1
0
        /// <summary>
        /// Compute the weighted the distance for a given chromosome.
        /// </summary>
        public IEnumerable <StretchPair> GetPairsFor(StretchChromosome chromosome)
        {
            var positions = GetPositionsFor(chromosome).ToArray();

            for (var node1 = 0; node1 < Nodes.Length - 1; node1++)
            {
                var pos1 = positions[node1];
                var p1   = new StretchPosition {
                    Node = Nodes[node1], X = pos1.X, Y = pos1.Y
                };
                for (var node2 = node1 + 1; node2 < Nodes.Length; node2++)
                {
                    var pos2 = positions[node2];
                    var p2   = new StretchPosition {
                        Node = Nodes[node2], X = pos2.X, Y = pos2.Y
                    };
                    var weight = Nodes[node1].Weights[node2];
                    yield return(new StretchPair {
                        P1 = p1, P2 = p2, Weigth = weight
                    });
                }
            }
        }
Пример #2
0
 private static double Distance(StretchPosition p1, StretchPosition p2)
 {
     return(Math.Sqrt(Math.Pow(p1.X - p2.X, 2) + Math.Pow(p1.Y - p2.Y, 2)));
 }