Example #1
0
        private double Phi(Data data, Paramater param, DataType type)
        {
            double[] vector;
            switch (type)
            {
            case DataType.WithoutPosition:
                vector = new double[]
                {
                    (data.ForwardDistance - param.M[0]),
                    (data.LeftDistance - param.M[1]),
                    (data.RightDistance - param.M[2])
                };
                break;

            case DataType.WithPosition:
                vector = new double[]
                {
                    (data.X - param.M[0]),
                    (data.Y - param.M[1]),
                    (data.ForwardDistance - param.M[2]),
                    (data.LeftDistance - param.M[3]),
                    (data.RightDistance - param.M[4])
                };
                break;

            default:
                throw new ArgumentException();
            }

            double vectorDistancePower2 = CalculateDistancePower2(vector);
            double result = Math.Exp(-1 * vectorDistancePower2 / (2 * Math.Pow(param.Sigma, 2)));

            return(result);
        }
Example #2
0
        public Paramater Clone()
        {
            Paramater p = new Paramater()
            {
                W     = W,
                Sigma = Sigma
            };

            for (int i = 0; i < M.Count; i++)
            {
                p.M.Add(M[i]);
            }

            return(p);
        }
Example #3
0
        public void Crossover(Paramater other, bool far, int crossoverBit)
        {
            switch (far)
            {
            case false:
                if (crossoverBit == 0)
                {
                    var nums = CrossoverClose(Sigma, other.Sigma);
                    Sigma       = nums.Item1;
                    other.Sigma = nums.Item2;
                }
                else if (crossoverBit == 1)
                {
                    var nums = CrossoverClose(W, other.W);
                    W       = nums.Item1;
                    other.W = nums.Item2;
                }
                else
                {
                    int i    = crossoverBit - 2;
                    var nums = CrossoverClose(M[i], other.M[i]);
                    if (nums.Item1 > _MaxM)
                    {
                        M[i] = _MaxM * rand.NextDouble();
                    }
                    else if (nums.Item1 < _MinM)
                    {
                        M[i] = rand.NextDouble();
                    }
                    else
                    {
                        M[i] = nums.Item1;
                    }

                    if (nums.Item2 > _MaxM)
                    {
                        other.M[i] = _MaxM * rand.NextDouble();
                    }
                    else if (nums.Item1 < _MinM)
                    {
                        other.M[i] = rand.NextDouble();
                    }
                    else
                    {
                        other.M[i] = nums.Item2;
                    }
                }
                break;

            case true:
                if (crossoverBit == 0)
                {
                    var nums = CrossoverFar(Sigma, other.Sigma);
                    Sigma       = nums.Item1;
                    other.Sigma = nums.Item2;
                }
                else if (crossoverBit == 1)
                {
                    var nums = CrossoverFar(W, other.W);
                    W       = nums.Item1;
                    other.W = nums.Item2;
                }
                else
                {
                    int i    = crossoverBit - 2;
                    var nums = CrossoverFar(M[i], other.M[i]);

                    if (nums.Item1 > _MaxM)
                    {
                        M[i] = _MaxM * rand.NextDouble();
                    }
                    else if (nums.Item1 < _MinM)
                    {
                        M[i] = rand.NextDouble();
                    }
                    else
                    {
                        M[i] = nums.Item1;
                    }

                    if (nums.Item2 > _MaxM)
                    {
                        other.M[i] = _MaxM * rand.NextDouble();
                    }
                    else if (nums.Item1 < _MinM)
                    {
                        other.M[i] = rand.NextDouble();
                    }
                    else
                    {
                        other.M[i] = nums.Item2;
                    }
                }
                break;
            }
        }