Beispiel #1
0
        public ISolution NextPos()
        {
            // calculated using Euclidean Distance

            if (old == null)
            {
                InitPos();
            }

            // Calc gradient
            var grad = Grad(d0, d, old);

            // - grad * alpha
            foreach (var pt in grad)
            {
                pt[0] = -pt[0] * Alpha; // X
                pt[1] = -pt[1] * Alpha; // Y
            }
            // next_step = old - alpha * grad
            for (int k = 0; k < n; k++)
            {
                grad[k][0] += old.GetArgument()[k][0]; // X
                grad[k][1] += old.GetArgument()[k][1]; // Y
            }

            // save changes and return
            d   = MDS.CalcDistances(grad, MDS.EuclideanDistance);
            old = new Solution(fun, d0, d, n, grad);
            return(old);
        }
Beispiel #2
0
        public ISolution InitPos()
        {
            // random solution for start
            Random          r   = new Random();
            List <double[]> pts = new List <double[]>();

            for (int k = 0; k < n; k++)
            {
                pts.Add(new double[2] {
                    RndRange(r, min, max), RndRange(r, min, max)
                });
            }

            d = MDS.CalcDistances(pts, MDS.EuclideanDistance);

            old = new Solution(fun, d0, d, n, pts);
            return(old);
        }
Beispiel #3
0
        private ISolution NewSolution()
        {
            const double min = -1;
            const double max = 1;

            Random r = new Random();
            var    y = new List <double[]>();

            for (int j = 0; j < count; j++)
            {
                double[] _y = new double[dimY];

                for (int i = 0; i < dimY; i++)
                {
                    _y[i] = NextGaussian(r, 1, 1) * (Math.Abs(min) + Math.Abs(max)) + min; // r.NextDouble()
                }

                y.Add(_y);
            }

            return(new Solution(MDS.KruskalStress, d0, MDS.CalcDistances(y, MDS.EuclideanDistance), count, y));
        }