pub struct ListConstructionPhaseBuilder<S, E>{ /* private fields */ }Expand description
Builder for creating list construction phases.
This builder creates phases that assign unassigned list elements to entities using a round-robin strategy. Ideal for VRP-style problems where visits need to be distributed across vehicles.
§Type Parameters
S- The planning solution typeE- The element type (e.g., visit index)
§Example
use solverforge_solver::{ListConstructionPhase, ListConstructionPhaseBuilder};
use solverforge_core::domain::PlanningSolution;
use solverforge_core::score::SimpleScore;
#[derive(Clone)]
struct Vehicle { visits: Vec<usize> }
#[derive(Clone)]
struct Plan { vehicles: Vec<Vehicle>, visits: Vec<()>, 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; }
}
let builder = ListConstructionPhaseBuilder::<Plan, usize>::new(
|plan| plan.visits.len(),
|plan| plan.vehicles.iter().flat_map(|v| v.visits.iter().copied()).collect(),
|plan| plan.vehicles.len(),
|plan, entity_idx, element| { plan.vehicles[entity_idx].visits.push(element); },
|idx| idx,
"visits",
1,
);
// Create a concrete phase:
let phase: ListConstructionPhase<Plan, usize> = builder.create_phase();Implementations§
Source§impl<S, E> ListConstructionPhaseBuilder<S, E>
impl<S, E> ListConstructionPhaseBuilder<S, E>
Sourcepub fn new(
element_count: fn(&S) -> usize,
get_assigned: fn(&S) -> Vec<E>,
entity_count: fn(&S) -> usize,
assign_element: fn(&mut S, usize, E),
index_to_element: fn(usize) -> E,
variable_name: &'static str,
descriptor_index: usize,
) -> Self
pub fn new( element_count: fn(&S) -> usize, get_assigned: fn(&S) -> Vec<E>, entity_count: fn(&S) -> usize, assign_element: fn(&mut S, usize, E), index_to_element: fn(usize) -> E, variable_name: &'static str, descriptor_index: usize, ) -> Self
Creates a new list construction phase builder.
Sourcepub fn create_phase(&self) -> ListConstructionPhase<S, E>
pub fn create_phase(&self) -> ListConstructionPhase<S, E>
Creates the list construction phase.
Trait Implementations§
Source§impl<S, E, D> PhaseFactory<S, D> for ListConstructionPhaseBuilder<S, E>where
S: PlanningSolution,
E: Copy + PartialEq + Eq + Hash + Send + Sync + 'static,
D: ScoreDirector<S>,
impl<S, E, D> PhaseFactory<S, D> for ListConstructionPhaseBuilder<S, E>where
S: PlanningSolution,
E: Copy + PartialEq + Eq + Hash + Send + Sync + 'static,
D: ScoreDirector<S>,
Auto Trait Implementations§
impl<S, E> Freeze for ListConstructionPhaseBuilder<S, E>
impl<S, E> RefUnwindSafe for ListConstructionPhaseBuilder<S, E>where
S: RefUnwindSafe,
E: RefUnwindSafe,
impl<S, E> Send for ListConstructionPhaseBuilder<S, E>
impl<S, E> Sync for ListConstructionPhaseBuilder<S, E>
impl<S, E> Unpin for ListConstructionPhaseBuilder<S, E>
impl<S, E> UnwindSafe for ListConstructionPhaseBuilder<S, E>where
S: UnwindSafe,
E: 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
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