示例#1
0
 /// <summary>
 /// Gets the positions for a given chromosome
 /// </summary>
 public IEnumerable <StretchPosition> GetPositionsFor(StretchChromosome chromosome)
 {
     return(chromosome
            .GetGenes()
            .Select(g => (int)g.Value)
            .Select((index, i) => new StretchPosition {
         Node = Nodes[i], X = index % Width, Y = index / Width
     }));
 }
示例#2
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
                    });
                }
            }
        }
示例#3
0
 /// <summary>
 /// Compute the weighted the distance for a given chromosome.
 /// </summary>
 public double WeightedDistanceFor(StretchChromosome chromosome)
 {
     return(GetPairsFor(chromosome)
            .Select(p => p.Weigth * Distance(p.P1, p.P2))
            .Sum());
 }