use necsim_core::{
cogs::{LocallyCoherentLineageStore, MathsCore, SplittableRng},
lineage::Lineage,
reporter::Reporter,
};
use necsim_core_bond::{NonNegativeF64, PositiveF64};
use necsim_impls_no_std::cogs::{
lineage_store::coherent::locally::classical::ClassicalLineageStore,
origin_sampler::pre_sampler::OriginPreSampler, turnover_rate::uniform::UniformTurnoverRate,
};
use necsim_partitioning_core::LocalPartition;
use rustcoalescence_algorithms::{
result::{ResumeError, SimulationOutcome},
strategy::RestartFixUpStrategy,
Algorithm,
};
use rustcoalescence_scenarios::{Scenario, ScenarioCogs};
use super::GillespieAlgorithm;
mod initialiser;
mod launch;
use initialiser::{
fixup::FixUpInitialiser, genesis::GenesisInitialiser, resume::ResumeInitialiser,
};
impl<
'p,
O: Scenario<M, G, TurnoverRate = UniformTurnoverRate>,
R: Reporter,
P: LocalPartition<'p, R>,
M: MathsCore,
G: SplittableRng<M>,
> Algorithm<'p, M, G, O, R, P> for GillespieAlgorithm
where
O::LineageStore<ClassicalLineageStore<M, O::Habitat>>:
LocallyCoherentLineageStore<M, O::Habitat>,
{
fn initialise_and_simulate<I: Iterator<Item = u64>>(
args: Self::Arguments,
rng: G,
scenario: ScenarioCogs<M, G, O>,
pre_sampler: OriginPreSampler<M, I>,
pause_before: Option<NonNegativeF64>,
local_partition: &mut P,
) -> Result<SimulationOutcome<M, G>, Self::Error> {
launch::initialise_and_simulate(
args,
rng,
scenario,
pre_sampler,
pause_before,
local_partition,
GenesisInitialiser,
)
}
fn resume_and_simulate<I: Iterator<Item = u64>, L: ExactSizeIterator<Item = Lineage>>(
args: Self::Arguments,
rng: G,
scenario: ScenarioCogs<M, G, O>,
pre_sampler: OriginPreSampler<M, I>,
lineages: L,
resume_after: Option<NonNegativeF64>,
pause_before: Option<NonNegativeF64>,
local_partition: &mut P,
) -> Result<SimulationOutcome<M, G>, ResumeError<Self::Error>> {
launch::initialise_and_simulate(
args,
rng,
scenario,
pre_sampler,
pause_before,
local_partition,
ResumeInitialiser {
lineages,
resume_after,
},
)
}
fn fixup_for_restart<I: Iterator<Item = u64>, L: ExactSizeIterator<Item = Lineage>>(
args: Self::Arguments,
rng: G,
scenario: ScenarioCogs<M, G, O>,
pre_sampler: OriginPreSampler<M, I>,
lineages: L,
restart_at: PositiveF64,
fixup_strategy: RestartFixUpStrategy,
local_partition: &mut P,
) -> Result<SimulationOutcome<M, G>, ResumeError<Self::Error>> {
launch::initialise_and_simulate(
args,
rng,
scenario,
pre_sampler,
Some(PositiveF64::max_after(restart_at.into(), restart_at.into()).into()),
local_partition,
FixUpInitialiser {
lineages,
restart_at,
fixup_strategy,
},
)
}
}