Skip to content

Commit

Permalink
Switch loops
Browse files Browse the repository at this point in the history
  • Loading branch information
gdalle committed Jun 12, 2024
1 parent 417f1d2 commit aec1c9f
Showing 1 changed file with 41 additions and 30 deletions.
71 changes: 41 additions & 30 deletions test/coloring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@ using SparseMatrixColorings:
using StableRNGs
using Test

rng = StableRNG(63)
rng = StableRNG(62)

samples = 10

asymmetric_params = vcat(
[(10, 20, p) for p in (0.0:0.1:1.0)], #
[(20, 10, p) for p in (0.0:0.1:1.0)],
[(100, 200, p) for p in (0.01:0.01:0.05)], #
[(200, 100, p) for p in (0.01:0.01:0.05)],
[(10, 20, p) for p in (0.0:0.2:1.0)], #
[(20, 10, p) for p in (0.0:0.2:1.0)],
[(100, 200, p) for p in (0.01:0.02:0.05)], #
[(200, 100, p) for p in (0.01:0.02:0.05)],
)

symmetric_params = vcat(
[(10, p) for p in (0.0:0.1:1.0)], #
[(100, p) for p in (0.01:0.01:0.05)],
[(10, p) for p in (0.0:0.2:1.0)], #
[(100, p) for p in (0.01:0.02:0.05)],
)

function test_colors(A::AbstractMatrix, method::String, colors::AbstractVector{<:Integer})
Expand Down Expand Up @@ -70,52 +72,61 @@ end

@testset verbose = true "General graph coloring" begin
@testset "$method" for method in COLORING_METHODS
@testset "$order" for order in COLORING_ORDERS
@testset "(n, p) = $((n, p))" for (n, p) in symmetric_params
@testset "(n, p) = $((n, p))" for (n, p) in symmetric_params
for _ in 1:samples
H = sparse(Symmetric(sprand(rng, Bool, n, n, p)))
filename = joinpath(@__DIR__, "H.mtx")
MatrixMarket.mmwrite(filename, H)
coloring_mat = ColPackColoring(H, method, order; verbose=false)
coloring_file = ColPackColoring(filename, method, order; verbose=false)
@test get_colors(coloring_mat) == get_colors(coloring_file)
colors = get_colors(coloring_file)
test_colors(H, method, colors)
for order in COLORING_ORDERS
coloring_mat = ColPackColoring(H, method, order; verbose=false)
coloring_file = ColPackColoring(filename, method, order; verbose=false)
@test get_colors(coloring_mat) == get_colors(coloring_file)
test_colors(H, method, get_colors(coloring_file))
test_colors(H, method, get_colors(coloring_mat))
end
end
end
end
end;

@testset verbose = true "Bipartite graph partial coloring" begin
@testset "$method" for method in PARTIAL_COLORING_METHODS
@testset "$order" for order in PARTIAL_COLORING_ORDERS
@testset "(n, m, p) = $((n, m, p))" for (n, m, p) in asymmetric_params
@testset "(n, m, p) = $((n, m, p))" for (n, m, p) in asymmetric_params
for _ in 1:samples
J = sprand(rng, Bool, n, m, p)
filename = joinpath(@__DIR__, "J.mtx")
MatrixMarket.mmwrite(filename, J)
coloring_mat = ColPackPartialColoring(J, method, order; verbose=false)
coloring_file = ColPackPartialColoring(
filename, method, order; verbose=false
)
@test length(get_colors(coloring_mat)) == length(get_colors(coloring_file))
# this should be true but it isn't at the moment
# @test get_colors(coloring_mat) == get_colors(coloring_file)
test_colors(J, method, get_colors(coloring_mat))
test_colors(J, method, get_colors(coloring_file))
for order in PARTIAL_COLORING_ORDERS
coloring_mat = ColPackPartialColoring(J, method, order; verbose=false)
coloring_file = ColPackPartialColoring(
filename, method, order; verbose=false
)
@test length(get_colors(coloring_mat)) ==
length(get_colors(coloring_file))
# this should be true but it isn't at the moment
@test_skip get_colors(coloring_mat) == get_colors(coloring_file)
test_colors(J, method, get_colors(coloring_file))
test_colors(J, method, get_colors(coloring_mat))
end
end
end
end
end;

@testset verbose = true "Bipartite graph bicoloring" begin
@testset "$method" for method in BICOLORING_METHODS
@testset "$order" for order in BICOLORING_ORDERS[1:1]
@testset "(n, m, p) = $((n, m, p))" for (n, m, p) in asymmetric_params
@testset "(n, m, p) = $((n, m, p))" for (n, m, p) in asymmetric_params
for _ in 1:samples
J = sprand(rng, Bool, n, m, p)
filename = joinpath(@__DIR__, "J.mtx")
MatrixMarket.mmwrite(filename, J)
coloring_file = ColPackBiColoring(filename, method, order; verbose=false)
colors1, colors2 = get_colors(coloring_file)
test_colors(J, method, colors1, colors2)
for order in BICOLORING_ORDERS
coloring_file = ColPackBiColoring(
filename, method, order; verbose=false
)
colors1, colors2 = get_colors(coloring_file)
test_colors(J, method, colors1, colors2)
end
end
end
end
Expand Down

0 comments on commit aec1c9f

Please sign in to comment.