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