Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub enum Violation {
Upper(f64),
}

#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Window {
pub start: f64, // Inclusive
Expand All @@ -71,6 +71,12 @@ impl std::hash::Hash for Window {
}
}

impl PartialOrd for Window {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

impl Ord for Window {
fn cmp(&self, other: &Self) -> Ordering {
self.start
Expand Down Expand Up @@ -206,10 +212,7 @@ pub enum ViolatedConstriant {

impl Constraint {
pub fn is_hard(&self) -> bool {
match self {
Constraint::HardConstraint { .. } => true,
_ => false,
}
matches!(self, Constraint::HardConstraint { .. })
}

pub fn evaluate(self, range: Window) -> Option<ViolatedConstriant> {
Expand All @@ -218,13 +221,9 @@ impl Constraint {
let violation = bound.0.violated(range);
violation.map(ViolatedConstriant::Hard)
}
Constraint::RepeatedBlock(repeated_bound) => {
if let Some(violated_range) = repeated_bound.violated(range) {
Some(ViolatedConstriant::Block(violated_range))
} else {
None
}
}
Constraint::RepeatedBlock(repeated_bound) => repeated_bound
.violated(range)
.map(ViolatedConstriant::Block),
Constraint::Block(block_range) => {
if block_range.overlap(range) {
Some(ViolatedConstriant::Block(block_range))
Expand Down Expand Up @@ -267,7 +266,7 @@ struct RepeatedBoundState {
last_range: Window,
}

#[derive(Debug, PartialEq, PartialOrd, Clone, Copy)]
#[derive(Debug, PartialEq, Clone, Copy)]
pub struct Consideration {
pub window: Window,
pub attention: Attention,
Expand All @@ -290,6 +289,12 @@ impl From<Window> for Consideration {
}
}

impl PartialOrd for Consideration {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

impl Ord for Consideration {
fn cmp(&self, other: &Self) -> Ordering {
self.window.cmp(&other.window)
Expand Down
32 changes: 17 additions & 15 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ pub struct Event {
}

impl Event {
#[allow(clippy::too_many_arguments)]
pub fn new(
id: EventId,
start: f64,
Expand Down Expand Up @@ -278,7 +279,7 @@ impl Event {
self.constraints.hard_bound_fn()(self.total_window())
}

pub fn from_windows(&mut self, windows: Vec<Window>) {
pub fn update_from_windows(&mut self, windows: Vec<Window>) {
self.segments = windows
.into_iter()
.map(|window| EventSegment {
Expand Down Expand Up @@ -309,7 +310,7 @@ pub fn split_segment(
return false;
}
let segment: usize = if segment < 0 {
segments.len().saturating_sub(segment.abs() as usize)
segments.len().saturating_sub(segment.unsigned_abs())
} else {
segment as usize
};
Expand Down Expand Up @@ -365,10 +366,16 @@ impl From<PlanBlueprint> for PlanningPhase {
fn from(blueprint: PlanBlueprint) -> Self {
let events = blueprint.events;
let queue = EventQueue::from_events(&events);
let event_map_reverse: HashMap<Uuid, EventId> = blueprint.event_map.iter().map(|(id, uuid)| (*uuid, *id)).collect();
let stop_exclude = blueprint.stop_exclude.into_iter().map(|id|
event_map_reverse[&id]
).collect();
let event_map_reverse: HashMap<Uuid, EventId> = blueprint
.event_map
.iter()
.map(|(id, uuid)| (*uuid, *id))
.collect();
let stop_exclude = blueprint
.stop_exclude
.into_iter()
.map(|id| event_map_reverse[&id])
.collect();

PlanningPhase {
events,
Expand Down Expand Up @@ -416,13 +423,9 @@ impl PlanningPhase {
fn create_plan(&mut self) {
let worker_ids: Vec<_> = self.workers.iter().map(|worker| worker.id()).collect();

loop {
let next_event = match self.event_queue.pop() {
Some(queued_event) => queued_event,
None => break,
};
while let Some(next_event) = self.event_queue.pop() {
let mut work_plans = vec![];
let mut event = (&self.events[next_event.event_id.0]).clone();
let mut event = (self.events[next_event.event_id.0]).clone();
#[cfg(feature = "tracing")]
tracing::debug!(
"Processing {:?} with priority {}, start time {}, duration {}",
Expand Down Expand Up @@ -493,7 +496,7 @@ impl PlanningPhase {
if let Some(lowest_cost) = lowest_cost {
let event = self.events.get_mut(next_event.event_id.0).unwrap();
event.assigned_worker = Some(lowest_cost.worker_id());
event.from_windows(lowest_cost.windows());
event.update_from_windows(lowest_cost.windows());
let worker = self.workers.get_mut(lowest_cost.worker_id().0).unwrap();
let vio = lowest_cost.violations();
if !vio.is_empty() {
Expand All @@ -509,8 +512,7 @@ impl PlanningPhase {
// If we have a stopping point, we only schedule events up to that point.
// If the event is part of the exclusion list, it is still scheduled.
if let Some(stop_at) = self.stop_at {
if self.stop_exclude.contains(&lowest_cost.id())
|| lowest_cost.end() <= stop_at
if self.stop_exclude.contains(&lowest_cost.id()) || lowest_cost.end() <= stop_at
{
worker.add_job(lowest_cost);
} else {
Expand Down
1 change: 1 addition & 0 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ impl PlanBlueprint {

let mut dependencies = vec![];
for connection in plan.dependencies {
#[allow(clippy::single_match)]
match self.events_seen.get(&connection.0) {
Some(event_id) => {
dependencies.push(Connection(*event_id));
Expand Down
18 changes: 8 additions & 10 deletions src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,12 @@ impl Worker {
for (i, job) in self.jobs.iter().enumerate() {
let job_priority = job.event.priority();

if event_priority < 0 && job_priority >= 0 {
if !event.depends_on(job.event.id(), events) {
// Negative priority events are classified as interrupts and can be scheduled at
// the same time as positive priority events.
interrupted_work = Some(i);
break;
}
if event_priority < 0 && job_priority >= 0 && !event.depends_on(job.event.id(), events)
{
// Negative priority events are classified as interrupts and can be scheduled at
// the same time as positive priority events.
interrupted_work = Some(i);
break;
}

if let Some(parent_id) = event.parent_id() {
Expand Down Expand Up @@ -279,9 +278,8 @@ impl Worker {
let mut blocked_off_time: f64 = 0.0;

for bound in self.blocked_off.hard_bounds() {
match bound {
Bound::Lower(lower) => start_time = lower,
_ => {}
if let Bound::Lower(lower) = bound {
start_time = lower
}
}

Expand Down