Ejemplo n.º 1
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));
        }
        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);
        }
Ejemplo n.º 3
0
        static LayerEdge[] EdgesOfStrip(int[] bottomVerts, ProperLayeredGraph properLayeredGraph)
        {
            LayerEdge[] edges = (from v in bottomVerts
                                 from e in properLayeredGraph.InEdges(v)
                                 select e).ToArray();

            return(edges);
        }
Ejemplo n.º 4
0
        private LayerEdge IncomingEdge(int u)
        {
            foreach (LayerEdge le in layeredGraph.InEdges(u))
            {
                return(le);
            }

            throw new InvalidOperationException();
        }
        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;
                    }
                }
            }
        }
        /// <summary>
        /// Sort new odd layers by the sum of x-coordinatates of predecessors and the successors of
        /// dummy nodes.
        /// </summary>
        void SortNewOddLayers()
        {
            for (int i = 1; i < nla.Layers.Length; i += 2)
            {
                SortedDictionary <int, object> sd = new SortedDictionary <int, object>();
                int[] layer = nla.Layers[i];
                foreach (int v in layer)
                {
                    //find unique predecessor and successor
                    int predecessor = -1;
                    foreach (LayerEdge ie in nLayeredGraph.InEdges(v))
                    {
                        predecessor = ie.Source;
                    }
                    int successor = -1;
                    foreach (LayerEdge ie in nLayeredGraph.OutEdges(v))
                    {
                        successor = ie.Target;
                    }

                    int x = nla.X[predecessor] + nla.X[successor];

                    if (sd.ContainsKey(x))
                    {
                        object o = sd[x];
#if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=347
                        if (o.GetType() == typeof(int))
                        {
#else
                        if (o is int)
                        {
#endif
                            List <int> l = new List <int>();
                            l.Add((int)o);
                            l.Add(v);
                            sd[x] = l;
                        }
                        else
                        {
                            List <int> l = o as List <int>;
                            l.Add(v);
                        }
                    }
                    else
                    {
                        sd[x] = v;
                    }
                }
                //fill the layer according to this order
                int c = 0;
                foreach (object v in sd.Values)
#if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=347{
                    if (v.GetType() == typeof(int))
#else
                { if (v is int)
#endif
                    { layer[c++] = (int)v; }
                    else
                    {
                        foreach (int k in v as List <int> )
                        {
                            layer[c++] = k;
                        }
                    } }

                //update X now
                for (int m = 0; m < layer.Length; m++)
                    nla.X[layer[m]] = m; }
            }
        }
 IEnumerable <LayerEdge> InEdges(int v)
 {
     return(this.BT ? graph.InEdges(v) : graph.OutEdges(v));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Sort new odd layers by the sum of x-coordinatates of predecessors and the successors of 
        /// dummy nodes.
        /// </summary>
        void SortNewOddLayers() {

            for (int i = 1; i < nla.Layers.Length; i += 2) {
                SortedDictionary<int, object> sd = new SortedDictionary<int, object>();
                int[] layer = nla.Layers[i];
                foreach (int v in layer) {

                    //find unique predecessor and successor
                    int predecessor = -1;
                    foreach (LayerEdge ie in nLayeredGraph.InEdges(v))
                        predecessor = ie.Source;
                    int successor = -1;
                    foreach (LayerEdge ie in nLayeredGraph.OutEdges(v))
                        successor = ie.Target;

                    int x = nla.X[predecessor] + nla.X[successor];

                    if (sd.ContainsKey(x)) {
                        object o = sd[x];
#if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=347
                        if (o.GetType() == typeof(int)) {
#else
                        if (o is int) {
#endif
                            List<int> l = new List<int>();
                            l.Add((int)o);
                            l.Add(v);
                            sd[x] = l;
                        } else {
                            List<int> l = o as List<int>;
                            l.Add(v);
                        }
                    } else
                        sd[x] = v;
                }
                //fill the layer according to this order
                int c = 0;
                foreach (object v in sd.Values)
#if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=347
                    if (v.GetType() == typeof(int))
#else
                {
                   if (v is int)
                      #endif
                      layer[c++] = (int)v;
                   else
                   {
                      foreach (int k in v as List<int>)
                         layer[c++] = k;
                   }
                }

                //update X now
                for (int m = 0; m < layer.Length; m++)
                    nla.X[layer[m]] = m;
            }
        }

        /// <summary>
        /// Allocating new layering and filling its y-layers
        /// </summary>
        void InitNewLayering() {


            nla = new LayerArrays(new int[totalNodes]);

            for (int i = 0; i < layeredGraph.NodeCount; i++)
                NLayering[i] = la.Y[i] * 2;

            foreach (KeyValuePair<IntPair, List<IntEdge>> kv in database.Multiedges) {
                IntPair ip = kv.Key;

                if (ip.First != ip.Second && la.Y[ip.First] != la.Y[ip.Second]) {//not a self edge and not a flat edge
                    int top = la.Y[ip.x] * 2;
                    foreach (IntEdge e in kv.Value) {
                        int layer = top - 1;
                        foreach (LayerEdge le in e.LayerEdges)
                        {
                           if (le.Target != e.Target)
                              NLayering[le.Target] = layer--;
                        }
                    }
                }
            }

            int[][] newLayers = new int[2 * la.Layers.Length - 1][];

            //count new layer widths
            int[] counts = new int[newLayers.Length];

            foreach (int l in NLayering)
                counts[l]++;

            for (int i = 0; i < counts.Length; i++)
                newLayers[i] = new int[counts[i]];

            nla = new LayerArrays(NLayering);
            nla.Layers = newLayers;

        }
        static LayerEdge[] EdgesOfStrip(int[] bottomVerts, ProperLayeredGraph properLayeredGraph) {
            LayerEdge[] edges = (from v in bottomVerts
                                 from e in properLayeredGraph.InEdges(v)
                                 select e).ToArray();

            return edges;
        }