Ejemplo n.º 1
0
        protected override Poligono CrossSolutions(Poligono poligono1, Poligono poligono2)
        {
            var point1 = r.Next(0, poligono1.Points.Count);
            var point2 = r.Next(0, poligono2.Points.Count);
            while (point2 == point1)
                point2 = r.Next(0, poligono2.Points.Count);
            var x1 = poligono1.Points[point1].PositionX;
            var y1 = poligono1.Points[point1].PositionY;
            var x2 = poligono2.Points[point2].PositionX;
            var y2 = poligono2.Points[point2].PositionY;
            var d = (int)Math.Sqrt(Math.Pow((x2 + x1) / 2 - x1, 2) + Math.Pow((y2 + y1) / 2 - y1, 2));
            bool positive;
            Poligono p = new Poligono(new Point(poligono1.Vertice1.PositionX, poligono1.Vertice1.PositionY), new Point(poligono1.Vertice2.PositionX, poligono1.Vertice2.PositionY),
                new Point(poligono1.Vertice3.PositionX, poligono1.Vertice3.PositionY), new Point(poligono1.Vertice4.PositionX, poligono1.Vertice4.PositionY));
            positive = (r.Next(0, 2) == 0) ? true : false;
            if (positive)
            {
                p.Points[point1].PositionX += d;
                p.Points[point1].PositionY += d;
                p.Points[point2].PositionX += d;
                p.Points[point2].PositionY += d;
            }
            else
            {
                p.Points[point1].PositionX -= d;
                p.Points[point1].PositionY -= d;
                p.Points[point2].PositionX -= d;
                p.Points[point2].PositionY -= d;
            }

            return updateVertexes(point1, point2, p);
        }
Ejemplo n.º 2
0
 protected override Poligono MutatePolygon(Poligono polygon)
 {
     var point = r.Next(0, polygon.Points.Count);
     Poligono p = new Poligono(new Point(polygon.Vertice1.PositionX, polygon.Vertice1.PositionY), new Point(polygon.Vertice2.PositionX, polygon.Vertice2.PositionY), new Point(polygon.Vertice3.PositionX, polygon.Vertice3.PositionY), new Point(polygon.Vertice4.PositionX, polygon.Vertice4.PositionY));
     p.Points[point].PositionX--;
     p.Points[point].PositionY--;
     return p;
 }
Ejemplo n.º 3
0
        private Poligono updateVertexes(int point1, int point2, Poligono p)
        {
            if (point1 == 0)
            {
                p.Vertice1.PositionX = p.Points[0].PositionX;
                p.Vertice1.PositionX = p.Points[0].PositionX;
            }
            else if (point1 == 1)
            {
                p.Vertice2.PositionX = p.Points[1].PositionX;
                p.Vertice2.PositionX = p.Points[1].PositionX;
            }
            else if (point1 == 2)
            {
                p.Vertice3.PositionX = p.Points[2].PositionX;
                p.Vertice3.PositionX = p.Points[2].PositionX;
            }
            else
            {
                p.Vertice4.PositionX = p.Points[3].PositionX;
                p.Vertice4.PositionX = p.Points[3].PositionX;
            }

            if (point2 == 0)
            {
                p.Vertice1.PositionX = p.Points[0].PositionX;
                p.Vertice1.PositionX = p.Points[0].PositionX;
            }
            else if (point2 == 1)
            {
                p.Vertice2.PositionX = p.Points[1].PositionX;
                p.Vertice2.PositionX = p.Points[1].PositionX;
            }
            else if (point2 == 2)
            {
                p.Vertice3.PositionX = p.Points[2].PositionX;
                p.Vertice3.PositionX = p.Points[2].PositionX;
            }
            else
            {
                p.Vertice4.PositionX = p.Points[3].PositionX;
                p.Vertice4.PositionX = p.Points[3].PositionX;
            }
            return p;
        }
Ejemplo n.º 4
0
 protected abstract Poligono MutatePolygon(Poligono polygon);
Ejemplo n.º 5
0
 protected abstract Poligono CrossSolutions(Poligono poligono1, Poligono poligono2);