-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added fractional_chromatic_number, fractional_clique_number (#13)
* added fractional_chromatic_number, fractional_clique_number * fractional_coloring: use HiGHS rather than GLPK * fractional_coloring: various fixes * Add quotes * format --------- Co-authored-by: Guillaume Dalle <[email protected]>
- Loading branch information
Showing
7 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
""" | ||
fractional_chromatic_number(g; optimizer) | ||
Compute the fractional chromatic number of a graph. Gives the same result as | ||
`fractional_clique_number`, though one function may run faster than the other. | ||
Beware: this can run very slowly for graphs of any substantial size. | ||
# Keyword arguments | ||
- `optimizer`: JuMP-compatible solver (default is `HiGHS.Optimizer`) | ||
# References | ||
- https://mathworld.wolfram.com/FractionalChromaticNumber.html | ||
""" | ||
function fractional_chromatic_number( | ||
g::AbstractGraph{T}, optimizer=HiGHS.Optimizer | ||
) where {T<:Integer} | ||
if is_directed(g) | ||
throw(ArgumentError("The graph must not be directed")) | ||
end | ||
|
||
ss = maximal_cliques(complement(g)) | ||
M = hcat(indvec.(ss, nv(g))...) | ||
|
||
model = Model(optimizer) | ||
set_silent(model) | ||
@variable(model, x[1:length(ss)] >= 0) | ||
@constraint(model, M * x .>= 1) | ||
@objective(model, Min, sum(x)) | ||
optimize!(model) | ||
return objective_value(model) | ||
end | ||
|
||
""" | ||
fractional_clique_number(g; optimizer) | ||
Compute the fractional clique number of a graph. Gives the same result as | ||
`fractional_chromatic_number`, though one function may run faster than the other. | ||
Beware: this can run very slowly for graphs of any substantial size. | ||
# Keyword arguments | ||
- `optimizer`: JuMP-compatible solver (default is `HiGHS.Optimizer`) | ||
# References | ||
- https://mathworld.wolfram.com/FractionalCliqueNumber.html | ||
""" | ||
function fractional_clique_number( | ||
g::AbstractGraph{T}, optimizer=HiGHS.Optimizer | ||
) where {T<:Integer} | ||
if is_directed(g) | ||
throw(ArgumentError("The graph must not be directed")) | ||
end | ||
|
||
model = Model(optimizer) | ||
set_silent(model) | ||
@variable(model, x[1:nv(g)] >= 0) | ||
for clique in maximal_cliques(complement(g)) | ||
@constraint(model, sum(x[clique]) <= 1) | ||
end | ||
@objective(model, Max, sum(x)) | ||
optimize!(model) | ||
return objective_value(model) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Graphs | ||
using GraphsOptim | ||
using IterTools | ||
using Test | ||
|
||
function kneser_graph(n::Integer, k::Integer) | ||
ss = collect(subsets(1:n, k)) | ||
return SimpleGraph([isdisjoint(a, b) for a in ss, b in ss]) | ||
end | ||
|
||
@test fractional_chromatic_number(kneser_graph(8, 3)) ≈ 8 / 3 | ||
@test fractional_clique_number(kneser_graph(8, 3)) ≈ 8 / 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters