use dagorder; use runduration; fn albatross_max2(a: f64, b: f64) -> f64 { if a > b { return a; } b } fn albatross_finite(values: vector) -> bool { let mut i = 0; while i < len(values) { let value = at(values, i); if !(value - value == 0.0) { return false; } i += 1; } true } fn albatross_integers(values: vector) -> bool { let mut i = 0; while i < len(values) { let value = at(values, i); if !(value >= -9007199254740991.0 && value <= 9007199254740991.0 && value % 1.0 == 0.0) { return false; } i += 1; } true } fn albatross_magnitudes(values: vector) -> bool { let mut i = 0; while i < len(values) { let value = at(values, i); if !(value >= 0.0 && value - value == 0.0) { return false; } i += 1; } true } fn albatross_compute(parents: vector, durations: vector, workers: f64) -> vector { let shape = dagorder_forest(parents); let timing = runduration_path(parents, durations); if len(shape) == 0 || len(timing) == 0 { return []; } [at(timing, 0), at(timing, 2), albatross_max2(at(timing, 0), at(timing, 2) / workers), at(shape, 1)] } // Estimate a build forest's scheduling lower bound from dependencies and worker capacity. // Returns [critical path, total work, lower bound with given workers, deepest stage count]. The capacity bound assumes divisible worker time; actual nonpreemptive schedules can take longer. pub fn albatross_schedule(parents: vector, durations: vector, workers: f64) -> vector { if !albatross_integers(parents) { return []; } if !albatross_magnitudes(durations) { return []; } if !(workers >= 1.0 && workers <= 9007199254740991.0 && workers % 1.0 == 0.0) { return []; } let result = albatross_compute(parents, durations, workers); if !albatross_finite(result) { return []; } result }