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


C# Matrix.CloneTo方法代码示例

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


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

示例1: SimulateNAPTStageTwo


//.........这里部分代码省略.........
            {
                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);
            Matrix FA2 = new Matrix(rowColSize, rowColSize);
            NAPTStageOneHelper1(CAP, SRG2, SRGC20, PAN2, UA21, CUA21, AOC20, ref DP2, ref FA2, stage, AC20);

            if (stage >= 10)
                FA2.NetworkId = int.Parse(networkid + "" + stage);
            else
                FA2.NetworkId = int.Parse(networkid + "0" + stage);
            for (int i = 0; i < FA1.Rows; i++)
            {
                FA2.RowLabels[i] = FA1.RowLabels[i];
                FA2.ColLabels[i] = FA1.ColLabels[i];
            }
            // write FA2 to matrix file
            // Set network ID and row and col labels first
            if (!EADyadic)
                MatrixWriter.WriteMatrixToMatrixFile(FA2, EAOutputFile, overwrite);
            else
                MatrixWriter.WriteMatrixToDyadicFile(FA2, EAOutputFile, overwrite);
            //overwrite = false;

            Matrix M2 = FA2 - FA1;
            if (M2.IsAllZero)
            {
                // done?
                EAOutput = FA2;
                for (int i = 0; i < output.Rows; i++)
                {
                    output.RowLabels[i] = (int.Parse(networkid + "0" + stage)).ToString();
                }
                if (!outputDyadic)
                    MatrixWriter.WriteMatrixToMatrixFile(output, outputfile, overwrite);
                else
                    MatrixWriter.WriteMatrixToDyadicFile(output, outputfile, overwrite);
                return output; // for now
            }
            else
            {
                // need to unbinarize FA2 first
                Matrix Temp = new Matrix(FA2);
                // argument needs to be UA11 and not UA12 (according to excel)
                Matrix new_output = NAPTStageOneHelper2(CAP, SRG2, FA2, UA11, REL, AOC20, stage, networkid);

                // write new_output to matrix file
                if (!outputDyadic)
                    MatrixWriter.WriteMatrixToMatrixFile(new_output, outputfile, overwrite);
                else
                    MatrixWriter.WriteMatrixToDyadicFile(new_output, outputfile, overwrite);

                // Copy the data from SRG2 to SRGOutput
                SRGOutput.Clear();
                for (int i = 0; i < SRG2.Rows; i++)
                    for (int j = 0; j < SRG2.Cols; j++)
                        SRGOutput[i, j] = SRG2[i, j];
                SRGOutput.NetworkId = new_output.NetworkId;
                FA2.Clear();
                Temp.CloneTo(FA2);
                return SimulateNAPTStageTwo(FA2, SRG1, DP2, CAP, REL, UA11, rowColSize, new_output, ref SRGOutput, ref EAOutput, stage + 1, EAOutputFile, outputfile, overwrite, EADyadic, outputDyadic, networkid);
            }
        }
开发者ID:Hydrologist,项目名称:msnp,代码行数:101,代码来源:NetworkFormationSimulation.cs

示例2: SimulateNAPTStageOne


