GetNumRows() public method

public GetNumRows ( ) : int
return int
Beispiel #1
0
        /**
         * ��ʼ������
         *
         * @param mtxCoef - ָ����ϵ������
         * @param mtxConst - ָ���ij�������
         * @return bool �ͣ���ʼ���Ƿ�ɹ�
         */
        public bool Init(Matrix mtxCoef, Matrix mtxConst)
        {
            if (mtxCoef.GetNumRows() != mtxConst.GetNumRows())
                return false;

            mtxLECoef = new Matrix(mtxCoef);
            mtxLEConst = new Matrix(mtxConst);

            return true;
        }
Beispiel #2
0
        public bool CalculateAssessment()
        {
            dgAssessment.Refresh();
            try
            {
                int Rows, Columns;//��¼����Ԫ�ص�����������
                Rows = dgAssessment.Rows.Count - 1;
                Columns = dgAssessment.Columns.Count - 1;

                lbState.Visible = true;
                pgBar.Visible = true;

                double[,] X = new double[Rows, Columns];
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = 0; j < Columns; j++)
                    {
                        if (isNumberic(dgAssessment.Rows[i + 1].Cells[j + 1].Value.ToString(), out X[i, j]))
                           ;
                        else
                            return false;
                    }
                }
                //��һ��
                double[,] S = new double[Rows, Columns];
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = 0; j < Columns; j++)
                    {
                        //object a=dgChooseSmallIndex.Rows[j].Cells[0].Value;
                        if (dgChooseSmallIndex.Rows[j].Cells[0].Value.ToString().Equals("True"))
                        {
                            S[i, j] = 1 / X[i, j];
                        }
                        else
                            S[i, j] = X[i, j];
                    }
                }
                lbState.Text = "���ڶ�ԭʼ���ݽ��й淶��";
                pgBar.Value = 10;
                //�ڶ���
                double[,] R = new double[Rows, Columns];
                double[] M = new double[Columns];
                double[] m = new double[Columns];
                for (int j = 0; j < Columns; j++)
                {
                    M[j] = S[0, j];
                    m[j] = S[0, j];
                    for (int i = 0; i < Rows; i++)
                    {
                        //object a=dgChooseSmallIndex.Rows[j].Cells[0].Value;
                        if (S[i, j] > M[j])
                        {
                            M[j] = S[i, j];
                        }
                        if (S[i, j] < m[j])
                        {
                            m[j] = S[i, j];
                        }
                    }
                }

                for (int i = 0; i < Rows; i++)
                {
                    for (int j = 0; j < Columns; j++)
                    {
                        //object a=dgChooseSmallIndex.Rows[j].Cells[0].Value;
                        R[i, j] = S[i, j] / m[j];
                    }
                }
                lbState.Text = "���ڼ����ۺ�����ֵ��ȡֵ��Χ";
                pgBar.Value = 25;
                //������
                double ��1 = dbInputFactor��1.Value;
                double[,] T = new double[Rows, Columns];
                double[] wu = new double[Columns];
                T = (double [,])R.Clone();
                for (int j = 0; j < Rows; j++)
                {
                    for (int i = 0; i < Columns; i++)
                    {
                        for (int k = i + 1; k < Columns; k++)
                        {
                            if (T[j, i] < T[j, k])
                            {
                                double temp = T[j, k];
                                T[j, k] = T[j, i];
                                T[j, i] = temp;
                            }
                        }
                    }
                }
                if (radioButton1.Checked)
                { //���ڡ�ǿȨ���Ƕ�������������
                    double temp = 0;
                    for (int i = 0; i < Columns - 2; i++)
                    {
                        wu[i] = Math.Pow(0.5, i + 1);
                        temp += wu[i];
                    }
                    wu[Columns - 2] = wu[Columns - 1] = 0.5 - 0.5 * temp;
                }
                else
                {//���ڡ���Ȩ���Ƕ�������������
                    wu[0] = 0.5;
                    wu[1] = 0.5 - (Columns - 2) * Math.Pow(0.5, Columns - 1);
                    for (int i = 2; i < Columns; i++)
                    {
                        wu[i] = Math.Pow(0.5, Columns - 1);
                    }
                }
                double[,] y = new double[Rows, 2];
                for (int i = 0; i < Rows; i++)
                {
                    double temp0 = 0, temp1 = 0, temp2 = 0, temp3 = 0, temp4 = 1, temp5= 1;
                    for (int j = 0; j < Columns; j++)
                    {
                        temp2 += wu[j] * T[i, Columns - j - 1];
                        temp3 += wu[j] * T[i, j];
                        //temp4 *= Math.Pow();
                        temp4 *= Math.Pow(T[i, Columns - j - 1], 1 / Columns);
                        temp5 *= Math.Pow(T[i, j], 1 / Columns);

                    }
                    temp0 = (��1 * temp2 + (1-��1) * temp4);
                    temp1 = (��1 * temp3 + (1-��1) * temp5);

                    y[i, 0] = temp0;
                    y[i, 1] = temp1;
                }
                lbState.Text = "���ڼ�������̷����ľ�����Ұ";
                pgBar.Value = 45;
                //���IJ�
                double[,] C_L = new double[Rows, Rows];
                double[,] C_U = new double[Rows, Rows];
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = i; j < Rows; j++)
                    {
                        intersection(y[i, 0], y[i, 1], y[j, 0], y[j, 1], out C_L[i, j], out C_U[i, j]);
                    }
                }

                double[,] d = new double[Rows, Rows];
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = i; j < Rows; j++)
                    {
                        if (i == j)
                        {
                            d[i, j] = 0;//���ﲻ֪��������ʲô��˼�����Ұ���0������
                        }
                        else
                        {
                            d[i, j] = d[j, i] = (C_U[i, j] - C_L[i, j]) / (Math.Max(y[i, 1], y[j, 1]) - Math.Min(y[i, 0], y[j, 0]));
                        }
                    }
                }
                lbState.Text = "���ڼ�������̷����ľ���ǿ��";
                pgBar.Value = 70;
                //���岽
                double[,] u = new double[Rows, Rows];
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = 0; j < Rows; j++)
                    {
                        if (i == j)
                        {
                            u[i, j] = 0;
                        }
                        else
                        {
                            double temp = 0;
                            for (int k = 0; k < Rows; k++)
                            {
                                temp += d[i, k];
                            }
                            u[i, j] = d[i, j] / temp;
                        }
                    }
                }
                lbState.Text = "���ڼ��㾺������עϵ������";
                pgBar.Value = 80;
                //������
                double �� = dbInputFactor��.Value;
                double[,] w = new double[Rows, Columns];
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = 0; j < Columns; j++)
                    {
                        double temp = 0;
                        for (int k = 0; k < Rows; k++)
                        {
                            if (k != i)
                            {
                                temp += R[k, j] * u[i, k];
                            }

                        }
                        w[i, j] = �� * R[i, j] - (1 - ��) * temp;
                    }
                }
                //���߲�
                lbState.Text = "���ڹ���滮���Ⲣ���";
                pgBar.Value = 90;
                double[,] wx = new double[Rows, Columns];//wx��ʾw*:xΪ�ǵ���˼
                //���ڡ�ǿȨ���Ƕ������������͡�ǿȨ���Ƕ�����������������һ���ģ�
                //��Ϊ��wx����wu��õģ���wu�Ѿ�ͨ������������á�
                ToBeOrdered[] orderNumber = new ToBeOrdered[Columns];
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = 0; j < Columns; j++)
                    {//�ȸ�ֵ
                        orderNumber[j].Index = j;
                        orderNumber[j].Value = w[i, j];
                    }
                    for (int j = 0; j < Columns; j++)
                    {//������
                        for (int k = j + 1; k < Columns; k++)
                        {
                            if (orderNumber[j].Value < orderNumber[k].Value)
                            {
                                ToBeOrdered temp = orderNumber[k];
                                orderNumber[k] = orderNumber[j];
                                orderNumber[j] = temp;
                            }
                        }

                    }
                    for (int j = 0; j < Columns; j++)
                    {//������
                        wx[i, orderNumber[j].Index] = wu[j];
                    }
                }
                //�ڰ˲�
                double[,] Y = new double[Rows, Rows];
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = 0; j < Rows; j++)
                    {
                        double  temp = 0, temp6 = 0, temp7 = 1;
                        for (int k = 0; k < Columns; k++)
                        {
                            //temp += wx[j, k] * R[i, k];

                            temp6 += wx[j, k] * R[i, k];
                            temp7 *= Math.Pow(R[i, k], 1 / Columns);

                        }
                        //Y[i, j] = temp;
                        temp = (��1 * temp6 + (1-��1) * temp7);
                        Y[i, j] = temp;

                    }
                }
                //�ھŲ�
                //������������������
                double[,] Y1 = new double[Rows, Rows];//���
                double[,] Y2 = new double[Rows, Rows];//�Ҳ�
                double[,] Y3 = new double[Rows, Rows];//���
                Y1 =(double [,]) Y.Clone();
                for (int i = 0; i < Rows; i++)
                {//����ת�þ���
                    for (int j = 0; j < Rows; j++)
                    {
                        Y2[i, j] = Y1[j, i];
                    }
                }
                for (int i = 0; i < Rows; i++)
                {//����Գƾ���
                    for (int j = 0; j < Rows; j++)
                    {
                        double temp = 0;
                        for (int k = 0; k < Rows; k++)
                        {
                            temp += Y1[i, k] * Y2[k, j];
                        }
                        Y3[i, j] = temp;
                    }
                }
                double[] Y4 = new double[Rows*Rows];//���ڼ������
                for (int i = 0; i < Rows; i++)
                {//���Գƾ���ת��Ϊһά����
                    for (int j = 0; j < Rows; j++)
                    {
                        Y4[i*Rows+j] = Y3[i, j];
                    }
                }
                //////////////////////////////////////////
                            // ʵ�Գ����Խ����ȫ������ֵ�����������ļ���
                Matrix mtx16 = new Matrix(Rows, Rows, Y4);

                Matrix mtxQ2 = new Matrix();//���غ�˹�ɶ��±任�ij˻�����Q
                Matrix mtxT2 = new Matrix();//������õĶԳ����Խ���
                double[] bArray2 = new double[mtx16.GetNumColumns()];//���ضԳ����Խ�������Խ���Ԫ��
                double[] cArray2 = new double[mtx16.GetNumColumns()];//ǰn-1��Ԫ�ط��ضԳ����Խ���ĴζԽ���Ԫ��
                double[] resultArray = new double[mtx16.GetNumColumns()];//��Ŧ˵Ľ��ֵ
                // 1: Լ���Գƾ���Ϊ�Գ����Խ���: ��˹�ɶ��±任��
                if (mtx16.MakeSymTri(mtxQ2, mtxT2, bArray2, cArray2))
                {
                    // 2: ����ȫ������ֵ����������
                    //bArray2:����Գ����Խ�������Խ���Ԫ��,����ʱ���ȫ������ֵ��
                    //cArray2:ǰn-1��Ԫ�ش���Գ����Խ���ĴζԽ���Ԫ��
                    //mtxQ2:���ؾ���A������ֵ�����������е�i��Ϊ������dblB�е�i������ֵ��Ӧ������������
                    //60:��������
                    //0.0001:���㾫��
                    if (mtx16.ComputeEvSymTri(bArray2, cArray2, mtxQ2, 60, 0.0001))
                    {
                        int tempi = 0;
                        double tempNum = bArray2[0];
                        for (int i = 0; i < mtxQ2.GetNumColumns(); ++i)
                        {//��������ֵ�������Ǹ�
                            if (tempNum < bArray2[i])
                            {
                                tempi = i;
                                tempNum = bArray2[i];
                            }
                        }
                        for (int i = 0; i < mtxQ2.GetNumRows(); ++i)
                        {
                            if(mtxQ2.GetElement(i,tempi)<0)
                            {//ȡ��ֵ
                                resultArray[i]=-mtxQ2.GetElement(i,tempi);
                            }
                            else
                            {
                                resultArray[i]=mtxQ2.GetElement(i,tempi);
                            }
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }

                //////////////////////////////////////////

                //��ʮ��
                double[,] x = new double[Rows, Rows];

                ToBeOrdered[] orderNumber2 = new ToBeOrdered[Rows];
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = 0; j < Rows; j++)
                    {//�ȸ�ֵ
                        orderNumber2[j].Index = j;
                        orderNumber2[j].Value = Y[j, i];//ע���Ƕ��н��в���
                    }
                    for (int j = 0; j < Rows; j++)
                    {//������
                        for (int k = j + 1; k < Rows; k++)
                        {
                            if (orderNumber2[j].Value < orderNumber2[k].Value)
                            {
                                ToBeOrdered temp = orderNumber2[k];
                                orderNumber2[k] = orderNumber2[j];
                                orderNumber2[j] = temp;
                            }
                        }
                    }
                    for (int j = 0; j < Rows; j++)
                    {//������
                        x[orderNumber2[j].Index, i] = j + 1;//ע��ֵԽ�����ԽС
                    }
                }
                //
                //��ʮһ��
                int[] orderResult = new int[Rows];//��Ŧ˵�����ֵ
                ToBeOrdered[] orderNumber3 = new ToBeOrdered[Rows];

                for (int j = 0; j < Rows; j++)
                {//�ȸ�ֵ
                    orderNumber3[j].Index = j;
                    orderNumber3[j].Value = resultArray[j];
                }
                for (int j = 0; j < Rows; j++)
                {//������
                    for (int k = j + 1; k < Rows; k++)
                    {
                        if (orderNumber3[j].Value < orderNumber3[k].Value)
                        {
                            ToBeOrdered temp = orderNumber3[k];
                            orderNumber3[k] = orderNumber3[j];
                            orderNumber3[j] = temp;
                        }
                    }
                }
                for (int j = 0; j < Rows; j++)
                {//������
                    orderResult[orderNumber3[j].Index] = j + 1;//ע��ֵԽ�����ԽС
                }

                //
                lbState.Text = "������ɣ�";
                pgBar.Value = 100;
                lbState.Visible = false;
                pgBar.Visible = false;

                FrmAssessResultshow result = new FrmAssessResultshow(x,orderResult);
                result.ShowDialog();
            }
            catch
            {
                return false;
            }

                return true;
        }
