pub struct ClosureProblemChange<S: PlanningSolution, F>{ /* private fields */ }Expand description
A problem change implemented as a closure.
This is a convenience wrapper for simple changes that don’t need a dedicated struct.
§Example
use solverforge_solver::realtime::ClosureProblemChange;
use solverforge_scoring::ScoreDirector;
use solverforge_core::domain::PlanningSolution;
use solverforge_core::score::SimpleScore;
#[derive(Clone, Debug)]
struct Task { id: usize, done: bool }
#[derive(Clone, Debug)]
struct Solution {
tasks: Vec<Task>,
score: Option<SimpleScore>,
}
impl PlanningSolution for Solution {
type Score = SimpleScore;
fn score(&self) -> Option<Self::Score> { self.score }
fn set_score(&mut self, score: Option<Self::Score>) { self.score = score; }
}
// Mark task 0 as done
let change = ClosureProblemChange::<Solution, _>::new("mark_task_done", |sd| {
if let Some(task) = sd.working_solution_mut().tasks.get_mut(0) {
task.done = true;
}
sd.trigger_variable_listeners();
});Implementations§
Source§impl<S, F> ClosureProblemChange<S, F>
impl<S, F> ClosureProblemChange<S, F>
Trait Implementations§
Source§impl<S, F> Debug for ClosureProblemChange<S, F>
impl<S, F> Debug for ClosureProblemChange<S, F>
Source§impl<S, F> ProblemChange<S> for ClosureProblemChange<S, F>
impl<S, F> ProblemChange<S> for ClosureProblemChange<S, F>
Source§fn apply(&self, score_director: &mut dyn ScoreDirector<S>)
fn apply(&self, score_director: &mut dyn ScoreDirector<S>)
Applies this change to the working solution. Read more
Auto Trait Implementations§
impl<S, F> Freeze for ClosureProblemChange<S, F>where
F: Freeze,
impl<S, F> RefUnwindSafe for ClosureProblemChange<S, F>where
F: RefUnwindSafe,
S: RefUnwindSafe,
impl<S, F> Send for ClosureProblemChange<S, F>
impl<S, F> Sync for ClosureProblemChange<S, F>where
F: Sync,
impl<S, F> Unpin for ClosureProblemChange<S, F>
impl<S, F> UnwindSafe for ClosureProblemChange<S, F>where
F: UnwindSafe,
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more