mod adjacency;
mod annealing;
mod exhaustive;
use core::fmt;
pub use annealing::{AnnealingStats, InvalidSchedule, Schedule, SimulatedAnnealing};
pub use exhaustive::{Exhaustive, ExhaustiveStats};
use search_core::{Budget, Status};
pub trait Sampler<Model> {
type Stats;
type Sample<'a>
where
Self: 'a;
type Error;
fn sample<B: Budget<Self::Stats>>(
&mut self,
model: &Model,
budget: B,
) -> Result<Run<Self::Sample<'_>, Self::Stats>, Self::Error>;
fn resume<B: Budget<Self::Stats>>(
&mut self,
budget: B,
) -> Result<Run<Self::Sample<'_>, Self::Stats>, Self::Error>;
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Run<S, Stats> {
pub sample: S,
pub status: Status,
pub stats: Stats,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Sample<'a, T> {
pub bits: &'a [bool],
pub energy: T,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum SampleError {
TooManyVariables {
variables: usize,
max: usize,
},
NothingToResume,
}
impl fmt::Display for SampleError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::TooManyVariables { variables, max } => write!(
f,
"the model has {variables} variables; the sampler accepts at most {max}"
),
Self::NothingToResume => f.write_str("there is no run to resume"),
}
}
}
impl core::error::Error for SampleError {}