@@ -144,3 +144,119 @@ function maximal_cliques end
144
144
end
145
145
return cliques
146
146
end
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
+ ```jldoctest
196
+ julia> using Graphs
197
+
198
+ julia> maximal_independent_sets(cycle_graph(5))
199
+ 5-element Vector{Vector{Int64}}:
200
+ [5, 2]
201
+ [5, 3]
202
+ [2, 4]
203
+ [1, 4]
204
+ [1, 3]
205
+ ```
206
+ """
207
+ function maximal_independent_sets end
208
+ # see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
209
+ @traitfn function maximal_independent_sets (
210
+ g:: AG :: (!IsDirected)
211
+ ) where {T,AG<: AbstractGraph{T} }
212
+ # Convert to SimpleGraph first because `complement` doesn't accept AbstractGraph.
213
+ return maximal_cliques (complement (SimpleGraph (g)))
214
+ end
215
+
216
+ """
217
+ maximum_independent_set(g)
218
+
219
+ Return a vector representing the node indices of a maximum independent set
220
+ of the undirected graph `g`.
221
+
222
+ ### See also
223
+ [`independent_set`](@ref)
224
+
225
+ ## Examples
226
+ ```jldoctest
227
+ julia> using Graphs
228
+
229
+ julia> maximum_independent_set(cycle_graph(7))
230
+ 3-element Vector{Int64}:
231
+ 2
232
+ 5
233
+ 7
234
+ ```
235
+ """
236
+ function maximum_independent_set end
237
+ # see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
238
+ @traitfn function maximum_independent_set (
239
+ g:: AG :: (!IsDirected)
240
+ ) where {T,AG<: AbstractGraph{T} }
241
+ # Convert to SimpleGraph first because `complement` doesn't accept AbstractGraph.
242
+ return maximum_clique (complement (SimpleGraph (g)))
243
+ end
244
+
245
+ """
246
+ independence_number(g)
247
+
248
+ Returns the size of the largest independent set of the undirected graph `g`.
249
+
250
+ ```jldoctest
251
+ julia> using Graphs
252
+
253
+ julia> independence_number(cycle_graph(7))
254
+ 3
255
+ ```
256
+ """
257
+ function independence_number end
258
+ # see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
259
+ @traitfn function independence_number (g:: AG :: (!IsDirected) ) where {T,AG<: AbstractGraph{T} }
260
+ # Convert to SimpleGraph first because `complement` doesn't accept AbstractGraph.
261
+ return clique_number (complement (SimpleGraph (g)))
262
+ end
0 commit comments