Skip to content

Commit d30b799

Browse files
committed
Add VNGraphs.jl stubs for chromatic_number and edge_chromatic_number
Declares chromatic_number and edge_chromatic_number in Graphs.jl with helpful error hints directing users to install VNGraphs.jl for the fast C-backed very_nauty implementations. Includes unit tests asserting the stubs throw the expected errors.
1 parent ca5cbc3 commit d30b799

4 files changed

Lines changed: 66 additions & 1 deletion

File tree

src/Graphs.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,9 @@ export
454454

455455
# planarity
456456
is_planar,
457-
planar_maximally_filtered_graph
457+
planar_maximally_filtered_graph,
458+
chromatic_number,
459+
edge_chromatic_number
458460
"""
459461
Graphs
460462
@@ -575,6 +577,7 @@ include("independentset/degree_ind_set.jl")
575577
include("independentset/maximal_ind_set.jl")
576578
include("vertexcover/degree_vertex_cover.jl")
577579
include("vertexcover/random_vertex_cover.jl")
580+
include("vngraphs_stubs.jl")
578581
include("Experimental/Experimental.jl")
579582
include("Parallel/Parallel.jl")
580583
include("Test/Test.jl")

src/vngraphs_stubs.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Algorithm stubs for VNGraphs.jl integration
2+
3+
"""
4+
chromatic_number(g, timeout=0)
5+
6+
Return the chromatic number of the graph `g`.
7+
Note: This is a stub provided by `Graphs.jl`. For a concrete implementation,
8+
please use the `VNGraphs.jl` package which provides a fast C implementation
9+
via `very_nauty`.
10+
11+
```julia
12+
using VNGraphs
13+
chromatic_number(g)
14+
```
15+
"""
16+
function chromatic_number(g::AbstractGraph, args...; kwargs...)
17+
error("chromatic_number is not implemented in Graphs.jl. " *
18+
"Please load VNGraphs.jl to use the very_nauty implementation.")
19+
end
20+
21+
"""
22+
edge_chromatic_number(g, timeout=0)
23+
24+
Return the edge chromatic number of the graph `g`.
25+
Note: This is a stub provided by `Graphs.jl`. For a concrete implementation,
26+
please use the `VNGraphs.jl` package which provides a fast C implementation
27+
via `very_nauty`.
28+
29+
```julia
30+
using VNGraphs
31+
edge_chromatic_number(g)
32+
```
33+
"""
34+
function edge_chromatic_number(g::AbstractGraph, args...; kwargs...)
35+
error("edge_chromatic_number is not implemented in Graphs.jl. " *
36+
"Please load VNGraphs.jl to use the very_nauty implementation.")
37+
end
38+
39+
export chromatic_number, edge_chromatic_number

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ tests = [
155155
"trees/prufer",
156156
"experimental/experimental",
157157
"planarity",
158+
"vngraphs_stubs",
158159
]
159160

160161
@testset verbose = true "Graphs" begin

test/vngraphs_stubs.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Graphs
2+
using Test
3+
4+
@testset "VNGraphs Stubs" begin
5+
g = path_graph(5)
6+
7+
@test_throws ErrorException chromatic_number(g)
8+
@test_throws ErrorException edge_chromatic_number(g)
9+
10+
# Verify the error message contains the suggestion to load VNGraphs.jl
11+
try
12+
chromatic_number(g)
13+
catch e
14+
@test contains(e.msg, "VNGraphs.jl")
15+
end
16+
17+
try
18+
edge_chromatic_number(g)
19+
catch e
20+
@test contains(e.msg, "VNGraphs.jl")
21+
end
22+
end

0 commit comments

Comments
 (0)