use core::time::Duration;
use thiserror::Error;
use crate::IterState;
#[derive(Clone, Debug, Error)]
#[error("Solver reached the maximum iteration: {max_iteration}.")]
pub struct MaxIterationReached<State: IterState> {
pub max_iteration: u64,
pub(crate) final_state: State,
}
impl<State: IterState> MaxIterationReached<State> {
pub fn into_final_state(self) -> State {
self.final_state
}
pub fn final_state_ref(&self) -> &State {
&self.final_state
}
pub fn into_solution(self) -> State::Solution {
self.final_state.into_sol()
}
}
#[derive(Clone, Debug, Error)]
#[error("Solver timeout: {}ms or {}s", timeout.as_millis(), timeout.as_secs_f64())]
pub struct TimeOut<State: IterState> {
pub timeout: Duration,
pub(crate) final_state: State,
}
impl<State: IterState> TimeOut<State> {
pub fn into_final_state(self) -> State {
self.final_state
}
pub fn final_state_ref(&self) -> &State {
&self.final_state
}
pub fn into_solution(self) -> State::Solution {
self.final_state.into_sol()
}
}