Exemple #1
0
        /// <summary>
        /// Creates a node from a serialized definition
        /// </summary>
        public StretchNode(string definition)
        {
            var split = StretchParser.Tokens(definition);

            Name    = split[0];
            Weights = split.Skip(1).Select(x => int.Parse(x)).ToArray();
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:GeneticSharp.Extensions.Stretch.StretchFitness"/> class.
        /// </summary>
        /// <param name="definition">Definition.</param>
        public StretchFitness(string definition)
        {
            var rows  = StretchParser.Rows(definition);
            var sizes = StretchParser.Tokens(rows[0]);

            Width  = int.Parse(sizes[0]);
            Height = int.Parse(sizes[1]);
            Nodes  = rows.Skip(2).Select(r => new StretchNode(r)).ToArray();
            var sumOfAllWeights = Nodes.SelectMany(n => n.Weights).Sum() / 2;
            var gridDiagonal    = Math.Sqrt(Math.Pow(Width - 1, 2) + Math.Pow(Height - 1, 2));

            m_totalWeightedDistanceUpperBound = sumOfAllWeights * gridDiagonal;
        }