Beispiel #3
0
        /**
         * ʵ�־���ļ���
         *
         * @param other - ��ָ����������ľ���
         * @return Matrix�ͣ�ָ��������other���֮��
         * @����������/������ƥ�䣬����׳��쳣
         */
        public Matrix Subtract(Matrix other)
        {
            if (numColumns != other.GetNumColumns() ||
                numRows != other.GetNumRows())
                throw new Exception("�������/������ƥ�䡣");

            // ����������
            Matrix	result = new Matrix(this) ;		// ��������

            // ���������
            for (int i = 0 ; i < numRows ; ++i)
            {
                for (int j = 0 ; j <  numColumns; ++j)
                    result.SetElement(i, j, result.GetElement(i, j) - other.GetElement(i, j)) ;
            }

            return result ;
        }
Beispiel #4
0
        /**
         * ������ֵ
         *
         * @param other - ���ڸ�����ֵ��Դ����
         * @return Matrix�ͣ�����other���
         */
        public Matrix SetValue(Matrix other)
        {
            if (other != this)
            {
                Init(other.GetNumRows(), other.GetNumColumns());
                SetData(other.elements);
            }

            // finally return a reference to ourselves
            return this ;
        }
Beispiel #5
0
        /**
         * ������ij˷�
         *
         * @param AR - ��߸������ʵ������
         * @param AI - ��߸�������鲿����
         * @param BR - �ұ߸������ʵ������
         * @param BI - �ұ߸�������鲿����
         * @param CR - �˻��������ʵ������
         * @param CI - �˻���������鲿����
         * @return bool�ͣ�������˷��Ƿ�ɹ�
         */
        public bool Multiply(Matrix AR,  Matrix AI,  Matrix BR,  Matrix BI, Matrix CR, Matrix CI)
        {
            // ���ȼ���������Ƿ����Ҫ��
            if (AR.GetNumColumns() != AI.GetNumColumns() ||
                AR.GetNumRows() != AI.GetNumRows() ||
                BR.GetNumColumns() != BI.GetNumColumns() ||
                BR.GetNumRows() != BI.GetNumRows() ||
                AR.GetNumColumns() != BR.GetNumRows())
                return false;

            // ����˻�����ʵ��������鲿����
            Matrix mtxCR = new Matrix(AR.GetNumRows(), BR.GetNumColumns());
            Matrix mtxCI = new Matrix(AR.GetNumRows(), BR.GetNumColumns());
            // ���������
            for (int i=0; i<AR.GetNumRows(); ++i)
            {
                for (int j=0; j<BR.GetNumColumns(); ++j)
                {
                    double vr = 0;
                    double vi = 0;
                    for (int k =0; k<AR.GetNumColumns(); ++k)
                    {
                        double p = AR.GetElement(i, k) * BR.GetElement(k, j);
                        double q = AI.GetElement(i, k) * BI.GetElement(k, j);
                        double s = (AR.GetElement(i, k) + AI.GetElement(i, k)) * (BR.GetElement(k, j) + BI.GetElement(k, j));
                        vr += p - q;
                        vi += s - p - q;
                    }
                    mtxCR.SetElement(i, j, vr);
                    mtxCI.SetElement(i, j, vi);
                }
            }

            CR = mtxCR;
            CI = mtxCI;

            return true;
        }
