public void RemoveCluster()
        {
            var wrappedGraph = new AdjacencyGraph <int, Edge <int> >();
            var graph        = new ClusteredAdjacencyGraph <int, Edge <int> >(wrappedGraph);

            AssertNoCluster(graph);

            IClusteredGraph cluster            = graph.AddCluster();
            IClusteredGraph cluster2           = graph.AddCluster();
            IClusteredGraph cluster3           = graph.AddCluster();
            var             wrappedGraph2      = new AdjacencyGraph <int, Edge <int> >();
            var             graphNotInClusters = new ClusteredAdjacencyGraph <int, Edge <int> >(wrappedGraph2);

            graph.RemoveCluster(graphNotInClusters);
            AssertHasClusters(graph, new[] { cluster, cluster2, cluster3 });

            graph.RemoveCluster(cluster2);
            AssertHasClusters(graph, new[] { cluster, cluster3 });

            graph.RemoveCluster(cluster);
            AssertHasClusters(graph, new[] { cluster3 });

            graph.RemoveCluster(cluster3);
            AssertNoCluster(graph);
        }
 internal void WriteClusters(
     IDictionary <TVertex, GraphColor> colors,
     IDictionary <TEdge, GraphColor> edgeColors,
     IClusteredGraph parent
     )
 {
     ++ClusterCount;
     foreach (IVertexAndEdgeListGraph <TVertex, TEdge> g in parent.Clusters)
     {
         Output.Write("subgraph cluster{0}", ClusterCount.ToString());
         Output.WriteLine(" {");
         OnFormatCluster(g);
         if (g is IClusteredGraph)
         {
             WriteClusters(colors, edgeColors, g as IClusteredGraph);
         }
         if (parent.Colapsed)
         {
             foreach (TVertex v in g.Vertices)
             {
                 colors[v] = GraphColor.Black;
             }
             foreach (TEdge e in g.Edges)
             {
                 edgeColors[e] = GraphColor.Black;
             }
         }
         else
         {
             WriteVertices(colors, g.Vertices);
             WriteEdges(edgeColors, g.Edges);
         }
         Output.WriteLine("}");
     }
 }
示例#3
0
 /// <summary>
 /// Removes a cluster
 /// </summary>
 /// <param name="cluster">cluster to remove</param>
 /// <exception cref="ArgumentNullException">cluster is a null reference.</exception>
 public void RemoveCluster(IClusteredGraph cluster)
 {
     if (cluster == null)
     {
         throw new ArgumentNullException("cluster");
     }
     clusters.Remove(cluster);
 }
示例#4
0
        /// <inheritdoc />
        public void RemoveCluster(IClusteredGraph graph)
        {
            if (graph is null)
            {
                throw new ArgumentNullException(nameof(graph));
            }

            _clusters.Remove(graph);
        }
        private static void AssertHasClusters(
            [NotNull] IClusteredGraph graph,
            [NotNull, ItemNotNull] IEnumerable <IClusteredGraph> clusters)
        {
            IClusteredGraph[] clusterArray = clusters.ToArray();
            CollectionAssert.IsNotEmpty(clusterArray);

            Assert.AreEqual(clusterArray.Length, graph.ClustersCount);
            CollectionAssert.AreEquivalent(clusterArray, graph.Clusters);
        }
        public void AddCluster()
        {
            var wrappedGraph = new AdjacencyGraph <int, Edge <int> >();
            var graph        = new ClusteredAdjacencyGraph <int, Edge <int> >(wrappedGraph);

            AssertNoCluster(graph);

            IClusteredGraph cluster = graph.AddCluster();

            Assert.IsNotNull(cluster);
            AssertHasClusters(graph, new[] { cluster });

            IClusteredGraph cluster2 = ((IClusteredGraph)graph).AddCluster();

            Assert.IsNotNull(cluster2);
            AssertHasClusters(graph, new[] { cluster, cluster2 });
        }
示例#7
0
        internal void WriteClusters(
            VertexColorDictionary colors,
            EdgeColorDictionary edgeColors,
            IClusteredGraph parent
            )
        {
            ++ClusterCount;
            foreach (IVertexAndEdgeListGraph g in parent.Clusters)
            {
                Output.Write("subgraph cluster{0}", ClusterCount.ToString());
                Output.WriteLine(" {");

                OnFormatCluster(g);

                if (g is IClusteredGraph)
                {
                    WriteClusters(colors, edgeColors, g as IClusteredGraph);
                }

                if (parent.Colapsed)
                {
                    // draw cluster
                    // put vertices as black
                    foreach (IVertex v in g.Vertices)
                    {
                        colors[v] = GraphColor.Black;
                    }
                    foreach (IEdge e in g.Edges)
                    {
                        edgeColors[e] = GraphColor.Black;
                    }

                    // add fake vertex
                }
                else
                {
                    WriteVertices(colors, g.Vertices);
                    WriteEdges(edgeColors, g.Edges);
                }

                Output.WriteLine("}");
            }
        }
 private static void AssertNoCluster(
     [NotNull] IClusteredGraph graph)
 {
     Assert.AreEqual(0, graph.ClustersCount);
     CollectionAssert.IsEmpty(graph.Clusters);
 }
 /// <summary>
 /// Removes a cluster
 /// </summary>
 /// <param name="cluster">cluster to remove</param>
 /// <exception cref="ArgumentNullException">cluster is a null reference.</exception>
 public void RemoveCluster(IClusteredGraph cluster)
 {
     if (cluster==null)
         throw new ArgumentNullException("cluster");
     clusters.Remove(cluster);
 }
        internal void WriteClusters(
            VertexColorDictionary colors,
            EdgeColorDictionary edgeColors,
            IClusteredGraph parent
            )
        {
            ++ClusterCount;
            foreach(IVertexAndEdgeListGraph g in parent.Clusters)
            {
                Output.Write("subgraph cluster{0}",ClusterCount.ToString());
                Output.WriteLine(" {");

                OnFormatCluster(g);

                if (g is IClusteredGraph)
                    WriteClusters(colors,edgeColors, g as IClusteredGraph);

                if (parent.Colapsed)
                {
                    // draw cluster
                    // put vertices as black
                    foreach(IVertex v in g.Vertices)
                    {
                        colors[v]=GraphColor.Black;

                    }
                    foreach(IEdge e in g.Edges)
                        edgeColors[e]=GraphColor.Black;

                    // add fake vertex

                }
                else
                {
                    WriteVertices(colors,g.Vertices);
                    WriteEdges(edgeColors,g.Edges);
                }

                Output.WriteLine("}");
            }
        }