//.........这里部分代码省略.........

            // 4. Generate an Enemy of Enemy matrix (EE) and binarize it
            Matrix EE = new Matrix(MID * MID);

            // 5. Generate a potential alliance network matrix PAN
            Matrix PAN = new Matrix(SRG.Rows, SRG.Cols);
            for (int i = 0; i < SRG.Rows; i++)
                for (int j = 0; j < SRG.Cols; j++)
                    PAN[i, j] = 1 - SRG[i, j];

            // 6. Generate a joint democracy matrix (DD)
            Matrix DD = new Matrix(DEMO.Rows, DEMO.Cols);
            for (int i = 0; i < DEMO.Rows; i++)
                for (int j = 0; j < DEMO.Cols; j++)
                    DD[i, j] = DEMO[i, i] * DEMO[j, j];

            // 7. Generate a contiguity to SRG matrix (SRGCT)
            Matrix SRGCT = SRG * CONT;

            // 8. Binarize the EE matrix
            // 9. Binarize the DD matrix
            // 10. Binarize the SRGCT matrix
            EE.Binarize();
            DD.Binarize();
            SRGCT.Binarize();

            // 11. Generate a Utility for Potential Ally matrix UA11
            Matrix UA11 = new Matrix(PAN.Rows, PAN.Cols);
            double[] maxRowUA11 = new double[UA11.Rows];
            for (int i = 0; i < PAN.Rows; i++)
            {
                double cur_max = double.MinValue; // find max value in row
                for (int j = 0; j < PAN.Cols; j++)
                {
                    if (i == j || PAN[i, j] == 0)
                        UA11[i, j] = 0;
                    else if (DEMO[i, i] == 1 && PAN[i, j] == 1)
                        UA11[i, j] = (0.2 * EE[i, j]) + (0.4 * DD[i, j]) + (0.1 * JC[i, j]) + (0.1 * CS[i, j]) + (0.2 * SRGCT[i, j]);
                    else if (DEMO[i, i] == 0 && PAN[i, j] == 1)
                        UA11[i, j] = (0.5 * EE[i, j]) + (0.1 * DD[i, j]) + (0.1 * JC[i, j]) + (0.1 * CS[i, j]) + (0.2 * SRGCT[i, j]);

                    if (UA11[i, j] > cur_max)
                        cur_max = UA11[i, j];
                }
                maxRowUA11[i] = cur_max;
            }

            // 12. Generate a matrix CUA11
            Matrix CUA11 = new Matrix(UA11.Rows, UA11.Cols);
            double[] maxRowCUA11 = new double[CUA11.Rows];
            for (int i = 0; i < UA11.Rows; i++)
            {
                double cur_max = double.MinValue; // find max value in row
                for (int j = 0; j < UA11.Cols; j++)
                {
                    if (UA11[i, j] != maxRowUA11[i])
                        CUA11[i, j] = 0;
                    else if (UA11[i, j] == maxRowUA11[i] && PAN[i, j] > 0 && i != j) // needs PAN and i!=j conditions
                        CUA11[i, j] = CAP[j, j];

                    if (CUA11[i, j] > cur_max)
                        cur_max = CUA11[i, j];
                }
                maxRowCUA11[i] = cur_max;
            }

            Matrix DP1 = new Matrix(UA11.Rows, UA11.Cols);
            Matrix FA1 = new Matrix(UA11.Rows, UA11.Cols);
            NAPTStageOneHelper1(CAP, SRG, SRGC, PAN, UA11, CUA11, AOC, ref DP1, ref FA1, stage, null);

            // write FA1 to matrix file
            FA1.NetworkId = int.Parse(networkid + "0" + stage);
            //FA1.NetworkId = SRG.NetworkId + 1;
            //int.Parse(editedNetworkId + "01");
            for (int i = 0; i < SRG.Rows; i++)
            {
                FA1.RowLabels[i] = SRG.RowLabels[i];
                FA1.ColLabels[i] = SRG.ColLabels[i];
            }
            if (!EADyadic)
                MatrixWriter.WriteMatrixToMatrixFile(FA1, EAOutputFile, overwrite);
            else
                MatrixWriter.WriteMatrixToDyadicFile(FA1, EAOutputFile, overwrite);
            //overwrite = false;

            Matrix Temp = new Matrix(FA1);
            Matrix Output = NAPTStageOneHelper2(CAP, SRG, FA1, UA11, REL, AOC, stage, networkid);

            // write Output to matrix file
            if (!outputDyadic)
                MatrixWriter.WriteMatrixToMatrixFile(Output, outputfile, overwrite);
            else
                MatrixWriter.WriteMatrixToDyadicFile(Output, outputfile, overwrite);
            overwrite = false;

            FA1.Clear();
            Temp.CloneTo(FA1);

            return SimulateNAPTStageTwo(FA1, SRG, DP1, CAP, REL, UA11, SRG.Rows, Output, ref SRGOutput, ref EAOutput, stage + 1, EAOutputFile, outputfile, overwrite, EADyadic, outputDyadic, networkid);
        }
开发者ID:Hydrologist,项目名称:msnp,代码行数:101,代码来源:NetworkFormationSimulation.cs

