Ejemplo n.º 1
0
        public void Initialize(IDataset dataset, XmlElement filterNode)
        {
            INumberTable numTable = dataset.GetNumberTable();
            int          N        = numTable.Rows;

            double[][] L      = Matrix(N, N);
            int        offset = numTable.Columns - N;

            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    if (i != j)
                    {
                        L[i][j] = -numTable.Matrix[i][offset + j];
                    }
                    else
                    {
                        L[i][j] = 0;
                    }
                }
            }
            for (int i = 0; i < N; i++)
            {
                double rowSum = 0;
                for (int j = 0; j < N; j++)
                {
                    rowSum += L[i][j];
                }
                L[i][i] = -rowSum;
            }

            IMathAdaptor math = GraphMetrics.App.GetMathAdaptor();

            double[][] H = math.InvertMatrix(L);

            d = Matrix(N, N);
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    d[i][j] = H[i][i] + H[j][j] - H[i][j] - H[j][i];
                }
            }
        }
Ejemplo n.º 2
0
        public void Initialize(IDataset dataset, XmlElement filterNode)
        {
            INumberTable numTable = dataset.GetNumberTable();
            int          N        = numTable.Rows;

            d = Matrix(N, N);
            int offset = numTable.Columns - N;

            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    d[i][j] = double.PositiveInfinity;
                    if (i != j)
                    {
                        double v = numTable.Matrix[i][offset + j];
                        if (v != 0)
                        {
                            d[i][j] = v;
                        }
                    }
                }
            }
            //Apply the Floyd–Warshall algorithm with some optimization
            //posted by Valerio Schiavoni (http://www.jroller.com/vschiavoni/entry/a_fast_java_implementation_of).
            for (int k = 0; k < N; k++)
            {
                double[] dk = d[k];
                for (int i = 0; i < N; i++)
                {
                    if (k == i)
                    {
                        continue;
                    }

                    double[] di  = d[i];
                    double   dki = (k < i) ? di[k] : dk[i];
                    if (dki == double.PositiveInfinity)
                    {
                        continue;
                    }

                    for (int j = 0; j < Math.Min(k, i); j++)
                    {
                        double s = dki + dk[j];
                        if (s < di[j])
                        {
                            di[j] = s;
                        }
                    }

                    for (int j = k + 1; j < i; j++)
                    {
                        double s = dki + d[j][k];
                        if (s < di[j])
                        {
                            di[j] = s;
                        }
                    }
                }
            }

            for (int k = 0; k < N; k++)
            {
                d[k][k] = 0;
            }
        }