Shuffle once and keep order, use SmallRng
time: [98.196 µs 100.64 µs 103.56 µs] change: [−13.633% −10.629% −7.6947%] (p = 0.00 < 0.05)
This commit is contained in:
@@ -11,7 +11,7 @@ use crate::{
|
||||
};
|
||||
|
||||
use log::info;
|
||||
use rand::Rng;
|
||||
use rand::{rngs::SmallRng, seq::SliceRandom, SeedableRng};
|
||||
use rayon::{
|
||||
current_thread_index,
|
||||
iter::{IntoParallelRefIterator, ParallelIterator},
|
||||
@@ -132,13 +132,13 @@ impl Scheduler {
|
||||
return self.search(schedule, tracker, slot.next(), solved_in_thread);
|
||||
}
|
||||
|
||||
// sort candidates by current workload, add rng for tie breakers
|
||||
let mut rng = SmallRng::from_rng(&mut rand::rng());
|
||||
let mut valid_resident_ids = self.valid_residents(slot, schedule);
|
||||
valid_resident_ids.sort_unstable_by_key(|res_id| {
|
||||
valid_resident_ids.shuffle(&mut rng);
|
||||
valid_resident_ids.sort_by_key(|res_id| {
|
||||
let type_count = tracker.get_type_count(res_id, slot.shift_type());
|
||||
let workload = tracker.current_workload(res_id);
|
||||
let tie_breaker: f64 = rand::rng().random();
|
||||
(type_count, workload, (tie_breaker * 1000.0) as usize)
|
||||
(type_count, workload)
|
||||
});
|
||||
|
||||
for id in valid_resident_ids {
|
||||
|
||||
Reference in New Issue
Block a user