SolverPhaseFactory

Trait SolverPhaseFactory 

Source
pub trait SolverPhaseFactory<S: PlanningSolution>: Send + Sync {
    // Required method
    fn create_phase(&self) -> Box<dyn Phase<S>>;
}
Expand description

Factory trait for creating phases.

Phase factories allow creating fresh phase instances for each solve, ensuring clean state between solves. This is essential because phases often maintain internal state (like step counters or tabu lists) that must be reset for each new solve.

§Implementing SolverPhaseFactory

There are two common ways to implement this trait:

  1. Use CloneablePhaseFactory for phases that implement Clone
  2. Use ClosurePhaseFactory with a closure that creates phases

§Example

use solverforge_solver::manager::SolverPhaseFactory;
use solverforge_solver::phase::Phase;
use solverforge_core::domain::PlanningSolution;
use solverforge_core::score::SimpleScore;

struct MyPhaseFactory;

impl SolverPhaseFactory<MySolution> for MyPhaseFactory {
    fn create_phase(&self) -> Box<dyn Phase<MySolution>> {
        // Create and return a new phase instance
        todo!("Create phase here")
    }
}

Required Methods§

Source

fn create_phase(&self) -> Box<dyn Phase<S>>

Creates a new phase instance.

This method is called once per solve to create a fresh phase with clean state.

Implementors§

Source§

impl<S, F> SolverPhaseFactory<S> for ClosurePhaseFactory<S, F>
where S: PlanningSolution, F: Fn() -> Box<dyn Phase<S>> + Send + Sync,

Source§

impl<S, M, F> SolverPhaseFactory<S> for ConstructionPhaseFactory<S, M, F>
where S: PlanningSolution + 'static, M: Move<S> + Clone + Send + Sync + 'static, F: Fn() -> Box<dyn EntityPlacer<S, M>> + Send + Sync,

Source§

impl<S, M, F> SolverPhaseFactory<S> for LocalSearchPhaseFactory<S, M, F>
where S: PlanningSolution + 'static, M: Move<S> + Clone + Send + Sync + 'static, F: Fn() -> Box<dyn MoveSelector<S, M>> + Send + Sync,

Source§

impl<S, P> SolverPhaseFactory<S> for CloneablePhaseFactory<P>
where S: PlanningSolution, P: Phase<S> + Clone + Send + Sync + 'static,