当前位置: 首页>>代码示例>>C#>>正文


C# Matrix.GetMaxInRow方法代码示例

本文整理汇总了C#中System.Matrix.GetMaxInRow方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.GetMaxInRow方法的具体用法?C# Matrix.GetMaxInRow怎么用?C# Matrix.GetMaxInRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Matrix的用法示例。


在下文中一共展示了Matrix.GetMaxInRow方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NAPTStageOneHelper1

        // for steps 13-24 in stage one
        private static void NAPTStageOneHelper1(Matrix CAP, Matrix SRG, Matrix SRGC, Matrix PAN, Matrix UA11, Matrix CUA11, Vector AOC,
            ref Matrix DP1, ref Matrix FA1, int stage, Matrix AC)
        {
            // 13. Calculate the expected alliance matrix A11
            // Sum across rows of A11?
            Matrix A11 = new Matrix(CUA11.Rows, CUA11.Cols);
            if (stage == 1)
            {
                for (int i = 0; i < CUA11.Rows; i++)
                {
                    for (int j = 0; j < CUA11.Cols; j++)
                    {
                        if (i == j)
                            A11[i, j] = CAP[i, i];
                        else if (CUA11[i, j] == CUA11.GetMaxInRow(i))
                            A11[i, j] = CAP[j, j];
                        else
                            A11[i, j] = 0;
                    }
                }
            }
            else // stage 2 is different
            {
                for (int i = 0; i < CUA11.Rows; i++)
                {
                    for (int j = 0; j < CUA11.Cols; j++)
                    {
                        if (AC[i, j] > 0)
                            A11[i, j] = AC[i, j];
                        else if (CUA11[i, j] > 0)
                            A11[i, j] = CUA11[i, j];
                        else
                            A11[i, j] = 0;
                    }
                }
            }

            /*
            // 14. Update the AOC vector to AOC11
            Vector AOC11 = new Vector(AOC.Size);
            for (int i = 0; i < A11.Rows; i++)
            {
                if (A11.GetRowSum(i) >= AOC[i])
                    AOC11[i] = 0;
                else
                    AOC11[i] = AOC[i] - A11.GetRowSum(i);
            }
            */

            // 14. Update the AOC vector to AOC11
            //      (modified to compare to SRG CAP instead of AOC) -------- this one is correct ------
            Vector AOC11 = new Vector(AOC.Size);
            for (int i = 0; i < A11.Rows; i++)
            {
                if (A11.GetRowSum(i) >= SRGC.GetRowSum(i))
                    AOC11[i] = 0;
                else
                    AOC11[i] = SRGC.GetRowSum(i) - A11.GetRowSum(i);
            }

            // 17.  Subtract Sum(AOC12) - Sum(AOC11). If result is equal to zero, stop run and go back to step #x
            //      If the result is less than zero, repeat steps 11-16 by calculating UA13, CUA13, A13, AOC13
            //
            //      This method incorporates steps 15-16
            Matrix new_A = UpdateAOC(UA11, CUA11, AOC11, CAP, SRGC, A11, PAN, stage);

            // 18.  Generate an aliiance offer matrix AO1 which is a binarized version of A1x (where x is the number
            //      of the last A matrix

            //new_A.Binarize();

            // Recently updated as of 3:59AM 7/17/2012 (subject to change)

            Matrix AO1 = new Matrix(new_A.Rows, new_A.Cols);
            for (int i = 0; i < AO1.Rows; i++)
            {
                for (int j = 0; j < AO1.Cols; j++)
                {
                    if (i == j)
                        AO1[i, j] = 0;
                    else if (new_A[i, j] > 0)
                        AO1[i, j] = 1;
                    else
                        AO1[i, j] = 0;
                }
            }

            // 19. Transpose AO1
            Matrix AO1_T = AO1.GetTranspose();

            // 20. Generate a Defence Pacts matrix DP1 = AO1 * AO1'
            DP1 = new Matrix(AO1.Rows, AO1_T.Cols);
            for (int i = 0; i < AO1.Rows; i++)
                for (int j = 0; j < AO1_T.Cols; j++)
                    DP1[i, j] = AO1[i, j] * AO1_T[i, j];

            // 21. Generate an Allies of Enemies AE1 matrix AE1 = SRG x DP1
            Matrix AE1 = SRG * DP1;

//.........这里部分代码省略.........
开发者ID:Hydrologist,项目名称:msnp,代码行数:101,代码来源:NetworkFormationSimulation.cs

示例2: SimulateNAPTStageTwo

        private static Matrix SimulateNAPTStageTwo(Matrix FA1, Matrix SRG1, Matrix DP1, Matrix CAP, Matrix REL, Matrix UA11, int rowColSize, Matrix output, ref Matrix SRGOutput, ref Matrix EAOutput, int stage, string EAOutputFile, string outputfile, bool overwrite, bool EADyadic, bool outputDyadic, int networkid)
        {
            //int networkid = SRG1.NetworkId;
            // 2. Generate Allies of Enemies matrix AE2 = SRG1 x DP1
            Matrix AE2 = SRG1 * DP1;

            // 3. Generate SRG2
            Matrix SRG2 = new Matrix(rowColSize, rowColSize);
            for (int i = 0; i < SRG2.Rows; i++)
            {
                for (int j = 0; j < SRG2.Cols; j++)
                {
                    if (FA1[i, j] > 0)
                        SRG2[i, j] = 0;
                    else if (SRG1[i, j] == 1 || AE2[i, j] > 0)
                        SRG2[i, j] = 1;
                    else
                        SRG2[i, j] = 0;
                }
            }

            // 4. Generate an Allies Capabilities Matrix AC20 = DP1 * C.  Sum over rows of AC20
            // Method from excel sheet
            Matrix AC20 = new Matrix(rowColSize, rowColSize);
            for (int i = 0; i < rowColSize; i++)
            {
                for (int j = 0; j < rowColSize; j++)
                {
                    if (i == j || FA1[i, j] == 1)
                        AC20[i, j] = CAP[j, j];
                    else
                        AC20[i, j] = 0;
                }
            }

            // 5. Generate an SRG Capabilities Matrix SRGC20 = SRGC * C.  Sum across rows
            Matrix SRGC20 = new Matrix(rowColSize, rowColSize);
            for (int i = 0; i < rowColSize; i++)
            {
                for (int j = 0; j < rowColSize; j++)
                {
                    SRGC20[i, j] = SRG2[i, j] * CAP[j, j];
                }
            }

            // 6. Generate an Alliance Opportunity Cost Vector AOC20
            Vector AOC20 = new Vector(rowColSize);
            for (int i = 0; i < rowColSize; i++)
            {
                if (AC20.GetRowSum(i) >= SRGC20.GetRowSum(i))
                    AOC20[i] = 0;
                else
                    AOC20[i] = SRGC20.GetRowSum(i) - AC20.GetRowSum(i);
            }

            // 7. Generate a Potential Alliance Network T2 PAN2
            // method from excel sheet
            Matrix PAN2 = new Matrix(rowColSize, rowColSize);
            for (int i = 0; i < rowColSize; i++)
            {
                for (int j = 0; j < rowColSize; j++)
                {
                    if (i == j || FA1[i, j] > 0)
                        PAN2[i, j] = 0;
                    else
                        PAN2[i, j] = 1 - SRG2[i, j];
                }
            }

            // 8. Generate a Utility for Potential Ally matrix UA21 = PAN2 * UA11.  Calulate the max row for UA21
            /*
            Matrix UA21 = new Matrix(rowColSize, rowColSize);
            for (int i = 0; i < rowColSize; i++)
            {
                for (int j = 0; j < rowColSize; j++)
                {
                    if (i != j)
                        UA21[i, j] = PAN2[i, j] * UA11[i, j];
                    else
                        UA21[i, j] = 0;
                }
            }
            */
            Matrix UA21 = new Matrix(UA11);

            // 9. Calculate the Potential Ally Capabilities matrix CUA21
            // method from excel sheet
            Matrix CUA21 = new Matrix(rowColSize, rowColSize);
            for (int i = 0; i < rowColSize; i++)
            {
                for (int j = 0; j < rowColSize; j++)
                {
                    if (i != j && UA21[i, j] == UA21.GetMaxInRow(i))
                        CUA21[i, j] = CAP[j, j];
                    else
                        CUA21[i, j] = 0;
                }
            }

            Matrix DP2 = new Matrix(rowColSize, rowColSize);
//.........这里部分代码省略.........
开发者ID:Hydrologist,项目名称:msnp,代码行数:101,代码来源:NetworkFormationSimulation.cs

示例3: UpdateAOC

        private static Matrix UpdateAOC(Matrix _UA, Matrix _CUA, Vector _AOC, Matrix CAP, Matrix SRGC, Matrix _A, Matrix PAN, int stage)
        {
            double sum1 = 0;
            double sum2 = 0;

            // Calculate sum for AOC11
            for (int i = 0; i < _AOC.Size; i++)
                sum1 += _AOC[i];

            // Update the UA11 matrix into UA12 matrix
            Matrix UA = new Matrix(_CUA.Rows, _CUA.Cols);

            for (int i = 0; i < _CUA.Rows; i++)
            {
                for (int j = 0; j < _CUA.Cols; j++)
                {
                    if (_CUA[i, j] == _CUA.GetMaxInRow(i))
                        UA[i, j] = 0;
                    else
                    {
                        // excel sheet assigns value from _UA instead of _CUA
                        //UA[i, j] = _CUA[i, j];
                        UA[i, j] = _UA[i, j];
                    }
                }
            }

            // Generate a matrix CUA11
            Matrix CUA = new Matrix(UA.Rows, UA.Cols);
            if (stage == 1)
            {
                for (int i = 0; i < UA.Rows; i++)
                {
                    for (int j = 0; j < UA.Cols; j++)
                    {
                        if (UA[i, j] != UA.GetMaxInRow(i))
                            CUA[i, j] = 0;
                        else if (UA[i, j] == UA.GetMaxInRow(i) && PAN[i, j] > 0 && i != j) // needs PAN and i!=j conditions
                            CUA[i, j] = CAP[j, j];
                    }
                }
            }
            else // for the other stages
            {
                for (int i = 0; i < UA.Rows; i++)
                {
                    for (int j = 0; j < UA.Cols; j++)
                    {
                        if (UA[i, j] != UA.GetMaxInRow(i))
                            CUA[i, j] = 0;
                        else if (UA[i, j] == UA.GetMaxInRow(i) && UA[i, j] > 0 && i != j) // needs PAN and i!=j conditions
                            CUA[i, j] = CAP[j, j];
                    }
                }
            }

            // Calculate the expected alliance matrix A11
            //
            // ****** Calculated completely different in excel sheet ******
            //
            /*
            Matrix A = new Matrix(CUA.Rows, CUA.Cols);
            for (int i = 0; i < CUA.Rows; i++)
            {
                for (int j = 0; j < CUA.Cols; j++)
                {
                    if (i == j)
                        A[i, j] = CAP[i, i];
                    else if (CUA[i, j] == CUA.GetMaxInRow(i))
                        A[i, j] = CAP[j, j];
                    else
                        A[i, j] = 0;
                }
            }
            */

            // This version may be wrong; might need to use above version
            Matrix A = new Matrix(CUA.Rows, CUA.Cols);
            if (stage == 1)
            {
                for (int i = 0; i < CUA.Rows; i++)
                {
                    for (int j = 0; j < CUA.Cols; j++)
                    {
                        if (_A[i, j] > 0 || _AOC[i] == 0)
                            A[i, j] = _A[i, j];
                        else
                        {
                            if (CUA[i, j] > 0)
                                A[i, j] = CUA[i, j];
                            else
                                A[i, j] = 0;
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < CUA.Rows; i++)
                {
//.........这里部分代码省略.........
开发者ID:Hydrologist,项目名称:msnp,代码行数:101,代码来源:NetworkFormationSimulation.cs


注:本文中的System.Matrix.GetMaxInRow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。