pub struct ListRuinMove<S, V> { /* private fields */ }Expand description
A ruin-and-recreate move for Large Neighborhood Search on list variables.
Removes selected elements from a source entity, then reinserts each one greedily into the best position across all entities (including the source). The move is self-contained: accepting it leaves the solution valid.
§Type Parameters
S- The planning solution typeV- The list element value type
§Example
use solverforge_solver::heuristic::r#move::ListRuinMove;
use solverforge_core::domain::PlanningSolution;
use solverforge_core::score::SoftScore;
#[derive(Clone, Debug)]
struct Route { stops: Vec<i32>, score: Option<SoftScore> }
impl PlanningSolution for Route {
type Score = SoftScore;
fn score(&self) -> Option<Self::Score> { self.score }
fn set_score(&mut self, score: Option<Self::Score>) { self.score = score; }
}
fn entity_count(s: &Route) -> usize { 1 }
fn list_len(s: &Route, _: usize) -> usize { s.stops.len() }
fn list_remove(s: &mut Route, _: usize, idx: usize) -> i32 { s.stops.remove(idx) }
fn list_insert(s: &mut Route, _: usize, idx: usize, v: i32) { s.stops.insert(idx, v); }
// Ruin elements at indices 1 and 3, then recreate greedily
let m = ListRuinMove::<Route, i32>::new(
0,
&[1, 3],
entity_count,
list_len, list_remove, list_insert,
"stops", 0,
);Implementations§
Source§impl<S, V> ListRuinMove<S, V>
impl<S, V> ListRuinMove<S, V>
pub fn new( entity_index: usize, element_indices: &[usize], entity_count: fn(&S) -> usize, list_len: fn(&S, usize) -> usize, list_remove: fn(&mut S, usize, usize) -> V, list_insert: fn(&mut S, usize, usize, V), variable_name: &'static str, descriptor_index: usize, ) -> Self
pub fn entity_index(&self) -> usize
pub fn element_indices(&self) -> &[usize]
pub fn ruin_count(&self) -> usize
Trait Implementations§
Source§impl<S, V> Clone for ListRuinMove<S, V>
impl<S, V> Clone for ListRuinMove<S, V>
Source§impl<S, V: Debug> Debug for ListRuinMove<S, V>
impl<S, V: Debug> Debug for ListRuinMove<S, V>
Source§impl<S, V> Move<S> for ListRuinMove<S, V>
impl<S, V> Move<S> for ListRuinMove<S, V>
Source§impl<S, V> MoveSelector<S, ListRuinMove<S, V>> for ListRuinMoveSelector<S, V>
impl<S, V> MoveSelector<S, ListRuinMove<S, V>> for ListRuinMoveSelector<S, V>
Auto Trait Implementations§
impl<S, V> Freeze for ListRuinMove<S, V>
impl<S, V> RefUnwindSafe for ListRuinMove<S, V>
impl<S, V> Send for ListRuinMove<S, V>
impl<S, V> Sync for ListRuinMove<S, V>
impl<S, V> Unpin for ListRuinMove<S, V>
impl<S, V> UnsafeUnpin for ListRuinMove<S, V>
impl<S, V> UnwindSafe for ListRuinMove<S, V>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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