/// <summary>
        /// Converts the VisitedGraph to the inner type (which is a mutable graph representation).
        /// Wraps the vertices, converts the edges.
        /// </summary>
        protected void ConvertGraph(IDictionary <TVertex, Size> vertexSizes)
        {
            //creating the graph with the new type
            _graph = new SoftMutableHierarchicalGraph <SugiVertex, SugiEdge>(true);

            var vertexDict = new Dictionary <TVertex, SugiVertex>();

            //wrapping the vertices
            foreach (TVertex v in VisitedGraph.Vertices)
            {
                var size = vertexSizes[v];
                size.Height += Parameters.VerticalGap;
                size.Width  += Parameters.HorizontalGap;
                var wrapped = new SugiVertex(v, size);

                _graph.AddVertex(wrapped);
                vertexDict[v] = wrapped;
            }

            //creating the new edges
            foreach (TEdge e in VisitedGraph.Edges)
            {
                var wrapped = new SugiEdge(e, vertexDict[e.Source], vertexDict[e.Target], _edgePredicate(e));
                _graph.AddEdge(wrapped);
            }
        }
        /// <summary>
        /// Long edges ( span(e) > 1 ) will be replaced by
        /// span(e) edges (1 edge between every 2 neighbor layer)
        /// and span(e)-1 dummy vertices will be added to graph.
        /// </summary>
        protected void ReplaceLongEdges(CancellationToken cancellationToken)
        {
            //if an edge goes through multiple layers, we split the edge at every layer and insert a dummy node
            //  (only for the hierarchical edges)
            foreach (var edge in _graph.HierarchicalEdges.ToArray())
            {
                int sourceLayerIndex = edge.Source.LayerIndex;
                int targetLayerIndex = edge.Target.LayerIndex;

                if (Math.Abs(sourceLayerIndex - targetLayerIndex) <= 1)
                {
                    continue; //span(e) <= 1, not long edge
                }
                //the edge goes through multiple layers
                edge.IsLongEdge = true;
                _graph.HideEdge(edge, LONG_EDGES_TAG);

                //sourcelayer must be above the targetlayer
                if (targetLayerIndex < sourceLayerIndex)
                {
                    int c = targetLayerIndex;
                    targetLayerIndex = sourceLayerIndex;
                    sourceLayerIndex = c;
                }

                SugiVertex prev = edge.Source;
                for (int i = sourceLayerIndex + 1; i <= targetLayerIndex; i++)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    //the last vertex is the Target, the other ones are dummy vertices
                    SugiVertex dummy;
                    if (i == targetLayerIndex)
                    {
                        dummy = edge.Target;
                    }
                    else
                    {
                        dummy = new SugiVertex(null, new Size(0, 0));
                        _graph.AddVertex(dummy);
                        _layers[i].Add(dummy);
                        edge.DummyVertices.Add(dummy);
                    }
                    _graph.AddEdge(new SugiEdge(edge.Original, prev, dummy, EdgeTypes.Hierarchical));
                    prev = dummy;
                }
            }
        }