pub struct ListReverseMove<S, V> { /* private fields */ }Expand description
A move that reverses a segment within a list.
This is the fundamental 2-opt move for TSP. Reversing a segment of the tour can significantly reduce total distance by eliminating crossing edges.
§Type Parameters
S- The planning solution typeV- The list element value type
§Example
use solverforge_solver::heuristic::r#move::ListReverseMove;
use solverforge_core::domain::PlanningSolution;
use solverforge_core::score::SoftScore;
#[derive(Clone, Debug)]
struct Tour { cities: Vec<i32>, score: Option<SoftScore> }
impl PlanningSolution for Tour {
type Score = SoftScore;
fn score(&self) -> Option<Self::Score> { self.score }
fn set_score(&mut self, score: Option<Self::Score>) { self.score = score; }
}
fn list_len(s: &Tour, _: usize) -> usize { s.cities.len() }
fn list_reverse(s: &mut Tour, _: usize, start: usize, end: usize) {
s.cities[start..end].reverse();
}
// Reverse segment [1..4) in tour: [A, B, C, D, E] -> [A, D, C, B, E]
let m = ListReverseMove::<Tour, i32>::new(
0, 1, 4,
list_len, list_reverse,
"cities", 0,
);Implementations§
Source§impl<S, V> ListReverseMove<S, V>
impl<S, V> ListReverseMove<S, V>
pub fn new( entity_index: usize, start: usize, end: usize, list_len: fn(&S, usize) -> usize, list_reverse: fn(&mut S, usize, usize, usize), variable_name: &'static str, descriptor_index: usize, ) -> Self
pub fn entity_index(&self) -> usize
pub fn start(&self) -> usize
pub fn end(&self) -> usize
pub fn segment_len(&self) -> usize
Trait Implementations§
Source§impl<S, V> Clone for ListReverseMove<S, V>
impl<S, V> Clone for ListReverseMove<S, V>
Source§impl<S, V: Debug> Debug for ListReverseMove<S, V>
impl<S, V: Debug> Debug for ListReverseMove<S, V>
Source§impl<S, V> Move<S> for ListReverseMove<S, V>
impl<S, V> Move<S> for ListReverseMove<S, V>
Source§impl<S, V, ES> MoveSelector<S, ListReverseMove<S, V>> for ListReverseMoveSelector<S, V, ES>
impl<S, V, ES> MoveSelector<S, ListReverseMove<S, V>> for ListReverseMoveSelector<S, V, ES>
impl<S, V> Copy for ListReverseMove<S, V>
Auto Trait Implementations§
impl<S, V> Freeze for ListReverseMove<S, V>
impl<S, V> RefUnwindSafe for ListReverseMove<S, V>
impl<S, V> Send for ListReverseMove<S, V>
impl<S, V> Sync for ListReverseMove<S, V>
impl<S, V> Unpin for ListReverseMove<S, V>
impl<S, V> UnsafeUnpin for ListReverseMove<S, V>
impl<S, V> UnwindSafe for ListReverseMove<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