Esempio n. 1
0
        /// <summary>
        /// Deletes an edge, if exists, between two vertices.
        /// </summary>
        /// <returns><c>true</c>, if edge was removed, <c>false</c> otherwise.</returns>
        /// <param name="firstVertex">First vertex.</param>
        /// <param name="secondVertex">Second vertex.</param>
        public bool RemoveEdge(T firstVertex, T secondVertex)
        {
            bool   ret = false;
            Clique splitting;
            Clique removing = new Clique();

            removing.Add(firstVertex);
            removing.Add(secondVertex);

            foreach (var clan in new HashSet <Clique>(_cliques))  //Iterating over a clone of cliques
            {
                if (clan.IsSupersetOf(removing))
                {
                    // clan should be eliminated from cliques and replaced by maximal refinements
                    _cliques.Remove(clan);

                    splitting = new Clique(clan);
                    splitting.Remove(firstVertex);
                    _cliques.Add(splitting);
                    ExpandToMaximal(splitting);

                    splitting = new Clique(clan);
                    splitting.Remove(secondVertex);
                    _cliques.Add(splitting);
                    ExpandToMaximal(splitting);

                    ret = true;  // return true when finished
                }
            }
            return(ret);
        }
Esempio n. 2
0
        /// <summary>
        /// Expands a clique to a maximal complete
        /// </summary>
        /// <param name="clan">Clique to expand</param>
        void ExpandToMaximal(Clique clan)
        {
            Clique maximalityChecker; // Temporal clique for checking maximality

            // Expand NewClique to a maximal complete subgraph
            foreach (var z in Vertices)
            {
                if (!clan.Contains(z))
                {
                    maximalityChecker = new Clique(clan);
                    maximalityChecker.Add(z);
                    if (IsComplete(maximalityChecker))
                    {
                        clan.Add(z);
                    }
                }
            }

            // Destroy every no maximal elements of the graph
            HashSet <Clique> clone = new HashSet <Clique>(_cliques);

            clone.Remove(clan);
            foreach (var c in clone) // Iterate over a clone of _cliques
            {
                if (clan.IsSupersetOf(c))
                {
                    _cliques.Remove(c);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Connects two vertices together.
        /// </summary>
        /// <returns><c>true</c>, if edge was added, <c>false</c> otherwise.</returns>
        /// <param name="firstVertex">First vertex.</param>
        /// <param name="secondVertex">Second vertex.</param>
        public bool AddEdge(T firstVertex, T secondVertex)
        {
            if (HasEdge(firstVertex, secondVertex))
            {
                return(false);
            }
            Clique NewClique = new Clique();  // The new clique that contains the edge (firstVertex, secondVertex)

            _cliques.Add(NewClique);

            _vertices.Add(firstVertex);
            _vertices.Add(secondVertex);

            NewClique.Add(firstVertex);
            NewClique.Add(secondVertex);

            ExpandToMaximal(NewClique);
            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DataStructures.Graphs.CliqueGraph`1"/> class.
        /// Copies the model from another graph.
        /// </summary>
        /// <param name="graph">Graph.</param>
        public CliqueGraph(IGraph <T> graph)
            : this(graph.Vertices)
        {
            foreach (var startVert in Vertices)
            {
                foreach (var endVert in graph.Neighbours(startVert))
                {
                    if (!HasEdge(startVert, endVert))
                    {
                        // Add vortex
                        Clique newClan = new Clique();
                        newClan.Add(startVert);
                        newClan.Add(endVert);

                        ExpandToMaximal(graph, newClan);
                        _cliques.Add(newClan);
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Expands a clique to a maximal complete in a given graph
        /// </summary>
        /// <param name="graph">Graph to use to determine maximality.</param>
        /// <param name="clan">Clique to expand.</param>
        static void ExpandToMaximal(IGraph <T> graph, Clique clan)
        {
            Clique tempo; // Temporal clique for checking maximality

            // Expand NewClique to a maximal complete subgraph
            foreach (var z in graph.Vertices)
            {
                if (!clan.Contains(z))
                {
                    tempo = new Clique(clan);
                    tempo.Add(z);
                    if (IsComplete(graph, tempo))
                    {
                        clan.Add(z);
                    }
                }
            }
        }