1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use alloc::vec::Vec;
use core::marker::PhantomData;

use necsim_core::{
    cogs::{
        ActiveLineageSampler, Backup, CoalescenceSampler, DispersalSampler, EmigrationExit,
        EventSampler, Habitat, ImmigrationEntry, LineageStore, MathsCore, RngCore,
        SpeciationProbability, TurnoverRate,
    },
    lineage::Lineage,
};
use necsim_core_bond::PositiveF64;

mod sampler;

pub mod lineage;

#[derive(Debug)]
pub struct RestartFixUpActiveLineageSampler<
    M: MathsCore,
    H: Habitat<M>,
    G: RngCore<M>,
    S: LineageStore<M, H>,
    X: EmigrationExit<M, H, G, S>,
    D: DispersalSampler<M, H, G>,
    C: CoalescenceSampler<M, H, S>,
    T: TurnoverRate<M, H>,
    N: SpeciationProbability<M, H>,
    E: EventSampler<M, H, G, S, X, D, C, T, N>,
    I: ImmigrationEntry<M>,
    A: ActiveLineageSampler<M, H, G, S, X, D, C, T, N, E, I>,
> {
    inner: A,
    restart_time: PositiveF64,
    fixable_lineages: Vec<Lineage>,
    #[allow(clippy::type_complexity)]
    _marker: PhantomData<(M, H, G, S, X, D, C, T, N, E, I)>,
}

impl<
        M: MathsCore,
        H: Habitat<M>,
        G: RngCore<M>,
        S: LineageStore<M, H>,
        X: EmigrationExit<M, H, G, S>,
        D: DispersalSampler<M, H, G>,
        C: CoalescenceSampler<M, H, S>,
        T: TurnoverRate<M, H>,
        N: SpeciationProbability<M, H>,
        E: EventSampler<M, H, G, S, X, D, C, T, N>,
        I: ImmigrationEntry<M>,
        A: ActiveLineageSampler<M, H, G, S, X, D, C, T, N, E, I>,
    > RestartFixUpActiveLineageSampler<M, H, G, S, X, D, C, T, N, E, I, A>
{
    #[must_use]
    pub fn new(
        active_lineage_sampler: A,
        fixable_lineages: Vec<Lineage>,
        restart_time: PositiveF64,
    ) -> Self {
        Self {
            inner: active_lineage_sampler,
            restart_time,
            fixable_lineages,
            _marker: PhantomData::<(M, H, G, S, X, D, C, T, N, E, I)>,
        }
    }
}

#[contract_trait]
impl<
        M: MathsCore,
        H: Habitat<M>,
        G: RngCore<M>,
        S: LineageStore<M, H>,
        X: EmigrationExit<M, H, G, S>,
        D: DispersalSampler<M, H, G>,
        C: CoalescenceSampler<M, H, S>,
        T: TurnoverRate<M, H>,
        N: SpeciationProbability<M, H>,
        E: EventSampler<M, H, G, S, X, D, C, T, N>,
        I: ImmigrationEntry<M>,
        A: ActiveLineageSampler<M, H, G, S, X, D, C, T, N, E, I>,
    > Backup for RestartFixUpActiveLineageSampler<M, H, G, S, X, D, C, T, N, E, I, A>
{
    unsafe fn backup_unchecked(&self) -> Self {
        Self {
            inner: self.inner.backup_unchecked(),
            restart_time: self.restart_time,
            fixable_lineages: self.fixable_lineages.clone(),
            _marker: PhantomData::<(M, H, G, S, X, D, C, T, N, E, I)>,
        }
    }
}