Beispiel #1
0
        public double[] CrossOverAndMutation(double[] _weights, int _type, bool closer)
        {
            WeightsGenerator _wg = new WeightsGenerator();

            if (closer)
            {
                //oldweights = _weights;

                //Select some weights at random and record
                List <int> weightIndexes = new List <int>();

                for (int i = 0; i < _weights.Length / 5; i++)
                {
                    weightIndexes.Add(rng.Next(_weights.Length));
                }

                //shift values up/down by around 2%
                for (int i = 0; i < weightIndexes.Count; i++)
                {
                    _weights[weightIndexes[i]] = _weights[weightIndexes[i]] + rng.NextDouble();
                }

                weightIndexes.Clear();
            }
            else
            {
                _weights = _wg.CreateWeights(3, _weights.Length);
            }

            //on next pass check if closer, if not go the other way, if so, repeat.

            return(_weights);
        }
Beispiel #2
0
        public double[] CrossOverAndMutation(bool[] _evaluateFitnessResult, double[] _weights, int _type)
        {
            WeightsGenerator _wg = new WeightsGenerator();

            double[] _childWeights = new double[_weights.Length];

            for (int i = 0; i < _weights.Length; i++)
            {
                if (_evaluateFitnessResult[i])
                {
                    _childWeights[i] = _weights[i];
                }
                else
                {
                    _childWeights[i] = _wg.CreateWeights(_type, 1)[0];
                }
            }

            return(_childWeights);
        }
Beispiel #3
0
        public double[] GeneratePopulation(int _amount, int _type)
        {
            WeightsGenerator _wg = new WeightsGenerator();

            return(_wg.CreateWeights(_type, _amount));
        }