KOptPhaseBuilder

Struct KOptPhaseBuilder 

Source
pub struct KOptPhaseBuilder<S, V, DM, ESF>
where S: PlanningSolution, V: Clone + Send + Sync + Debug + 'static,
{ /* private fields */ }
Expand description

Builder for creating k-opt local search phases.

§Type Parameters

  • S - The planning solution type
  • V - The list element value type (e.g., usize for 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>
where S: PlanningSolution, V: Clone + Send + Sync + Debug + 'static,

Source

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).

Source

pub fn with_k(self, k: usize) -> Self

Sets the k value for k-opt (2-5).

Source

pub fn with_step_limit(self, limit: u64) -> Self

Sets the step limit.

Source

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>
where S: PlanningSolution, V: Clone + Send + Sync + Debug + 'static,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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>,

Source§

type Phase = KOptPhase<S, V>

The concrete phase type produced by this factory.
Source§

fn create(&self) -> Self::Phase

Creates a new phase instance with concrete type.

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>
where DM: Send, ESF: Send,

§

impl<S, V, DM, ESF> Sync for KOptPhaseBuilder<S, V, DM, ESF>
where DM: Sync, ESF: Sync,

§

impl<S, V, DM, ESF> Unpin for KOptPhaseBuilder<S, V, DM, ESF>
where S: Unpin, V: Unpin, DM: Unpin, ESF: Unpin,

§

impl<S, V, DM, ESF> UnwindSafe for KOptPhaseBuilder<S, V, DM, ESF>
where S: UnwindSafe, V: UnwindSafe, DM: UnwindSafe, ESF: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more