Skip to main content

PlanningSolution

Trait PlanningSolution 

Source
pub trait PlanningSolution:
    Clone
    + Send
    + Sync
    + 'static {
    type Score: Score;

    // Required methods
    fn score(&self) -> Option<Self::Score>;
    fn set_score(&mut self, score: Option<Self::Score>);

    // Provided method
    fn is_initialized(&self) -> bool { ... }
}
Expand description

Marker trait for planning solutions.

A planning solution represents both the problem definition and the (potentially partial) solution. It contains:

  • Problem facts: Immutable input data
  • Planning entities: Things to be optimized
  • Score: The quality of the current solution

§Example

use solverforge_core::{PlanningSolution, score::SoftScore};

#[derive(Clone)]
struct NQueens {
    n: usize,
    rows: Vec<Option<usize>>,
    score: Option<SoftScore>,
}

impl PlanningSolution for NQueens {
    type Score = SoftScore;

    fn score(&self) -> Option<Self::Score> {
        self.score
    }

    fn set_score(&mut self, score: Option<Self::Score>) {
        self.score = score;
    }
}

For complex solutions, use the #[derive(PlanningSolution)] macro from solverforge-macros.

§Thread Safety

Planning solutions must be Send + Sync to support multi-threaded solving.

Required Associated Types§

Required Methods§

Source

fn score(&self) -> Option<Self::Score>

Source

fn set_score(&mut self, score: Option<Self::Score>)

Provided Methods§

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§