示例#1
0
 public GradientProjectionMethod(Polygon[] pol, SemiinfiniteStrip s, double h, double w)
 {
     this.polygons = pol;
     this.st = s;
     this.height = h;
     this.width = w;
 }
示例#2
0
 public InitialEstimate(Polygon[] p, double h, double w)
 {
     this.polygons = p;
     this.height = h;
     this.width = w;
     ChangePolusAndVertices(ref polygons);
 }
示例#3
0
        public int[] DividingLine(int[] cond, Polygon[] polygons)
        {
            double a, b, c;
            int[] A = new int[2];
            A[0] = -1;
            List<double[]> pol1 = polygons[cond[0]].ListOfConvexPoligons[cond[1]];
            List<double[]> pol2 = polygons[cond[3]].ListOfConvexPoligons[cond[4]];

            for (int i = 0; i < pol1.Count; i++)
            {
                if (i != cond[2])
                {
                    double[] currentpoint = new double[2];

                    double[] x1 = pol1[i];
                    double[] x2 = polygons[cond[0]].NextElement(pol1[i], cond[1]);

                    bool check = true;
                    a = x1[1] - x2[1];
                    b = -x1[0] + x2[0];
                    c = -(polygons[cond[0]].polus[0] + x2[0]) * (x1[1] - x2[1]) + (x1[0] - x2[0]) * (polygons[cond[0]].polus[1] + x2[1]);
                    //c = -x1[0] * x2[1] + x2[0] * x1[1];
                    for (int j = 0; j < pol2.Count; j++)
                    {
                        currentpoint[0] = polygons[cond[3]].polus[0] + pol2[j][0];
                        currentpoint[1] = polygons[cond[3]].polus[1] + pol2[j][1];
                        if (Function(a, b, c, currentpoint) > 0)
                        {
                            check = false;
                            break;
                        }
                    }
                    if (check == true)
                    {
                        A[0] = i;
                        currentpoint[0] = polygons[cond[3]].polus[0] + pol2[0][0];
                        currentpoint[1] = polygons[cond[3]].polus[1] + pol2[0][1];
                        double min = Math.Abs(Function(a, b, c, currentpoint));
                        int m = 0;
                        for (int j = 1; j < pol2.Count; j++)
                        {
                            currentpoint[0] = polygons[cond[3]].polus[0] + pol2[j][0];
                            currentpoint[1] = polygons[cond[3]].polus[1] + pol2[j][1];
                            if (min > Math.Abs(Function(a, b, c, currentpoint)))
                            {
                                min = Math.Abs(Function(a, b, c, currentpoint));
                                m = j;
                            }

                        }
                        A[1] = m;
                        return A;
                    }
                }
            }

            return A;
        }
示例#4
0
        //выстраиваем многоугольники в полосу
        public void ChangePolusAndVertices(ref Polygon[] polygons)
        {
            polygons[0].polus[0] = -polygons[0].MinAndMax[0];
            polygons[0].polus[1] = -polygons[0].MinAndMax[1];
            for (int i = 1; i < polygons.Count(); i++)
            {
                polygons[i].polus[0] = polygons[i - 1].polus[0] + polygons[i - 1].MinAndMax[2] - polygons[i].MinAndMax[0] + 5;
                polygons[i].polus[1] = -polygons[i].MinAndMax[1];

            }
        }
