Exemplo n.º 1
0
        public static Data EvaluationMME()
        {
            // Utworzenie obiektu data
            Data data = new Data();

            BoundaryList boundaryList = new BoundaryList();

            Reader.GetGeometry(@path, ref boundaryList);                       // Odczytywanie listy elementów brzegowych
            Reader.GetBoundaryConditionsMME(@path, ref boundaryList);          // Odczytywanie warunków brzegowych
            BoundaryNodeList bNodeList   = new BoundaryNodeList(boundaryList); // Utworzenie listy węzłów brzegowych
            ElementList      elementList = new ElementList(boundaryList);      // Utworzenie listy elementów brzegowych

            InternalPointList iPointList = constValue.MMEiternalPointList;
            BoundaryNodeList  nodeList   = new BoundaryNodeList(iPointList);        // Wyznaczanie listy węzłów dla elementów brzegowych

            double[,] G = Matrixs.GMatrix(nb, ref elementList, ref bNodeList, lam); // Wycznaczenie macierzy G
            double[,] H = Matrixs.HMatrix(nb, ref elementList, ref bNodeList);      // Wycznaczenie macierzy H
            double[,] B;

            double[,] A1 = Matrixs.A1MatrixMME(ref G, ref H, ref bNodeList);    // Wycznaczenie macierzy A1
            if (!GaussJordanElimination.gaussJordanElimination(A1, out B))
            {
                data.Error = "Macierz A1 jest nieodwracalna.\n\n"
                             + AuxiliaryFunctions.PrintArray(A1, (int)Math.Sqrt(A1.Length), (int)Math.Sqrt(A1.Length));
                data.binarySerialize(); // Zapis obiektu data do pliku binarnego
                return(data);
            }

            double[,] A2 = Matrixs.A2MatrixMME(ref G, ref H, ref bNodeList);    // Wycznaczenie macierzy A2

            double[,] Hw;
            double[,] Gw;
            if (BoundaryElement.ElemType == "Constant")
            {
                Hw = Matrixs.HdMatrix(nb, ref elementList, ref nodeList);
                Gw = Matrixs.GdMatrix(nb, ref elementList, ref nodeList, lam);
            }
            else
            {
                Hw = Matrixs.HMatrixForInternalPoints(nb, ref elementList, ref nodeList, ref bNodeList);
                Gw = Matrixs.GMatrixForInternalPoints(nb, ref elementList, ref nodeList, ref bNodeList, lam);
            }
            data.BoundaryList      = boundaryList;
            data.ElementList       = elementList;
            data.BoundaryNodeList  = bNodeList;
            data.IntenralPointList = iPointList;
            data.G   = G;
            data.Gw  = Gw;
            data.H   = H;
            data.Hw  = Hw;
            data.A1  = A1;
            data.B   = B;
            data.A2  = A2;
            data.R   = Matrixs.RMatrix(Gw, Hw, data.B, data.BoundaryNodeList, data.IntenralPointList);
            data.Dw  = Matrixs.DwMatrix(Gw, Hw, data.U, data.BoundaryNodeList, data.IntenralPointList);
            data.Dw1 = Matrixs.Dw1Matrix(Gw, Hw, data.BoundaryNodeList, data.IntenralPointList);
            data.W   = Matrixs.WMatrix(data.Hw, data.Gw, data.U, data.BoundaryNodeList, data.IntenralPointList);
            data.P   = Matrixs.PMatrix(data.BoundaryNodeList);
            data.E   = Matrixs.EMatrix(Gw, Hw, data.P, data.BoundaryNodeList, data.IntenralPointList);
            data.Z   = Matrixs.ZMatrix(data.Dw, data.P, data.E, data.BoundaryNodeList, data.IntenralPointList);
            data.Fd  = Matrixs.FdMatrix(data.Z, data.IntenralPointList);
            //double[] fff = { 11.327, 21.561, 25, 21.561, 11.327 };
            //data.Fd = fff;
            data.J  = Matrixs.JMatrix(data.BoundaryNodeList);
            data.S  = Matrixs.SMatrix(data.U, data.P, data.BoundaryNodeList);
            data.Pd = Matrixs.PdMatrix(data.U, data.J, data.S, data.BoundaryNodeList);
            data.C  = Matrixs.CMatrix(data.U, data.BoundaryNodeList);

            // WOLFE
            int n = (int)Math.Sqrt(data.C.Length);  // Ilość zmiennych decyzyjnych
            int m = (int)((data.W.Length / n) * 2); // Ilość ograniczeń

            double[,] A = new double[m, n];
            double[] b = new double[m];
            double[,] C;
            double[] p;
            if (precision == -1)
            {
                for (int i = 0; i < m / 2; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        A[i, j] = data.W[i, j];
                    }
                    b[i] = data.Fd[i] + epsilon;
                }
                for (int i = 0; i < m / 2; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        A[i + m / 2, j] = -data.W[i, j];
                    }
                    b[i + m / 2] = epsilon - data.Fd[i];
                }
                C = new double[n, n];
                p = new double[n];
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        C[i, j] = data.C[i, j];
                    }
                    p[i] = data.Pd[i];
                }
            }
            else
            {
                for (int i = 0; i < m / 2; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        A[i, j] = Math.Round(data.W[i, j], precision);
                    }
                    b[i] = Math.Round(data.Fd[i] + epsilon, precision);
                }
                for (int i = 0; i < m / 2; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        A[i + m / 2, j] = Math.Round(-data.W[i, j], precision);
                    }
                    b[i + m / 2] = Math.Round(epsilon - data.Fd[i], precision);
                }
                C = new double[n, n];
                p = new double[n];
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        C[i, j] = Math.Round(data.C[i, j], precision);
                    }
                    p[i] = Math.Round(data.Pd[i], precision);
                }
            }
            InitialTask    iTask = new InitialTask(n, m, C, p, A, b);
            SubstituteTask sTask = new SubstituteTask(iTask);
            Wolfe          wolfe = new Wolfe(sTask);

            wolfe.Evaluation();
            data.Error = wolfe.Error;
            if (data.Error == null)
            {
                AssignSolution(wolfe, ref data);
                MEB.EvaluationMEB(data);
            }
            // wolfe

            data.binarySerialize(); // Zapis obiektu data do pliku binarnego
            return(data);
        }
