double GetBaricenterAbove(int v)
        {
            int inEdgesCount = ProperLayeredGraph.InEdgesCount(v);

            Debug.Assert(inEdgesCount > 0);
            return((from edge in ProperLayeredGraph.InEdges(v) select XPosition(edge.Source)).Sum() / inEdgesCount);
        }
Beispiel #2
0
        float WMedian(int node, bool theMedianGoingDown)
        {
            IEnumerable <LayerEdge> edges;
            int p;

            if (theMedianGoingDown)
            {
                edges = properLayeredGraph.OutEdges(node);
                p     = properLayeredGraph.OutEdgesCount(node);
            }
            else
            {
                edges = properLayeredGraph.InEdges(node);
                p     = properLayeredGraph.InEdgesCount(node);
            }

            if (p == 0)
            {
                return(-1.0f);
            }

            var parray = new int[p]; //we have no multiple edges

            int i = 0;

            if (theMedianGoingDown)
            {
                foreach (LayerEdge e in edges)
                {
                    parray[i++] = X[e.Target];
                }
            }
            else
            {
                foreach (LayerEdge e in edges)
                {
                    parray[i++] = X[e.Source];
                }
            }

            Array.Sort(parray);

            int m = p / 2;

            if (p % 2 == 1)
            {
                return(parray[m]);
            }

            if (p == 2)
            {
                return(0.5f * ((float)parray[0] + (float)parray[1]));
            }

            float left = parray[m - 1] - parray[0];

            float right = parray[p - 1] - parray[m];

            return(((float)parray[m - 1] * left + (float)parray[m] * right) / (left + right));
        }
        void AllocArrays()
        {
            int n = properLayeredGraph.NodeCount;

            P = new List <int> [n];
            S = new List <int> [n];


            POrder = new Dictionary <int, int> [n];
            SOrder = new Dictionary <int, int> [n];
            if (hasCrossWeights)
            {
                outCrossingCount = new Dictionary <int, int> [n];
                inCrossingCount  = new Dictionary <int, int> [n];
            }
            for (int i = 0; i < n; i++)
            {
                int count = properLayeredGraph.InEdgesCount(i);
                P[i] = new List <int>();
                if (hasCrossWeights)
                {
                    Dictionary <int, int> inCounts = inCrossingCount[i] = new Dictionary <int, int>(count);
                    foreach (LayerEdge le in properLayeredGraph.InEdges(i))
                    {
                        inCounts[le.Source] = le.CrossingWeight;
                    }
                }
                POrder[i] = new Dictionary <int, int>(count);
                count     = properLayeredGraph.OutEdgesCount(i);
                S[i]      = new List <int>();
                SOrder[i] = new Dictionary <int, int>(count);
                if (hasCrossWeights)
                {
                    Dictionary <int, int> outCounts = outCrossingCount[i] = new Dictionary <int, int>(count);
                    foreach (LayerEdge le in properLayeredGraph.OutEdges(i))
                    {
                        outCounts[le.Target] = le.CrossingWeight;
                    }
                }
            }
        }
 private int NumberOfInEdges(int v)
 {
     return(this.BT ? graph.InEdgesCount(v) : graph.OutEdgesCount(v));
 }