@@ -38,31 +38,81 @@ Random.seed!(StableRNG(42), 42)
3838end
3939
4040@testset " Matching LMO" begin
41- N = 200
41+ N = 50
4242 Random. seed! (9754 )
4343 g = Graphs. complete_graph (N)
4444 iter = collect (Graphs. edges (g))
4545 M = length (iter)
4646 direction = randn (M)
4747 lmo = CO. MatchingLMO (g)
4848 v = FrankWolfe. compute_extreme_point (lmo, direction)
49+ @test Boscia. is_simple_linear_feasible (lmo, v)
4950 adj_mat = spzeros (M, M)
50- for i in 1 : M
51- adj_mat[src (iter[i] ), dst (iter[i] )] = direction[i]
51+ for (i, edge) in enumerate ( edges (g))
52+ adj_mat[src (edge ), dst (edge )] = direction[i]
5253 end
5354 match_result = GraphsMatching. maximum_weight_matching (g, HiGHS. Optimizer, - adj_mat)
5455 v_sol = spzeros (M)
5556 K = length (match_result. mate)
56- for i in 1 : K
57- for j in 1 : M
58- if (match_result. mate[i ] == src (iter[j] ) && dst (iter[j] ) == i )
59- v_sol[j ] = 1
57+ for k in 1 : K
58+ for (i, edge) in enumerate ( edges (g))
59+ if (match_result. mate[k ] == src (edge ) && dst (edge ) == k )
60+ v_sol[i ] = 1
6061 end
6162 end
6263 end
6364 @test v_sol == v
6465 v2 = FrankWolfe. compute_extreme_point (lmo, ones (M))
6566 @test norm (v2) == 0
67+ @test v == Boscia. bounded_compute_extreme_point (lmo, direction, zeros (M), ones (M), 1 : M)
68+ @testset " Fix one entry to zero" begin
69+ for one_idx in SparseArrays. nonzeroinds (v)
70+ # upperbound one everywhere except one_idx fixed to zero
71+ v_fixed1 = Boscia. bounded_compute_extreme_point (lmo, direction, zeros (M), (1 : M) .!= one_idx, 1 : M)
72+ @test v_fixed1[one_idx] == 0
73+ @test Boscia. is_simple_linear_feasible (lmo, v_fixed1)
74+ end
75+ end
76+ @testset " Fix a single entry to one" begin
77+ for idx in rand (1 : M, 100 )
78+ # skip if entry already at one
79+ if v[idx] == 1
80+ continue
81+ end
82+ lb = (1 : M) .== idx
83+ ub = ones (M)
84+ v_fixed2 = Boscia. bounded_compute_extreme_point (lmo, direction, lb, ub, 1 : M)
85+ @test v_fixed2[idx] == 1
86+ @test Boscia. is_simple_linear_feasible (lmo, v_fixed2)
87+ end
88+ end
89+ @testset " Fix two entries to one" begin
90+ for (i1, e1) in enumerate (edges (g))
91+ for (i2, e2) in enumerate (edges (g))
92+ # lighter on computation
93+ if i1 ÷ 2 + i2 ÷ 2 > 0
94+ continue
95+ end
96+ # non-adjacent edges
97+ if isempty (intersect (Tuple (e1), Tuple (e2)))
98+ lb = zeros (M)
99+ ub = ones (M)
100+ lb[i1] = lb[i2] = 1
101+ v_fixed3 = Boscia. bounded_compute_extreme_point (lmo, direction, lb, ub, 1 : M)
102+ @test v_fixed3[i1] == 1
103+ @test v_fixed3[i2] == 1
104+ @test Boscia. is_simple_linear_feasible (lmo, v_fixed3)
105+ end
106+ end
107+ end
108+ end
109+ # non-matching vector
110+ v_wrong = 1.0 * copy (v)
111+ idx1 = findfirst (== (Edge (1 , 2 )), collect (edges (g)))
112+ idx2 = findfirst (== (Edge (1 , 3 )), collect (edges (g)))
113+ v_wrong[idx1] = 0.75
114+ v_wrong[idx2] = 0.5
115+ @test ! Boscia. is_simple_linear_feasible (lmo, v_wrong)
66116end
67117
68118
0 commit comments