Exemplo n.º 2
0
        double[] fc;           // Wektor funkcji celu
        #endregion

        #region Konstruktory
        public SubstituteTask(InitialTask iTask)
        {
            this.n = iTask.N;
            this.m = iTask.N + iTask.M;
            this.q = iTask.M;
            this.r = 0;
            a      = new double[q, n];
            c      = new double[n, n];
            p      = new double[n];
            for (int i = 0; i < q; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    a[i, j] = iTask.A[i, j];
                }
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    c[i, j] = iTask.C[i, j];
                }
            }
            for (int j = 0; j < n; j++)
            {
                p[j] = iTask.P[j];
            }
            xdp = new double[q, q];
            for (int i = 0; i < q; i++)
            {
                for (int j = 0; j < q; j++)
                {
                    if (i == j)
                    {
                        xdp[i, j] = 1.0;
                    }
                    else
                    {
                        xdp[i, j] = 0.0;
                    }
                }
            }
            for (int i = 0; i < q; i++)
            {
                if (iTask.B[i] < 0.0)
                {
                    r++;
                    for (int j = 0; j < n; j++)
                    {
                        a[i, j] *= -1;
                    }
                    for (int j = 0; j < q; j++)
                    {
                        xdp[i, j] *= -1;
                    }
                }
            }
            ydp = new double[n, n];
            wd  = new double[n, n];
            vd  = new double[q, r];
            b   = new double[q];
            for (int i = 0; i < q; i++)
            {
                b[i] = Math.Abs(iTask.B[i]);
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (i == j)
                    {
                        ydp[i, j] = 1.0;
                        wd[i, j]  = 1.0;
                    }
                    else
                    {
                        ydp[i, j] = 0.0;
                        wd[i, j]  = 0.0;
                    }
                }
            }
            int ctr = 0;

            for (int i = 0; i < q; i++)
            {
                for (int j = 0; j < r; j++)
                {
                    vd[i, j] = 0.0;
                }
                if (iTask.B[i] < 0.0)
                {
                    vd[i, ctr++] = 1.0;
                }
            }

            md = new double[q + n, 3 * n + 2 * q + r];
            bd = new double[q + n];
            for (int i = 0; i < q + n; i++)   // Zerowanie M i B
            {
                bd[i] = 0.0;
                for (int j = 0; j < (3 * n + 2 * q + r); j++)
                {
                    md[i, j] = 0.0;
                }
            }
            for (int i = 0; i < q; i++)
            {
                bd[i] = Math.Abs(iTask.B[i]);
                for (int j = 0; j < n; j++)
                {
                    md[i, j] = a[i, j];
                }
            }
            for (int i = 0; i < n; i++)
            {
                bd[i + q] = iTask.P[i];
                for (int j = 0; j < n; j++)
                {
                    md[i + q, j] = 2 * c[i, j];
                }
            }
            for (int i = 0; i < q; i++)
            {
                for (int j = 0; j < q; j++)
                {
                    md[i, j + n] = xdp[i, j];
                }
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < q; j++)
                {
                    md[i + q, j + n + q] = iTask.A[j, i];
                }
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    md[i + q, j + n + 2 * q] = -ydp[i, j];
                }
            }
            for (int i = 0; i < q; i++)
            {
                for (int j = 0; j < r; j++)
                {
                    md[i, j + 2 * n + 2 * q] = vd[i, j];
                }
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    md[i + q, j + 2 * n + 2 * q + r] = wd[i, j];
                }
            }

            zd  = new string[3 * n + 2 * q + r];
            ctr = 0;
            for (int i = 0; i < n; i++)
            {
                zd[ctr++] = "x" + (i + 1).ToString();
            }
            for (int i = 0; i < q; i++)
            {
                zd[ctr++] = "x" + (i + 1).ToString() + "'";
            }
            for (int i = 0; i < q; i++)
            {
                zd[ctr++] = "y" + (i + 1).ToString();
            }
            for (int i = 0; i < n; i++)
            {
                zd[ctr++] = "y" + (i + 1).ToString() + "'";
            }
            for (int i = 0; i < r; i++)
            {
                zd[ctr++] = "v" + (i + 1).ToString();
            }
            for (int i = 0; i < n; i++)
            {
                zd[ctr++] = "w" + (i + 1).ToString();
            }
            baseValues   = new double[q + n];
            baseVariable = new string[q + n];
            ctr          = 0;
            for (int i = 0; i < q; i++)
            {
                for (int k = 0; k < r; k++)
                {
                    if (vd[i, k] == 1)
                    {
                        baseVariable[i] = zd[n + 2 * q + n + ctr++];
                    }
                }
                if (baseVariable[i] == null)
                {
                    baseVariable[i] = zd[n + i];
                }
            }
            for (int i = 0; i < n; i++)
            {
                baseVariable[i + q] = zd[n + q + m + r + i];
            }
            fc = new double[zd.Length];
            for (int i = 0; i < zd.Length; i++)
            {
                if (zd[i].IndexOf("v") >= 0 || zd[i].IndexOf("w") >= 0)
                {
                    fc[i] = 1.0;
                }
                else
                {
                    fc[i] = 0.0;
                }
            }
            for (int l = 0; l < q + n; l++)
            {
                for (int k = 0; k < zd.Length; k++)
                {
                    if (baseVariable[l] == zd[k])
                    {
                        baseValues[l] = fc[k];
                    }
                }
            }
        }