|
13 | 13 |
|
14 | 14 | @testset "GraphsMatching" begin
|
15 | 15 |
|
16 |
| - @testset "maximum_weight_matching_reduction" begin |
17 |
| - N = Int(1e2) |
18 |
| - g = complete_graph(N) |
19 |
| - for i = 1:10 |
20 |
| - w = randn(N, N) |
21 |
| - w = transpose(w) * w |
22 |
| - match_sol = maximum_weight_matching( |
23 |
| - g, |
24 |
| - optimizer_with_attributes(Cbc.Optimizer, "LogLevel" => 0), |
25 |
| - w, |
26 |
| - ) |
27 |
| - match_red = maximum_weight_matching_reduction(g, w) |
28 |
| - sol = Edge[] |
29 |
| - for i = 1:N |
30 |
| - if (match_sol.mate[i] > 0) |
31 |
| - push!(sol, Edge(i, match_sol.mate[i])) |
32 |
| - end |
33 |
| - end |
34 |
| - @test sol == match_red |
35 |
| - end |
36 |
| - end |
37 |
| - |
38 |
| - @testset "maximum_weight_matching" begin |
39 |
| - g = complete_graph(3) |
40 |
| - w = [ |
41 |
| - 1 2 1 |
42 |
| - 1 1 1 |
43 |
| - 3 1 1 |
44 |
| - ] |
45 |
| - match = maximum_weight_matching( |
46 |
| - g, |
47 |
| - optimizer_with_attributes(Cbc.Optimizer, "LogLevel" => 0), |
48 |
| - w, |
49 |
| - ) |
50 |
| - @test match.mate[1] == 3 |
51 |
| - @test match.weight ≈ 3 |
52 |
| - |
53 |
| - g = complete_graph(3) |
54 |
| - w = zeros(3, 3) |
55 |
| - w[1, 2] = 1 |
56 |
| - w[3, 2] = 1 |
57 |
| - w[1, 3] = 1 |
58 |
| - match = maximum_weight_matching( |
59 |
| - g, |
60 |
| - optimizer_with_attributes(Cbc.Optimizer, "LogLevel" => 0), |
61 |
| - w, |
62 |
| - ) |
63 |
| - @test match.weight ≈ 1 |
64 |
| - |
65 |
| - |
66 |
| - g = Graph(4) |
67 |
| - add_edge!(g, 1, 3) |
68 |
| - add_edge!(g, 1, 4) |
69 |
| - add_edge!(g, 2, 4) |
70 |
| - |
71 |
| - w = zeros(4, 4) |
72 |
| - w[1, 3] = 1 |
73 |
| - w[1, 4] = 3 |
74 |
| - w[2, 4] = 1 |
75 |
| - |
76 |
| - match = maximum_weight_matching( |
77 |
| - g, |
78 |
| - optimizer_with_attributes(Cbc.Optimizer, "LogLevel" => 0), |
79 |
| - w, |
80 |
| - ) |
81 |
| - @test match.weight ≈ 3 |
82 |
| - @test match.mate[1] == 4 |
83 |
| - @test match.mate[2] == -1 |
84 |
| - @test match.mate[3] == -1 |
85 |
| - @test match.mate[4] == 1 |
86 |
| - |
87 |
| - g = Graph(4) |
88 |
| - add_edge!(g, 1, 2) |
89 |
| - add_edge!(g, 2, 3) |
90 |
| - add_edge!(g, 3, 1) |
91 |
| - add_edge!(g, 3, 4) |
92 |
| - match = maximum_weight_matching( |
93 |
| - g, |
94 |
| - optimizer_with_attributes(Cbc.Optimizer, "LogLevel" => 0), |
95 |
| - ) |
96 |
| - @test match.weight ≈ 2 |
97 |
| - @test match.mate[1] == 2 |
98 |
| - @test match.mate[2] == 1 |
99 |
| - @test match.mate[3] == 4 |
100 |
| - @test match.mate[4] == 3 |
101 |
| - |
102 |
| - w = zeros(4, 4) |
103 |
| - w[1, 2] = 1 |
104 |
| - w[2, 3] = 1 |
105 |
| - w[1, 3] = 1 |
106 |
| - w[3, 4] = 1 |
107 |
| - |
108 |
| - match = maximum_weight_matching( |
109 |
| - g, |
110 |
| - optimizer_with_attributes(Cbc.Optimizer, "LogLevel" => 0), |
111 |
| - w, |
112 |
| - ) |
113 |
| - @test match.weight ≈ 2 |
114 |
| - @test match.mate[1] == 2 |
115 |
| - @test match.mate[2] == 1 |
116 |
| - @test match.mate[3] == 4 |
117 |
| - @test match.mate[4] == 3 |
118 |
| - |
119 |
| - w = zeros(4, 4) |
120 |
| - w[1, 2] = 1 |
121 |
| - w[2, 3] = 1 |
122 |
| - w[1, 3] = 5 |
123 |
| - w[3, 4] = 1 |
124 |
| - |
125 |
| - match = maximum_weight_matching( |
126 |
| - g, |
127 |
| - optimizer_with_attributes(Cbc.Optimizer, "LogLevel" => 0), |
128 |
| - w, |
129 |
| - ) |
130 |
| - @test match.weight ≈ 5 |
131 |
| - @test match.mate[1] == 3 |
132 |
| - @test match.mate[2] == -1 |
133 |
| - @test match.mate[3] == 1 |
134 |
| - @test match.mate[4] == -1 |
135 |
| - end |
136 |
| - |
137 |
| - |
138 | 16 | @testset "maximum_weight_maximal_matching" begin
|
139 | 17 |
|
140 | 18 | g = complete_bipartite_graph(2, 2)
|
|
0 commit comments