use std::ops::ControlFlow;
use crate::Solver;
use crate::branching::Brancher;
use crate::conflict_resolving::ConflictResolver;
use crate::results::SolutionReference;
pub trait SolutionCallback<B: Brancher, R: ConflictResolver> {
type Stop;
fn on_solution_callback(
&mut self,
solver: &Solver,
solution: SolutionReference,
brancher: &B,
resolver: &R,
) -> ControlFlow<Self::Stop>;
}
impl<T, B, R, StopData> SolutionCallback<B, R> for T
where
T: FnMut(&Solver, SolutionReference, &B, &R) -> ControlFlow<StopData>,
B: Brancher,
R: ConflictResolver,
{
type Stop = StopData;
fn on_solution_callback(
&mut self,
solver: &Solver,
solution: SolutionReference,
brancher: &B,
resolver: &R,
) -> ControlFlow<Self::Stop> {
(self)(solver, solution, brancher, resolver)
}
}
impl<T, StopData, B, R> SolutionCallback<B, R> for Option<T>
where
T: SolutionCallback<B, R, Stop = StopData>,
B: Brancher,
R: ConflictResolver,
{
type Stop = StopData;
fn on_solution_callback(
&mut self,
solver: &Solver,
solution: SolutionReference,
brancher: &B,
resolver: &R,
) -> ControlFlow<Self::Stop> {
if let Some(callback) = self {
return callback.on_solution_callback(solver, solution, brancher, resolver);
}
ControlFlow::Continue(())
}
}