private static double EvaluateEdgeLength(
            [NotNull] ICompoundGraph <object, IEdge <object> > compoundGraph,
            [NotNull] CompoundFDPLayoutAlgorithm <object, IEdge <object>, CompoundGraph <object, IEdge <object> > > algorithm,
            [NotNull] IReadOnlyDictionary <object, Size> verticesSizes,
            double idealEdgeLength,
            double nestingFactor)
        {
            double edgeLengthError = 0.0;

            foreach (IEdge <object> edge in compoundGraph.Edges)
            {
                Point uPos  = algorithm.VerticesPositions[edge.Source];
                Point vPos  = algorithm.VerticesPositions[edge.Target];
                Size  uSize = verticesSizes[edge.Source];
                Size  vSize = verticesSizes[edge.Target];

                Point uPoint = LayoutUtils.GetClippingPoint(uSize, uPos, vPos);
                Point vPoint = LayoutUtils.GetClippingPoint(vSize, vPos, uPos);

                double length      = (uPoint - vPoint).Length;
                bool   isInterEdge = compoundGraph.GetParent(edge.Source) != compoundGraph.GetParent(edge.Target);
                double iel         = isInterEdge
                              ? idealEdgeLength *
                                     (algorithm.LevelOfVertex(edge.Source) + algorithm.LevelOfVertex(edge.Target) + 1) *
                                     nestingFactor
                              : idealEdgeLength;
                double error = Math.Pow(length - iel, 2);
                edgeLengthError += error;
            }

            return(edgeLengthError);
        }
Esempio n. 2
0
        int ICompoundGraph <TVertex, TEdge> .GetChildrenCount(TVertex vertex)
        {
            ICompoundGraph <TVertex, TEdge> ithis = this;

            Contract.Requires(ithis.ContainsVertex(vertex));
            Contract.Ensures(Contract.Result <int>() >= 0);

            return(default(int));
        }
Esempio n. 3
0
        IEnumerable <TVertex> ICompoundGraph <TVertex, TEdge> .GetChildrenVertices(TVertex vertex)
        {
            ICompoundGraph <TVertex, TEdge> ithis = this;

            Contract.Requires(!vertex.Equals(default(TVertex)));
            Contract.Requires(ithis.ContainsVertex(vertex));

            return(new List <TVertex>());
        }
Esempio n. 4
0
        bool ICompoundGraph <TVertex, TEdge> .IsChildVertex(TVertex vertex)
        {
            ICompoundGraph <TVertex, TEdge> ithis = this;

            Contract.Requires(!vertex.Equals(default(TVertex)));
            Contract.Requires(ithis.ContainsVertex(vertex));

            return(default(bool));
        }
Esempio n. 5
0
        bool ICompoundGraph <TVertex, TEdge> .AddChildVertex(TVertex parent, TVertex child)
        {
            ICompoundGraph <TVertex, TEdge> ithis = this;

            Contract.Requires(!parent.Equals(default(TVertex)));
            Contract.Requires(ithis.ContainsVertex(parent));

            return(default(bool));
        }
Esempio n. 6
0
        int ICompoundGraph <TVertex, TEdge> .AddChildVertexRange(TVertex parent, IEnumerable <TVertex> children)
        {
            ICompoundGraph <TVertex, TEdge> ithis = this;

            Contract.Requires(!parent.Equals(default(TVertex)));
            Contract.Requires(ithis.ContainsVertex(parent));
            Contract.Ensures(Contract.Result <int>() >= 0);

            return(default(int));
        }