示例3: SimulateSimplifiedRealistStageTwo

        private static Matrix SimulateSimplifiedRealistStageTwo(Matrix C, Matrix R, Matrix M, Matrix BEA, string outputFile, string srgOutputFile, int networkID, bool outputDyadic, bool srgDyadic, int maxIter, double br)
        {
            int stage = 2;
            Matrix Temp = new Matrix(C.Rows);
            BEA.CloneTo(Temp);
            //Matrix OriginalR = new Matrix(C.Rows);
            //R.CloneTo(OriginalR);
            Matrix BEA2 = UpdateSimplifiedRealistStageTwo(C, R, M, BEA, outputFile, br);
            BEA2.CopyLabelsFrom(C);
            BEA2.NetworkId = int.Parse(networkID + "02");
            R.NetworkId = BEA2.NetworkId;

            while (!BEA2.IsSameAs(Temp) && (stage <= maxIter))
            {
                if (!outputDyadic)
                    MatrixWriter.WriteMatrixToMatrixFile(BEA2, outputFile, false);
                else
                    MatrixWriter.WriteMatrixToDyadicFile(BEA2, outputFile, false);
                if (!srgDyadic)
                    MatrixWriter.WriteMatrixToMatrixFile(R, srgOutputFile, false);
                else
                    MatrixWriter.WriteMatrixToDyadicFile(R, srgOutputFile, false);
                //Matrix OriginR = new Matrix(C.Rows);
                //R.CloneTo(OriginR);
                BEA.CloneTo(Temp);
                BEA2.CloneTo(BEA);
                BEA2 = UpdateSimplifiedRealistStageTwo(C, R, M, BEA, outputFile, br);
                stage++;
                BEA2.NetworkId = int.Parse(networkID + "" + (stage >= 10 ? stage + "" : "0" + stage + ""));
                R.NetworkId = BEA2.NetworkId;
                BEA2.CopyLabelsFrom(C);
            }
            return BEA2;
        }
开发者ID:Hydrologist,项目名称:msnp,代码行数:34,代码来源:NetworkFormationSimulation.cs

