Skip to content
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
10 changes: 5 additions & 5 deletions necsim/core/src/cogs/dispersal_sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub trait DispersalSampler<M: MathsCore, H: Habitat<M>, G: RngCore<M>>:
crate::cogs::Backup + core::fmt::Debug
{
#[must_use]
#[debug_requires(habitat.contains(location), "location is inside habitat")]
#[debug_ensures(old(habitat).contains(&ret), "target is inside habitat")]
#[debug_requires(habitat.is_location_habitable(location), "location is habitable")]
#[debug_ensures(old(habitat).is_location_habitable(&ret), "target is habitable")]
fn sample_dispersal_from_location(
&self,
location: &Location,
Expand All @@ -33,8 +33,8 @@ pub trait SeparableDispersalSampler<M: MathsCore, H: Habitat<M>, G: RngCore<M>>:
DispersalSampler<M, H, G>
{
#[must_use]
#[debug_requires(habitat.contains(location), "location is inside habitat")]
#[debug_ensures(old(habitat).contains(&ret), "target is inside habitat")]
#[debug_requires(habitat.is_location_habitable(location), "location is habitable")]
#[debug_ensures(old(habitat).is_location_habitable(&ret), "target is habitable")]
#[debug_ensures(&ret != location, "disperses to a different location")]
fn sample_non_self_dispersal_from_location(
&self,
Expand All @@ -44,7 +44,7 @@ pub trait SeparableDispersalSampler<M: MathsCore, H: Habitat<M>, G: RngCore<M>>:
) -> Location;

#[must_use]
#[debug_requires(habitat.contains(location), "location is inside habitat")]
#[debug_requires(habitat.is_location_habitable(location), "location is habitable")]
fn get_self_dispersal_probability_at_location(
&self,
location: &Location,
Expand Down
11 changes: 9 additions & 2 deletions necsim/core/src/cogs/habitat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ pub trait Habitat<M: MathsCore>: crate::cogs::Backup + core::fmt::Debug + Sized
fn get_extent(&self) -> &LandscapeExtent;

#[must_use]
fn contains(&self, location: &Location) -> bool {
self.get_extent().contains(location)
fn is_location_habitable(&self, location: &Location) -> bool {
self.get_extent().contains(location) && self.get_habitat_at_location(location) > 0_u32
}

#[must_use]
fn is_indexed_location_habitable(&self, indexed_location: &IndexedLocation) -> bool {
self.get_extent().contains(indexed_location.location())
&& (indexed_location.index()
< self.get_habitat_at_location(indexed_location.location()))
}

#[must_use]
Expand Down
20 changes: 12 additions & 8 deletions necsim/core/src/cogs/lineage_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub trait LocallyCoherentLineageStore<M: MathsCore, H: Habitat<M>>:
{
#[must_use]
#[debug_requires(
habitat.contains(indexed_location.location()),
"indexed location is inside habitat"
habitat.is_indexed_location_habitable(indexed_location),
"indexed location is habitable"
)]
fn get_global_lineage_reference_at_indexed_location(
&self,
Expand All @@ -42,8 +42,8 @@ pub trait LocallyCoherentLineageStore<M: MathsCore, H: Habitat<M>>:
) -> Option<&GlobalLineageReference>;

#[debug_requires(
habitat.contains(lineage.indexed_location.location()),
"indexed location is inside habitat"
habitat.is_indexed_location_habitable(&lineage.indexed_location),
"indexed location is habitable"
)]
#[debug_ensures(self.get_lineage_for_local_reference(
&ret
Expand All @@ -68,9 +68,10 @@ pub trait LocallyCoherentLineageStore<M: MathsCore, H: Habitat<M>>:
#[debug_requires(self.get_lineage_for_local_reference(
&reference
).is_some(), "lineage is active")]
#[debug_ensures(old(habitat).contains(
ret.indexed_location.location()
), "prior location is inside habitat")]
#[debug_ensures(
old(habitat).is_indexed_location_habitable(&ret.indexed_location),
"prior indexed location is habitable"
)]
#[debug_ensures(self.get_lineage_for_local_reference(
&old(unsafe { crate::cogs::Backup::backup_unchecked(&reference) })
).is_none(), "lineage was deactivated")]
Expand Down Expand Up @@ -104,7 +105,10 @@ pub trait GloballyCoherentLineageStore<M: MathsCore, H: Habitat<M>>:
fn iter_active_locations(&self, habitat: &H) -> Self::LocationIterator<'_>;

#[must_use]
#[debug_requires(habitat.contains(location), "location is inside habitat")]
#[debug_requires(
habitat.is_location_habitable(location),
"location is habitable"
)]
fn get_local_lineage_references_at_location_unordered(
&self,
location: &Location,
Expand Down
5 changes: 4 additions & 1 deletion necsim/core/src/cogs/speciation_probability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ pub trait SpeciationProbability<M: MathsCore, H: Habitat<M>>:
crate::cogs::Backup + core::fmt::Debug
{
#[must_use]
#[debug_requires(habitat.contains(location), "location is inside habitat")]
#[debug_requires(
habitat.is_location_habitable(location),
"location is habitable"
)]
fn get_speciation_probability_at_location(
&self,
location: &Location,
Expand Down
5 changes: 4 additions & 1 deletion necsim/core/src/cogs/turnover_rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ pub trait TurnoverRate<M: MathsCore, H: Habitat<M>>:
crate::cogs::Backup + core::fmt::Debug
{
#[must_use]
#[debug_requires(habitat.contains(location), "location is inside habitat")]
#[debug_requires(
habitat.is_location_habitable(location),
"location is habitable"
)]
#[debug_ensures(
ret != 0.0_f64 || habitat.get_habitat_at_location(location) == 0_u32,
"only returns zero if the location is inhabitable"
Expand Down
Loading