Esempio n. 7
0
        TVertex ICompoundGraph <TVertex, TEdge> .GetParent(TVertex vertex)
        {
            ICompoundGraph <TVertex, TEdge> ithis = this;

            Contract.Requires(!vertex.Equals(default(TVertex)));
            Contract.Requires(ithis.ContainsVertex(vertex));
            //TODO this is a bug in the MS Contract, i think -- solve it
            //Contract.Ensures( Contract.Result<TVertex>().Equals( default( TVertex ) ) || ithis.ContainsVertex( Contract.Result<TVertex>() ) );

            return(default(TVertex));
        }
        private static void EvaluateNodeDistances(
            [NotNull] ICompoundGraph <object, IEdge <object> > compoundGraph,
            [NotNull] CompoundFDPLayoutAlgorithm <object, IEdge <object>, CompoundGraph <object, IEdge <object> > > algorithm,
            [NotNull] IReadOnlyDictionary <object, Size> verticesSizes,
            out double minimalMinDistance,
            out double averageMinDistance,
            out double maximalMinDistance)
        {
            minimalMinDistance = 0.0;
            averageMinDistance = 0.0;
            maximalMinDistance = 0.0;
            foreach (HashSet <object> level in algorithm.Levels)
            {
                foreach (object u in level)
                {
                    double m = double.PositiveInfinity;
                    foreach (object v in level)
                    {
                        if (ReferenceEquals(u, v) || compoundGraph.GetParent(u) != compoundGraph.GetParent(v))
                        {
                            continue;
                        }

                        Point uPoint = LayoutUtils.GetClippingPoint(
                            verticesSizes[u],
                            algorithm.VerticesPositions[u],
                            algorithm.VerticesPositions[v]);

                        Point vPoint = LayoutUtils.GetClippingPoint(
                            verticesSizes[v],
                            algorithm.VerticesPositions[v],
                            algorithm.VerticesPositions[u]);
                        double distance = (uPoint - vPoint).Length;
                        m = Math.Min(m, distance);
                    }

                    if (double.IsPositiveInfinity(m))
                    {
                        continue;
                    }

                    minimalMinDistance  = Math.Min(minimalMinDistance, m);
                    averageMinDistance += m;
                    maximalMinDistance  = Math.Max(maximalMinDistance, m);
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CompoundGraph{TVertex,TEdge}"/> class.
        /// </summary>
        /// <param name="graph">Graph from which initializing this graph.</param>
        public CompoundGraph([NotNull] ICompoundGraph <TVertex, TEdge> graph)
        // ReSharper disable once ConstantConditionalAccessQualifier
            : base(graph?.AllowParallelEdges ?? throw new ArgumentNullException(nameof(graph)), graph.VertexCount)
        {
            // Copy the vertices
            // ReSharper disable once VirtualMemberCallInConstructor
            AddVertexRange(graph.Vertices);

            // Copy the containment information
            foreach (TVertex vertex in graph.CompoundVertices)
            {
                AddChildVertexRange(vertex, graph.GetChildrenVertices(vertex));
            }

            // Copy the edges
            AddEdgeRange(graph.Edges);
        }
Esempio n. 10
0
        public CompoundGraph(ICompoundGraph <TVertex, TEdge> graph)
            : base(graph.AllowParallelEdges, graph.VertexCount)
        {
            //copy the vertices
            AddVertexRange(graph.Vertices);

            //copy the containment information
            foreach (var vertex in graph.Vertices)
            {
                if (!graph.IsChildVertex(vertex))
                {
                    continue;
                }

                var parent = graph.GetParent(vertex);
                AddChildVertex(parent, vertex);
            }

            //copy the edges
            AddEdgeRange(graph.Edges);
        }
        private static double EvaluateNodeOverlaps(
            [NotNull] ICompoundGraph <object, IEdge <object> > compoundGraph,
            [NotNull] CompoundFDPLayoutAlgorithm <object, IEdge <object>, CompoundGraph <object, IEdge <object> > > algorithm,
            [NotNull] IDictionary <object, Size> verticesSizes)
        {
            double overlapArea = 0.0;

            foreach (HashSet <object> level in algorithm.Levels)
            {
                foreach (object u in level)
                {
                    foreach (object v in level)
                    {
                        if (ReferenceEquals(u, v) || compoundGraph.GetParent(u) != compoundGraph.GetParent(v))
                        {
                            continue;
                        }

                        Point uPosition = algorithm.VerticesPositions[u];
                        Point vPosition = algorithm.VerticesPositions[v];
                        Size  uSize     = verticesSizes[u];
                        Size  vSize     = verticesSizes[v];

                        var uRect = new Rect(uPosition, uSize);
                        var vRect = new Rect(vPosition, vSize);

                        // Get the overlap size
                        uRect.Intersect(vRect);
                        if (double.IsNegativeInfinity(uRect.Width) || double.IsNegativeInfinity(uRect.Height))
                        {
                            continue;
                        }

                        overlapArea += uRect.Width * uRect.Height;
                    }
                }
            }

            return(overlapArea);
        }