pub struct KOptPhaseBuilder<S, V, DM, ESF>{ /* private fields */ }Expand description
Builder for creating k-opt local search phases.
§Type Parameters
S- The planning solution typeV- The list element value type (e.g.,usizefor visit indices)DM- The distance meter type (for nearby selection, stored for future use)ESF- Entity selector factory type (for nearby selection, stored for future use)
§Example
use solverforge_solver::KOptPhaseBuilder;
use solverforge_solver::heuristic::selector::{DefaultDistanceMeter, FromSolutionEntitySelector};
use solverforge_core::domain::PlanningSolution;
use solverforge_core::score::SimpleScore;
#[derive(Clone, Debug)]
struct Vehicle { visits: Vec<usize> }
#[derive(Clone, Debug)]
struct Plan {
vehicles: Vec<Vehicle>,
score: Option<SimpleScore>,
}
impl PlanningSolution for Plan {
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: &Plan, idx: usize) -> usize {
s.vehicles.get(idx).map_or(0, |v| v.visits.len())
}
fn sublist_remove(s: &mut Plan, idx: usize, start: usize, end: usize) -> Vec<usize> {
s.vehicles.get_mut(idx)
.map(|v| v.visits.drain(start..end).collect())
.unwrap_or_default()
}
fn sublist_insert(s: &mut Plan, idx: usize, pos: usize, items: Vec<usize>) {
if let Some(v) = s.vehicles.get_mut(idx) {
for (i, item) in items.into_iter().enumerate() {
v.visits.insert(pos + i, item);
}
}
}
let builder = KOptPhaseBuilder::<Plan, usize, _, _>::new(
DefaultDistanceMeter,
|| FromSolutionEntitySelector::new(0),
list_len,
sublist_remove,
sublist_insert,
"visits",
0,
);Implementations§
Source§impl<S, V, DM, ESF> KOptPhaseBuilder<S, V, DM, ESF>
impl<S, V, DM, ESF> KOptPhaseBuilder<S, V, DM, ESF>
Sourcepub fn new(
_distance_meter: DM,
_entity_selector_factory: ESF,
list_len: fn(&S, usize) -> usize,
sublist_remove: fn(&mut S, usize, usize, usize) -> Vec<V>,
sublist_insert: fn(&mut S, usize, usize, Vec<V>),
variable_name: &'static str,
descriptor_index: usize,
) -> Self
pub fn new( _distance_meter: DM, _entity_selector_factory: ESF, list_len: fn(&S, usize) -> usize, sublist_remove: fn(&mut S, usize, usize, usize) -> Vec<V>, sublist_insert: fn(&mut S, usize, usize, Vec<V>), variable_name: &'static str, descriptor_index: usize, ) -> Self
Creates a new k-opt phase builder.
The distance_meter and entity_selector_factory parameters are accepted
for API compatibility but not currently used (reserved for nearby selection).
Sourcepub fn with_step_limit(self, limit: u64) -> Self
pub fn with_step_limit(self, limit: u64) -> Self
Sets the step limit.
Sourcepub fn without_step_limit(self) -> Self
pub fn without_step_limit(self) -> Self
Removes the step limit.
Trait Implementations§
Source§impl<S, V, DM, ESF> Debug for KOptPhaseBuilder<S, V, DM, ESF>
impl<S, V, DM, ESF> Debug for KOptPhaseBuilder<S, V, DM, ESF>
Source§impl<S, V, DM, ESF, D> PhaseFactory<S, D> for KOptPhaseBuilder<S, V, DM, ESF>where
S: PlanningSolution,
V: Clone + Send + Sync + Debug + 'static,
DM: Send + Sync,
ESF: Send + Sync,
D: ScoreDirector<S>,
impl<S, V, DM, ESF, D> PhaseFactory<S, D> for KOptPhaseBuilder<S, V, DM, ESF>where
S: PlanningSolution,
V: Clone + Send + Sync + Debug + 'static,
DM: Send + Sync,
ESF: Send + Sync,
D: ScoreDirector<S>,
Auto Trait Implementations§
impl<S, V, DM, ESF> Freeze for KOptPhaseBuilder<S, V, DM, ESF>
impl<S, V, DM, ESF> RefUnwindSafe for KOptPhaseBuilder<S, V, DM, ESF>
impl<S, V, DM, ESF> Send for KOptPhaseBuilder<S, V, DM, ESF>
impl<S, V, DM, ESF> Sync for KOptPhaseBuilder<S, V, DM, ESF>
impl<S, V, DM, ESF> Unpin for KOptPhaseBuilder<S, V, DM, ESF>
impl<S, V, DM, ESF> UnwindSafe for KOptPhaseBuilder<S, V, DM, ESF>
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