示例#5
0
        //находим разделяющую прямую
        public int[] DividingLine(List<double[]> pol1, List<double[]> pol2, double[] polus1, Polygon P1, Polygon P2)
        {
            double a, b, c;
            int[] A = new int[2];
            A[0] = -1;

            for (int i = 0; i < pol1.Count; i++)
            {
                double[] currentpoint = new double[2];

                double[] x1 = pol1[i];
                double[] x2 = P1.NextElement(pol1[i], P1.ListOfConvexPoligons.IndexOf(pol1));

                bool check = true;
                a = x2[1] - x1[1];
                b = -x2[0] + x1[0];
                c = -(P1.polus[0] + x1[0]) * (x2[1] - x1[1]) + (x2[0] - x1[0]) * (P1.polus[1] + x1[1]);
                //c = -x1[0] * x2[1] + x2[0] * x1[1];
                for (int j = 0; j < pol2.Count; j++)
                {
                    currentpoint[0] = P2.polus[0] + pol2[j][0];
                    currentpoint[1] = P2.polus[1] + pol2[j][1];
                    if (Function(a, b, c, currentpoint) > 0)
                    {
                        check = false;
                        break;
                    }
                }
                if (check == true)
                {
                    A[0]=i;
                    currentpoint[0] = P2.polus[0] + pol2[0][0];
                    currentpoint[1] = P2.polus[1] + pol2[0][1];
                    double min = Math.Abs(Function(a, b, c, currentpoint));
                    int m=0;
                    for (int j = 1; j < pol2.Count; j++)
                    {
                        currentpoint[0] = P2.polus[0] + pol2[j][0];
                        currentpoint[1] = P2.polus[1] + pol2[j][1];
                        if (min > Math.Abs(Function(a, b, c, currentpoint)))
                        {
                            min = Math.Abs(Function(a, b, c, currentpoint));
                            m = j;
                        }

                    }
                    A[1] = m;
                    return A;
                }
            }
            return A;
        }
示例#6
0
        //заполняем матрицу ограничений
        private void FillMatrix(Polygon P1, Polygon P2)
        {
            int[] A = new int[2];
            for (int t = 0; t < P1.GetCountOfConvexPoligons(); t++)
            {
                for (int j = 0; j < P2.GetCountOfConvexPoligons(); j++)
                {
                    A = DividingLine(P1.ListOfConvexPoligons[t], P2.ListOfConvexPoligons[j], P1.polus, P1, P2);
                    if (A[0] != -1)
                    {

                        IntersectionConditions.Add(new List<int[]>());

                        IntersectionConditions[IntersectionConditions.Count - 1].Add(new int[3]);
                        IntersectionConditions[IntersectionConditions.Count - 1][IntersectionConditions[IntersectionConditions.Count - 1].Count - 1][0] = P1.number;
                        IntersectionConditions[IntersectionConditions.Count - 1][IntersectionConditions[IntersectionConditions.Count - 1].Count - 1][1] = t;
                        IntersectionConditions[IntersectionConditions.Count - 1][IntersectionConditions[IntersectionConditions.Count - 1].Count - 1][2] = A[0];

                        IntersectionConditions[IntersectionConditions.Count - 1].Add(new int[3]);
                        IntersectionConditions[IntersectionConditions.Count - 1][IntersectionConditions[IntersectionConditions.Count - 1].Count - 1][0] = P2.number;
                        IntersectionConditions[IntersectionConditions.Count - 1][IntersectionConditions[IntersectionConditions.Count - 1].Count - 1][1] = j;
                        IntersectionConditions[IntersectionConditions.Count - 1][IntersectionConditions[IntersectionConditions.Count - 1].Count - 1][2] = A[1];
                    }
                    else
                    {
                        A = DividingLine(P2.ListOfConvexPoligons[j], P1.ListOfConvexPoligons[t], P2.polus, P2, P1);
                        IntersectionConditions.Add(new List<int[]>());

                        IntersectionConditions[IntersectionConditions.Count - 1].Add(new int[3]);
                        IntersectionConditions[IntersectionConditions.Count - 1][IntersectionConditions[IntersectionConditions.Count - 1].Count - 1][0] = P2.number;
                        IntersectionConditions[IntersectionConditions.Count - 1][IntersectionConditions[IntersectionConditions.Count - 1].Count - 1][1] = j;
                        IntersectionConditions[IntersectionConditions.Count - 1][IntersectionConditions[IntersectionConditions.Count - 1].Count - 1][2] = A[0];

                        IntersectionConditions[IntersectionConditions.Count - 1].Add(new int[3]);
                        IntersectionConditions[IntersectionConditions.Count - 1][IntersectionConditions[IntersectionConditions.Count - 1].Count - 1][0] = P1.number;
                        IntersectionConditions[IntersectionConditions.Count - 1][IntersectionConditions[IntersectionConditions.Count - 1].Count - 1][1] = t;
                        IntersectionConditions[IntersectionConditions.Count - 1][IntersectionConditions[IntersectionConditions.Count - 1].Count - 1][2] = A[1];
                    }
                }
            }
        }
