@@ -12,5 +12,91 @@ using LinearAlgebra: I
12
12
end
13
13
14
14
@testset " GraphsMatching" begin
15
- @test 1 == 1
15
+
16
+
17
+
18
+ @testset " maximum_weight_maximal_matching" begin
19
+
20
+ g = complete_bipartite_graph (2 , 2 )
21
+ w = zeros (4 , 4 )
22
+ w[1 , 3 ] = 10.0
23
+ w[1 , 4 ] = 1.0
24
+ w[2 , 3 ] = 2.0
25
+ w[2 , 4 ] = 11.0
26
+ match = maximum_weight_maximal_matching (
27
+ g,
28
+ w,
29
+ algorithm = LPAlgorithm (),
30
+ optimizer = optimizer_with_attributes (Cbc. Optimizer, " LogLevel" => 0 ),
31
+ )
32
+ @test match. weight ≈ 21
33
+ @test match. mate[1 ] == 3
34
+ @test match. mate[3 ] == 1
35
+ @test match. mate[2 ] == 4
36
+ @test match. mate[4 ] == 2
37
+
38
+ g = complete_bipartite_graph (2 , 4 )
39
+ w = zeros (6 , 6 )
40
+ w[1 , 3 ] = 10
41
+ w[1 , 4 ] = 0.5
42
+ w[2 , 3 ] = 11
43
+ w[2 , 4 ] = 1
44
+ match = maximum_weight_maximal_matching (
45
+ g,
46
+ w,
47
+ algorithm = LPAlgorithm (),
48
+ optimizer = optimizer_with_attributes (Cbc. Optimizer, " LogLevel" => 0 ),
49
+ )
50
+ @test match. weight ≈ 11.5
51
+ @test match. mate[1 ] == 4
52
+ @test match. mate[4 ] == 1
53
+ @test match. mate[2 ] == 3
54
+ @test match. mate[3 ] == 2
55
+
56
+ g = complete_bipartite_graph (2 , 6 )
57
+ w = zeros (8 , 8 )
58
+ w[1 , 3 ] = 10
59
+ w[1 , 4 ] = 0.5
60
+ w[2 , 3 ] = 11
61
+ w[2 , 4 ] = 1
62
+ w[2 , 5 ] = - 1
63
+ w[2 , 6 ] = - 1
64
+ match = maximum_weight_maximal_matching (
65
+ g,
66
+ w,
67
+ algorithm = LPAlgorithm (),
68
+ optimizer = optimizer_with_attributes (Cbc. Optimizer, " LogLevel" => 0 ),
69
+ cutoff = 0 ,
70
+ )
71
+ @test match. weight ≈ 11.5
72
+ @test match. mate[1 ] == 4
73
+ @test match. mate[4 ] == 1
74
+ @test match. mate[2 ] == 3
75
+ @test match. mate[3 ] == 2
76
+
77
+ g = complete_bipartite_graph (4 , 2 )
78
+ w = zeros (6 , 6 )
79
+ w[3 , 5 ] = 10
80
+ w[3 , 6 ] = 0.5
81
+ w[2 , 5 ] = 11
82
+ w[1 , 6 ] = 1
83
+ w[1 , 5 ] = - 1
84
+
85
+ match = maximum_weight_maximal_matching (
86
+ g,
87
+ w,
88
+ algorithm = LPAlgorithm (),
89
+ optimizer = optimizer_with_attributes (Cbc. Optimizer, " LogLevel" => 0 ),
90
+ cutoff = 0 ,
91
+ )
92
+ @test match. weight ≈ 12
93
+ @test match. mate[1 ] == 6
94
+ @test match. mate[2 ] == 5
95
+ @test match. mate[3 ] == - 1
96
+ @test match. mate[4 ] == - 1
97
+ @test match. mate[5 ] == 2
98
+ @test match. mate[6 ] == 1
99
+
100
+ end
101
+
16
102
end
0 commit comments