1
- struct FakeModel <: ClB.AbstractModel
1
+ struct FakeModel <: ClB.AbstractModel
2
2
id:: Int
3
3
end
4
4
FakeModel () = FakeModel (1 )
5
5
6
- const Solution = ClB. Solution{FakeModel,Int,Float64}
6
+ const Solution = ClB. Solution{FakeModel, Int, Float64}
7
+
8
+ function Base. show (io:: IOContext , solution:: Solution{FakeModel, Int, Float64} )
9
+ println (io, " Solution" )
10
+ for (decision, value) in solution
11
+ println (io, " | " , decision, " = " , value)
12
+ end
13
+ Printf. @printf (io, " └ value = %.2f \n " , getvalue (solution))
14
+ end
7
15
8
16
function constructor ()
9
17
# Make sure that Coluna initializes bounds to infinity.
@@ -16,19 +24,19 @@ function constructor()
16
24
pb = ClB. Bound (primal, min)
17
25
@test pb == Inf
18
26
@test ClB. getvalue (pb) == Inf
19
-
27
+
20
28
pb = ClB. Bound (primal, max)
21
29
@test pb == - Inf
22
30
@test ClB. getvalue (pb) == - Inf
23
-
31
+
24
32
db = ClB. Bound (dual, min)
25
33
@test db == - Inf
26
34
@test ClB. getvalue (db) == - Inf
27
-
35
+
28
36
db = ClB. Bound (dual, max)
29
37
@test db == Inf
30
38
@test ClB. getvalue (db) == Inf
31
-
39
+
32
40
pb = ClB. Bound (primal, min, 100 )
33
41
@test pb == 100
34
42
@test ClB. getvalue (pb) == 100
@@ -118,16 +126,16 @@ function gap()
118
126
# In minimisation, gap = (pb - db)/db
119
127
pb = ClB. Bound (min, primal, 10.0 )
120
128
db = ClB. Bound (min, dual, 5.0 )
121
- @test ClB. gap (pb, db) == ClB. gap (db, pb) == (10.0 - 5.0 )/ 5.0
129
+ @test ClB. gap (pb, db) == ClB. gap (db, pb) == (10.0 - 5.0 ) / 5.0
122
130
123
131
# In maximisation, gap = (db - pb)/pb
124
132
pb = ClB. Bound (max, primal, 5.0 )
125
133
db = ClB. Bound (max, dual, 10.0 )
126
- @test ClB. gap (pb, db) == ClB. gap (db, pb) == (10.0 - 5.0 )/ 5.0
134
+ @test ClB. gap (pb, db) == ClB. gap (db, pb) == (10.0 - 5.0 ) / 5.0
127
135
128
136
pb = ClB. Bound (min, primal, 10.0 )
129
137
db = ClB. Bound (min, dual, - 5.0 )
130
- @test ClB. gap (pb, db) == ClB. gap (db, pb) == (10.0 + 5.0 )/ 5.0
138
+ @test ClB. gap (pb, db) == ClB. gap (db, pb) == (10.0 + 5.0 ) / 5.0
131
139
132
140
# Cannot compute the gap between 2 primal bounds
133
141
pb1 = ClB. Bound (max, primal, 10 )
@@ -174,7 +182,7 @@ function show_test()
174
182
pb = ClB. Bound (max, primal, 4 )
175
183
io = IOBuffer ()
176
184
show (io, pb)
177
- @test String (take! (io)) == " 4.0"
185
+ @test String (take! (io)) == " 4.0"
178
186
end
179
187
register! (unit_tests, " bounds" , show_test)
180
188
@@ -217,7 +225,7 @@ function convert_MOI_Coluna_termination_statuses()
217
225
(MOI. ALMOST_OPTIMAL, ClB. UNCOVERED_TERMINATION_STATUS),
218
226
(MOI. SLOW_PROGRESS, ClB. UNCOVERED_TERMINATION_STATUS),
219
227
(MOI. MEMORY_LIMIT, ClB. UNCOVERED_TERMINATION_STATUS),
220
- (MOI. ALMOST_OPTIMAL, ClB. UNCOVERED_TERMINATION_STATUS)
228
+ (MOI. ALMOST_OPTIMAL, ClB. UNCOVERED_TERMINATION_STATUS),
221
229
]
222
230
223
231
for (moi_status, coluna_status) in statuses_bijection
@@ -236,7 +244,7 @@ function convert_MOI_Coluna_result_statuses()
236
244
@test ClB. convert_status (MOI. NO_SOLUTION) == ClB. UNKNOWN_SOLUTION_STATUS
237
245
@test ClB. convert_status (MOI. FEASIBLE_POINT) == ClB. FEASIBLE_SOL
238
246
@test ClB. convert_status (MOI. INFEASIBLE_POINT) == ClB. INFEASIBLE_SOL
239
- @test ClB. convert_status (MOI. NEARLY_FEASIBLE_POINT) == ClB. UNCOVERED_SOLUTION_STATUS
247
+ @test ClB. convert_status (MOI. NEARLY_FEASIBLE_POINT) == ClB. UNCOVERED_SOLUTION_STATUS
240
248
end
241
249
register! (unit_tests, " convert_MOI_Coluna" , convert_MOI_Coluna_result_statuses)
242
250
@@ -290,18 +298,18 @@ function solution_constructor_iterate_print()
290
298
test_solution_iterations (primal_sol, dict_sol)
291
299
@test ClB. getvalue (primal_sol) == 12.3
292
300
@test ClB. getstatus (primal_sol) == ClB. FEASIBLE_SOL
293
-
301
+
294
302
dict_sol = Dict (1 => 2.0 , 2 => 3.0 , 3 => 4.0 )
295
303
primal_sol = Solution (model, collect (keys (dict_sol)), collect (values (dict_sol)), 0.0 , ClB. FEASIBLE_SOL)
296
-
304
+
297
305
@test length (primal_sol) == typemax (Coluna. MAX_NB_ELEMS)
298
306
@test nnz (primal_sol) == 3
299
307
@test primal_sol[1 ] == 2.0
300
308
primal_sol[1 ] = 5.0 # change the value
301
309
@test primal_sol[1 ] == 5.0
302
-
310
+
303
311
io = IOBuffer ()
304
- show (io, primal_sol)
312
+ ClB . show (io, primal_sol)
305
313
306
314
@test String (take! (io)) == " Solution\n | 1 = 5.0\n | 2 = 3.0\n | 3 = 4.0\n └ value = 0.00 \n "
307
315
end
@@ -324,7 +332,7 @@ function solution_isequal()
324
332
sol6 = Solution (model, collect (keys (dict_sol2)), collect (values (dict_sol2)), 12.0 , ClB. FEASIBLE_SOL)
325
333
sol7 = Solution (model, collect (keys (dict_sol3)), collect (values (dict_sol3)), 12.0 , ClB. FEASIBLE_SOL)
326
334
sol8 = Solution (model, collect (keys (dict_sol4)), collect (values (dict_sol4)), 12.0 , ClB. FEASIBLE_SOL)
327
-
335
+
328
336
@test sol1 == sol2
329
337
@test sol1 != sol3 # different cost
330
338
@test sol1 != sol4 # different solution status
0 commit comments