Beispiel #6
0
        /**
         * ʵ�־���ij˷�
         *
         * @param other - ��ָ��������˵ľ���
         * @return Matrix�ͣ�ָ��������other���֮��
         * @����������/������ƥ�䣬����׳��쳣
         */
        public Matrix Multiply(Matrix other)
        {
            // ���ȼ���������Ƿ����Ҫ��
            if (numColumns != other.GetNumRows())
                throw new Exception("�������/������ƥ�䡣");

            // ruct the object we are going to return
            Matrix	result = new Matrix(numRows, other.GetNumColumns());

            // ����˷�����
            //
            // [A][B][C]   [G][H]     [A*G + B*I + C*K][A*H + B*J + C*L]
            // [D][E][F] * [I][J] =   [D*G + E*I + F*K][D*H + E*J + F*L]
            //             [K][L]
            //
            double	value ;
            for (int i = 0 ; i < result.GetNumRows() ; ++i)
            {
                for (int j = 0 ; j < other.GetNumColumns() ; ++j)
                {
                    value = 0.0 ;
                    for (int k = 0 ; k < numColumns ; ++k)
                    {
                        value += GetElement(i, k) * other.GetElement(k, j) ;
                    }

                    result.SetElement(i, j, value) ;
                }
            }

            return result ;
        }
Beispiel #7
0
 /**
  * �������캯��
  *
  * @param other - Դ����
  */
 public Matrix( Matrix other)
 {
     numColumns = other.GetNumColumns();
     numRows = other.GetNumRows();
     Init(numRows, numColumns);
     SetData(other.elements);
 }