示例4: UpdateSimplifiedRealistStageTwo

        /// <summary>
        /// Simulates stage two of the realist network formation simulation.
        /// </summary>
        /// <param name="C">Capability matrix for stage two</param>
        /// <param name="R">Policy relevance matrix (SRG)</param>
        /// <param name="EAF">EAF matrix from stage one</param>
        /// <param name="M">MID matrix</param>
        /// <returns>Expected alliance matrix</returns>
        /// <returns>EA matrix for stage two</returns>
        private static Matrix UpdateSimplifiedRealistStageTwo(Matrix C, Matrix R, Matrix M, Matrix BEA, string outputFile, double br)
        {
            int n = C.Rows;

            Matrix AE = M * BEA;

            for (int i = 0; i < n; ++i)
                for (int j = 0; j < n; ++j)
                {
                    if (R[i, j] == 1 || AE[i, j] > 0 ) R[i, j] = 1;
                    else R[i, j] = 0;
                }

            R.ZeroDiagonal();
            Matrix SRC = R * C;

            Vector SRGC = new Vector(n);
            for (int i = 0; i < n; ++i)
                SRGC[i] = SRC.GetRowSum(i) * br;

            Matrix EAC = BEA * C;

            Vector AOC = new Vector(n);
            for (int i = 0; i < n; ++i)
            {
                if (EAC.GetRowSum(i) + C[i, i] >= SRGC[i]) AOC[i] = 0;
                else AOC[i] = 1 - ((EAC.GetRowSum(i) + C[i, i]) / SRGC[i]);
            }

            Matrix F = Matrix.Ones(n, n);
            F.ZeroDiagonal();
            Matrix PAN = F - R;
            Matrix PAC = PAN * C;

            Matrix EE = M * M;
            EE.ZeroDiagonal();
            for (int i = 0; i < n; ++i)
                for (int j = 0; j < n; ++j)
                    if (EE[i, j] != 0) EE[i, j] = 1;

            Matrix EEC = EE * C;

            Vector EEM = new Vector(n);

            for (int i = 0; i < n; ++i)
                EEM[i] = Algorithms.MaxValue<double>(EEC.GetRowEnumerator(i));

            Matrix EA = new Matrix(n, n);

            for (int i = 0; i < n; ++i)
                for (int j = 0; j < n; ++j)
                    if (EAC[i, j] > 0 || AOC[i] <= 0)
                        EA[i, j] = EAC[i, j];
                    else if (PAN[i, j] > 0 && EEC[i, j] == EEM[i])
                        EA[i, j] = EEC[i, j];
                    else
                        EA[i, j] = 0;

            //Copied from Stage 1

            Vector SEA = new Vector(n);

            Matrix previousEA = new Matrix(n);

            Matrix TempEEC = new Matrix(n);

            EEC.CloneTo(TempEEC);

            do
            {

                EA.CloneTo(previousEA);

                for (int i = 0; i < n; ++i)
                    SEA[i] = EA.GetRowSum(i) + C[i, i];

                for (int i = 0; i < n; ++i)
                {
                    if (SRGC[i] <= SEA[i]) AOC[i] = 0;
                    else AOC[i] = 1 - SEA[i] / SRGC[i];
                }

                for (int i = 0; i < n; ++i)
                    for (int j = 0; j < n; ++j)
                        if (EEC[i, j] == EEM[i]) EEC[i, j] = 0;

                for (int i = 0; i < n; ++i)
                    EEM[i] = Algorithms.MaxValue<double>(EEC.GetRowEnumerator(i));

                for (int i = 0; i < n; ++i)
                    for (int j = 0; j < n; ++j)
//.........这里部分代码省略.........
开发者ID:Hydrologist,项目名称:msnp,代码行数:101,代码来源:NetworkFormationSimulation.cs

示例5: SimulateSimplifiedRealistStageOne

        /// <summary>
        /// Simulates stage one of the SIMPLIFIED realist network formation simulation.
        /// </summary>
        /// <param name="C">Capability matrix</param>
        /// <param name="R">Policy relevance matrix (SRG)</param>
        /// <param name="M">MID matrix</param>
        /// <returns>Expected alliance matrix</returns>
        private static Matrix SimulateSimplifiedRealistStageOne(Matrix C, Matrix R, Matrix M, string outputFile, double br)
        {
            int n = C.Rows;
            Matrix SRC = R * C;
            Vector SRGC = new Vector(n);
            for (int i = 0; i < n; ++i)
                SRGC[i] = SRC.GetRowSum(i) * br;
            Vector AOC = new Vector(n);
            for (int i = 0; i < n; ++i)
            {
                if (SRGC[i] <= C[i, i]) AOC[i] = 0;
                else AOC[i] = 1 - C[i, i] / SRGC[i];
            }

            Matrix F = Matrix.Ones(n, n);
            F.ZeroDiagonal();
            Matrix PAN = F - R;
            Matrix PAC = PAN * C;

            Matrix EE = M * M;
            EE.ZeroDiagonal();
            for (int i = 0; i < n; ++i)
                for (int j = 0; j < n; ++j)
                    if (EE[i, j] != 0) EE[i, j] = 1;

            Matrix EEC = EE * C;
            Vector EEM = new Vector(n);

            for (int i = 0; i < n; ++i)
                EEM[i] = Algorithms.MaxValue<double>(EEC.GetRowEnumerator(i));

            Matrix EA = new Matrix(n, n);

            for (int i = 0; i < n; ++i)
                for (int j = 0; j < n; ++j)
                    if (EEC[i, j] == EEM[i] && PAN[i, j] == 1 && AOC[i] != 0)
                        EA[i, j] = EEC[i, j];
                    else
                        EA[i, j] = 0;

            Vector SEA = new Vector(n);

            Matrix previousEA = new Matrix(n);

            do
            {

                EA.CloneTo(previousEA);

                for (int i = 0; i < n; ++i)
                    SEA[i] = EA.GetRowSum(i) + C[i, i];

                for (int i = 0; i < n; ++i)
                {
                    if (SRGC[i] <= SEA[i]) AOC[i] = 0;
                    else AOC[i] = 1 - SEA[i] / SRGC[i];
                }

                for (int i = 0; i < n; ++i)
                    for (int j = 0; j < n; ++j)
                        if (EEC[i, j] == EEM[i]) EEC[i, j] = 0;

                for (int i = 0; i < n; ++i)
                    EEM[i] = Algorithms.MaxValue<double>(EEC.GetRowEnumerator(i));

                for (int i = 0; i < n; ++i)
                    for (int j = 0; j < n; ++j)
                    {
                        //if (AOC[i] != 0 && EEC[i, j] == EEM[i] && EA[i, j] == 0)
                        //    EA[i, j] = EEC[i, j];

                        if (AOC[i] == 0 || EA[i, j] != 0);
                        else if (PAN[i, j] > 0 && EEC[i, j] == EEM[i])
                            EA[i, j] = EEC[i, j];
                        else EA[i, j] = 0;
                    }

            } while ((!previousEA.IsSameAs(EA)) && !EEC.IsAllZero && !AOC.IsZeroVector);

            if (!AOC.IsZeroVector)
            {

                for (int i = 0; i < n; ++i)
                    for (int j = 0; j < n; ++j)
                        if (PAC[i, j] > 0 && EEC[i, j] != 0) PAC[i, j] = 0;

                Vector PAM = new Vector(n);

                for (int i = 0; i < n; ++i)
                    PAM[i] = Algorithms.MaxValue<double>(PAC.GetRowEnumerator(i));

                for (int i = 0; i < n; ++i)
                    for (int j = 0; j < n; ++j)
//.........这里部分代码省略.........
开发者ID:Hydrologist,项目名称:msnp,代码行数:101,代码来源:NetworkFormationSimulation.cs


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