示例#7
0
         public int[] NewCond; //хранит разделяющую линию для пары выпуклых многоугольников

        public DoubleChangeCondition(int[] cond, Polygon[] polygons)
        {
            NewCond = new int[2];
            int[] A = DividingLine(cond, polygons);
            if (A[0] != -1)
            {
                NewCond = A;
            }
            else
            {

                int ll = cond[0];
                cond[0] = cond[3];
                cond[3] = ll;

                ll = cond[1];
                cond[1] = cond[4];
                cond[4] = ll;

                A = DividingLine1(cond, polygons);

                NewCond = A;
            }
        }
示例#8
0
文件: Form1.cs 项目: Ring-r/opt
        private void polygons3ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            iterator = 0;
            st.n = 8;
            polygons = new Polygon[st.n];

            Points = new List<double[]>[st.n];
            CopyPoints = new List<double[]>[st.n];
            p = new List<double[]>();
            for (int i = 0; i < st.n; i++)
            {
                if (i < 4)
                {
                    Points[i] = new List<double[]>();
                    CopyPoints[i] = new List<double[]>();
                    Read(ref Points[i], ref CopyPoints[i], ref p, "Polygon" + (i + 1) + "b.txt");

                    polygons[i] = new Polygon(Points[i], CopyPoints[i], i, p[i]);
                }
                else
                {
                    Points[i] = new List<double[]>();
                    CopyPoints[i] = new List<double[]>();
                    Read(ref Points[i], ref CopyPoints[i], ref p, "Polygon" + (i -3) + "b.txt");

                    polygons[i] = new Polygon(Points[i], CopyPoints[i], i, p[i]);
                }
            }
            grad = new GradientProjectionMethod(polygons, st, DrawPanel.Height, DrawPanel.Width);
            InitialEstimate ie = new InitialEstimate(polygons, DrawPanel.Height, DrawPanel.Width);
        }
示例#9
0
文件: Form1.cs 项目: Ring-r/opt
        private void polygons1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            iterator = 0;
            st.n = 20;
            polygons = new Polygon[st.n];

            Points = new List<double[]>[st.n];
            CopyPoints = new List<double[]>[st.n];
            p = new List<double[]>();
            for (int i = 0; i < st.n; i++)
            {
                //if (i < st.n)
                //{
                Points[i] = new List<double[]>();
                CopyPoints[i] = new List<double[]>();
                Read(ref Points[i], ref CopyPoints[i], ref p, "Polygon" + (i + 1) + ".txt");

                polygons[i] = new Polygon(Points[i], CopyPoints[i], i, p[i]);
                //}
                // else if((i>st.n-1)&&(i<2*st.n))
                // {
                //     Points[i] = new List<double[]>();
                //     CopyPoints[i] = new List<double[]>();
                //     Read(ref Points[i], ref CopyPoints[i], ref p, "Polygon" + (i - 19) + ".txt");

                //     polygons[i] = new Polygon(Points[i], CopyPoints[i], i, p[i]);

                // }
                //else
                //{
                //    Points[i] = new List<double[]>();
                //    CopyPoints[i] = new List<double[]>();
                //    Read(ref Points[i], ref CopyPoints[i], ref p, "Polygon" + (i - 39) + ".txt");

                //    polygons[i] = new Polygon(Points[i], CopyPoints[i], i, p[i]);

                //}
            }
            grad = new GradientProjectionMethod(polygons, st, DrawPanel.Height, DrawPanel.Width);
            InitialEstimate ie = new InitialEstimate(polygons, DrawPanel.Height, DrawPanel.Width);
        }
示例#10
0
        public List<List<int[]>> IntersectionConditions; //хранит разделяющие линии для пары выпуклых многоугольников

        public NonIntersectionConditions(Polygon P1, Polygon P2)
        {
            IntersectionConditions = new List<List<int[]>>();
            FillMatrix(P1, P2);
        }