@@ -144,3 +144,125 @@ function maximal_cliques end
144144 end
145145 return cliques
146146end
147+
148+ """
149+ maximum_clique(g)
150+
151+ Return a vector representing the node indices of a maximum clique
152+ of the undirected graph `g`.
153+
154+ ```jldoctest
155+ julia> using Graphs
156+
157+ julia> maximum_clique(blockdiag(complete_graph(3), complete_graph(4)))
158+ 4-element Vector{Int64}:
159+ 4
160+ 5
161+ 6
162+ 7
163+ ```
164+ """
165+ function maximum_clique end
166+ # see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
167+ @traitfn function maximum_clique (g:: AG :: (!IsDirected) ) where {T,AG<: AbstractGraph{T} }
168+ return sort (argmax (length, maximal_cliques (g)))
169+ end
170+
171+ """
172+ clique_number(g)
173+
174+ Returns the size of the largest clique of the undirected graph `g`.
175+
176+ ```jldoctest
177+ julia> using Graphs
178+
179+ julia> clique_number(blockdiag(complete_graph(3), complete_graph(4)))
180+ 4
181+ ```
182+ """
183+ function clique_number end
184+ # see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
185+ @traitfn function clique_number (g:: AG :: (!IsDirected) ) where {T,AG<: AbstractGraph{T} }
186+ return maximum (length, maximal_cliques (g))
187+ end
188+
189+ """
190+ maximal_independent_sets(g)
191+
192+ Return a vector of vectors representing the node indices in each of the maximal
193+ independent sets found in the undirected graph `g`.
194+
195+ The graph will be converted to SimpleGraph at the start of the computation.
196+
197+ ```jldoctest
198+ julia> using Graphs
199+
200+ julia> maximal_independent_sets(cycle_graph(5))
201+ 5-element Vector{Vector{Int64}}:
202+ [5, 2]
203+ [5, 3]
204+ [2, 4]
205+ [1, 4]
206+ [1, 3]
207+ ```
208+ """
209+ function maximal_independent_sets end
210+ # see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
211+ @traitfn function maximal_independent_sets (
212+ g:: AG :: (!IsDirected)
213+ ) where {T,AG<: AbstractGraph{T} }
214+ # Convert to SimpleGraph first because `complement` doesn't accept AbstractGraph.
215+ return maximal_cliques (complement (SimpleGraph (g)))
216+ end
217+
218+ """
219+ maximum_independent_set(g)
220+
221+ Return a vector representing the node indices of a maximum independent set
222+ of the undirected graph `g`.
223+
224+ The graph will be converted to SimpleGraph at the start of the computation.
225+
226+ ### See also
227+ [`independent_set`](@ref)
228+
229+ ## Examples
230+ ```jldoctest
231+ julia> using Graphs
232+
233+ julia> maximum_independent_set(cycle_graph(7))
234+ 3-element Vector{Int64}:
235+ 2
236+ 5
237+ 7
238+ ```
239+ """
240+ function maximum_independent_set end
241+ # see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
242+ @traitfn function maximum_independent_set (
243+ g:: AG :: (!IsDirected)
244+ ) where {T,AG<: AbstractGraph{T} }
245+ # Convert to SimpleGraph first because `complement` doesn't accept AbstractGraph.
246+ return maximum_clique (complement (SimpleGraph (g)))
247+ end
248+
249+ """
250+ independence_number(g)
251+
252+ Returns the size of the largest independent set of the undirected graph `g`.
253+
254+ The graph will be converted to SimpleGraph at the start of the computation.
255+
256+ ```jldoctest
257+ julia> using Graphs
258+
259+ julia> independence_number(cycle_graph(7))
260+ 3
261+ ```
262+ """
263+ function independence_number end
264+ # see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
265+ @traitfn function independence_number (g:: AG :: (!IsDirected) ) where {T,AG<: AbstractGraph{T} }
266+ # Convert to SimpleGraph first because `complement` doesn't accept AbstractGraph.
267+ return clique_number (complement (SimpleGraph (g)))
268+ end
0 commit comments