1
1
use crate :: schedule:: Schedule ;
2
+ use crate :: base_types:: Cost ;
2
3
3
4
use super :: swap_factory:: SwapFactory ;
4
5
use crate :: schedule:: objective:: ObjectiveValue ;
@@ -61,6 +62,7 @@ pub(crate) struct TakeFirstRecursion<F: SwapFactory> {
61
62
swap_factory : F ,
62
63
recursion_depth : u8 ,
63
64
recursion_width : Option < usize > , // number of schedule that are considered for recursion (the one with best value are taken)
65
+ soft_objective_threshold : Cost ,
64
66
}
65
67
66
68
@@ -73,8 +75,8 @@ impl<F: SwapFactory> LocalImprover for TakeFirstRecursion<F> {
73
75
74
76
impl < F : SwapFactory > TakeFirstRecursion < F > {
75
77
76
- pub ( crate ) fn new ( swap_factory : F , recursion_depth : u8 , recursion_width : Option < usize > ) -> TakeFirstRecursion < F > {
77
- TakeFirstRecursion { swap_factory, recursion_depth, recursion_width}
78
+ pub ( crate ) fn new ( swap_factory : F , recursion_depth : u8 , recursion_width : Option < usize > , soft_objective_threshold : Cost ) -> TakeFirstRecursion < F > {
79
+ TakeFirstRecursion { swap_factory, recursion_depth, recursion_width, soft_objective_threshold }
78
80
}
79
81
80
82
@@ -98,7 +100,7 @@ impl<F: SwapFactory> TakeFirstRecursion<F> {
98
100
schedules_for_recursion. truncate ( width) ;
99
101
}
100
102
}
101
- new_sched. objective_value ( ) < objective_to_beat
103
+ new_sched. objective_value ( ) . cmp_with_threshold ( & objective_to_beat, self . soft_objective_threshold ) . is_lt ( )
102
104
} ) ;
103
105
104
106
if result. is_none ( ) {
@@ -137,6 +139,7 @@ pub(crate) struct TakeFirstParallelRecursion<F: SwapFactory + Send + Sync> {
137
139
swap_factory : F ,
138
140
recursion_depth : u8 ,
139
141
recursion_width : Option < usize > , // number of schedule that are considered per schedule for the next recursion (the one with best objectivevalue are taken for each schedule, dublicates are removed)
142
+ soft_objective_threshold : Cost , // improvement must be better than this threshold
140
143
}
141
144
142
145
@@ -149,8 +152,8 @@ impl<F: SwapFactory + Send + Sync> LocalImprover for TakeFirstParallelRecursion<
149
152
150
153
impl < F : SwapFactory + Send + Sync > TakeFirstParallelRecursion < F > {
151
154
152
- pub ( crate ) fn new ( swap_factory : F , recursion_depth : u8 , recursion_width : Option < usize > ) -> TakeFirstParallelRecursion < F > {
153
- TakeFirstParallelRecursion { swap_factory, recursion_depth, recursion_width}
155
+ pub ( crate ) fn new ( swap_factory : F , recursion_depth : u8 , recursion_width : Option < usize > , soft_objective_threshold : Cost ) -> TakeFirstParallelRecursion < F > {
156
+ TakeFirstParallelRecursion { swap_factory, recursion_depth, recursion_width, soft_objective_threshold }
154
157
}
155
158
156
159
@@ -194,7 +197,7 @@ impl<F: SwapFactory + Send + Sync> TakeFirstParallelRecursion<F> {
194
197
if let Ok ( best_i) = found_receiver. try_recv ( ) {
195
198
counter_limit = best_i;
196
199
}
197
- new_sched. objective_value ( ) < objective_to_beat || * i > counter_limit
200
+ new_sched. objective_value ( ) . cmp_with_threshold ( & objective_to_beat, self . soft_objective_threshold ) . is_lt ( ) || * i > counter_limit
198
201
} ) ;
199
202
200
203
match result {
@@ -267,7 +270,7 @@ impl<F: SwapFactory + Send + Sync> TakeFirstParallelRecursion<F> {
267
270
268
271
269
272
///////////////////////////////////////////////////////////
270
- /////////////////// TakeAnyParallelRecursion //// //////////////////
273
+ /////////////// TakeAnyParallelRecursion //////////////////
271
274
///////////////////////////////////////////////////////////
272
275
273
276
/// This improver uses parallel computation at two steps. In the recursion when multiple schedules
@@ -283,6 +286,7 @@ pub(crate) struct TakeAnyParallelRecursion<F: SwapFactory + Send + Sync> {
283
286
swap_factory : F ,
284
287
recursion_depth : u8 ,
285
288
recursion_width : Option < usize > , // number of schedule that are considered per schedule for the next recursion (the one with best objectivevalue are taken for each schedule, dublicates are removed)
289
+ soft_objective_threshold : Cost , // improvement must be better than this threshold
286
290
}
287
291
288
292
@@ -295,8 +299,8 @@ impl<F: SwapFactory + Send + Sync> LocalImprover for TakeAnyParallelRecursion<F>
295
299
296
300
impl < F : SwapFactory + Send + Sync > TakeAnyParallelRecursion < F > {
297
301
298
- pub ( crate ) fn new ( swap_factory : F , recursion_depth : u8 , recursion_width : Option < usize > ) -> TakeAnyParallelRecursion < F > {
299
- TakeAnyParallelRecursion { swap_factory, recursion_depth, recursion_width}
302
+ pub ( crate ) fn new ( swap_factory : F , recursion_depth : u8 , recursion_width : Option < usize > , soft_objective_threshold : Cost ) -> TakeAnyParallelRecursion < F > {
303
+ TakeAnyParallelRecursion { swap_factory, recursion_depth, recursion_width, soft_objective_threshold }
300
304
}
301
305
302
306
@@ -344,7 +348,7 @@ impl<F: SwapFactory + Send + Sync> TakeAnyParallelRecursion<F> {
344
348
345
349
let found_receiver_mutex = found_receiver_mutex. lock ( ) . unwrap ( ) ;
346
350
let found = found_receiver_mutex. try_recv ( ) ;
347
- new_sched. objective_value ( ) < objective_to_beat || found. is_ok ( )
351
+ new_sched. objective_value ( ) . cmp_with_threshold ( & objective_to_beat, self . soft_objective_threshold ) . is_lt ( ) || found. is_ok ( )
348
352
} ) ;
349
353
350
354
0 commit comments