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::SimpleScore;
#[derive(Clone, Debug)]
struct Tour { cities: Vec<i32>, score: Option<SimpleScore> }
impl PlanningSolution for Tour {
type Score = SimpleScore;
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>
Sourcepub 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 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
Creates a new list reverse move with typed function pointers.
§Arguments
entity_index- Entity indexstart- Start of range (inclusive)end- End of range (exclusive)list_len- Function to get list lengthlist_reverse- Function to reverse elements in rangevariable_name- Name of the list variabledescriptor_index- Entity descriptor index
Sourcepub fn entity_index(&self) -> usize
pub fn entity_index(&self) -> usize
Returns the entity index.
Sourcepub fn segment_len(&self) -> usize
pub fn segment_len(&self) -> usize
Returns the segment length.
Trait Implementations§
Source§impl<S: Clone, V: Clone> Clone for ListReverseMove<S, V>
impl<S: Clone, V: Clone> Clone for ListReverseMove<S, V>
Source§fn clone(&self) -> ListReverseMove<S, V>
fn clone(&self) -> ListReverseMove<S, V>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§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§fn is_doable(&self, score_director: &dyn ScoreDirector<S>) -> bool
fn is_doable(&self, score_director: &dyn ScoreDirector<S>) -> bool
Returns true if this move can be executed in the current state. Read more
Source§fn do_move(&self, score_director: &mut dyn ScoreDirector<S>)
fn do_move(&self, score_director: &mut dyn ScoreDirector<S>)
Executes this move, modifying the working solution. Read more
Source§fn descriptor_index(&self) -> usize
fn descriptor_index(&self) -> usize
Returns the descriptor index of the entity type this move affects.
Source§fn entity_indices(&self) -> &[usize]
fn entity_indices(&self) -> &[usize]
Returns the entity indices involved in this move.
Source§fn variable_name(&self) -> &str
fn variable_name(&self) -> &str
Returns the variable name this move affects.
impl<S: Copy, V: Copy> Copy for ListReverseMove<S, V>
Auto Trait Implementations§
impl<S, V> Freeze for ListReverseMove<S, V>
impl<S, V> RefUnwindSafe for ListReverseMove<S, V>where
V: RefUnwindSafe,
impl<S, V> Send for ListReverseMove<S, V>where
V: Send,
impl<S, V> Sync for ListReverseMove<S, V>where
V: Sync,
impl<S, V> Unpin for ListReverseMove<S, V>where
V: Unpin,
impl<S, V> UnwindSafe for ListReverseMove<S, V>where
V: 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