Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Deme::most_recent_deme_start_time #191

Merged
merged 1 commit into from
Oct 20, 2022
Merged
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
17 changes: 17 additions & 0 deletions src/specification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2609,6 +2609,23 @@ impl Graph {
Err(e) => Err(e.into()),
}
}

/// Return the most recent end time of any deme
/// in the Graph.
///
/// This function is useful to check if the most
/// recent end time is greater than zero, meaning
/// that the model ends at a time point ancestral to
/// "now".
pub fn most_recent_deme_end_time(&self) -> Time {
let init = self.demes[0].end_time();
self.demes
.iter()
.skip(1)
.fold(init, |current_min, current_deme| {
std::cmp::min(current_min, current_deme.end_time())
})
}
}

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions tests/test_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ demes:
let graph = demes::loads(yaml).unwrap();
let end_time = graph.deme(0).epochs()[0].end_time();
assert_eq!(100.0, f64::from(end_time));
assert_eq!(graph.most_recent_deme_end_time(), 100.0);
}

// from demes-spec/test-cases/valid
Expand Down