-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathoptimal.jl
More file actions
46 lines (40 loc) · 1.35 KB
/
optimal.jl
File metadata and controls
46 lines (40 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using SparseArrays
using SparseMatrixColorings
using StableRNGs
using Test
using JuMP
using MiniZinc
using HiGHS
rng = StableRNG(0)
asymmetric_params = vcat(
[(10, 20, p) for p in (0.0:0.1:0.5)], [(20, 10, p) for p in (0.0:0.1:0.5)]
)
algo = GreedyColoringAlgorithm()
optalgo = OptimalColoringAlgorithm(() -> MiniZinc.Optimizer{Float64}("highs"); silent=false)
@testset "Column coloring" begin
problem = ColoringProblem(; structure=:nonsymmetric, partition=:column)
for (m, n, p) in asymmetric_params
A = sprand(rng, m, n, p)
result = coloring(A, problem, algo)
optresult = coloring(A, problem, optalgo)
@test ncolors(result) >= ncolors(optresult)
end
end
@testset "Row coloring" begin
problem = ColoringProblem(; structure=:nonsymmetric, partition=:row)
for (m, n, p) in asymmetric_params
A = sprand(rng, m, n, p)
result = coloring(A, problem, algo)
optresult = coloring(A, problem, optalgo)
@test ncolors(result) >= ncolors(optresult)
end
end
@testset "Too big" begin
A = sprand(rng, Bool, 100, 100, 0.1)
optalgo_timelimit = OptimalColoringAlgorithm(
optimizer_with_attributes(HiGHS.Optimizer, "time_limit" => 10.0); # 1 second
silent=false,
assert_solved=false,
)
@test_throws AssertionError coloring(A, ColoringProblem(), optalgo_timelimit)
end