Skip to main content

SimulatedAnnealingParameters

Struct SimulatedAnnealingParameters 

Source
pub struct SimulatedAnnealingParameters<T, N>
where T: Clone, N: NeighborhoodOperator<T>,
{ pub neighborhood: N, pub initial_temperature: f64, pub minimum_temperature: f64, pub cooling_rate: f64, pub termination_criteria: TerminationCriteria, pub random_seed: Option<u64>, /* private fields */ }

Fields§

§neighborhood: N§initial_temperature: f64§minimum_temperature: f64§cooling_rate: f64§termination_criteria: TerminationCriteria§random_seed: Option<u64>

Implementations§

Source§

impl<T, N> SimulatedAnnealingParameters<T, N>
where T: Clone, N: NeighborhoodOperator<T>,

Source

pub fn new( neighborhood: N, initial_temperature: f64, cooling_rate: f64, termination_criteria: TerminationCriteria, ) -> Self

Examples found in repository?
examples/experiment_parallel_vs_sequential.rs (lines 58-63)
35fn run_experiment(parallel: bool, runs: usize) -> Result<(Duration, ExperimentReport), String> {
36    let problem = build_problem();
37
38    let hill_climbing_case = HillClimbingParameters::new(
39        BitFlipNeighborhood::new(),
40        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(180)]),
41    )
42    .with_seed(111);
43
44    // Keep GA internally sequential to focus the comparison on experiment-level parallelism.
45    let genetic_algorithm_case = GeneticAlgorithmParameters::new(
46            80,
47            0.90,
48            0.06,
49            SinglePointCrossover::new(),
50            BitFlipMutation::new(),
51            BinaryTournamentSelection::new(),
52            TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(60)]),
53        )
54        .with_elite_size(1)
55        .with_seed(222)
56        .sequential();
57
58    let simulated_annealing_case = SimulatedAnnealingParameters::new(
59        BitFlipNeighborhood::new(),
60        45.0,
61        0.985,
62        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(220)]),
63    )
64    .with_seed(333);
65
66    let pso_case = PSOParameters::new(
67        50,
68        0.72,
69        1.49,
70        1.49,
71        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(120)]),
72    )
73    .with_velocity_clamp(4.0)
74    .with_seed(444);
75
76    let experiment = Experiment::new(problem)
77        .with_runs(runs)
78        .add_case(hill_climbing_case)
79        .add_case(genetic_algorithm_case)
80        .add_case(simulated_annealing_case)
81        .add_case(pso_case);
82
83    measure_result(|| {
84        if parallel {
85            experiment.with_parallel().execute()
86        } else {
87            experiment.sequential().execute()
88        }
89    })
90}
More examples
Hide additional examples
examples/mono_objective_experiment.rs (lines 51-56)
13fn main() {
14    let problem = KnapsackBuilder::new()
15        .with_capacity(150.0)
16        .add_item(1.0, 2.0)
17        .add_item(1.0, 2.0)
18        .add_item(2.0, 6.0)
19        .add_item(2.0, 6.5)
20        .add_item(3.0, 7.0)
21        .add_item(10.0, 20.0)
22        .add_item(20.0, 30.0)
23        .add_item(30.0, 60.0)
24        .add_item(35.0, 65.0)
25        .add_item(45.0, 100.0)
26        .add_item(55.0, 120.0)
27        .add_item(75.0, 211.0)
28        .add_item(75.0, 211.0)
29        .add_item(80.0, 160.0)
30        .add_item(90.0, 301.0)
31        .add_item(150.0, 301.0)
32        .build();
33
34    let hill_climbing_case = HillClimbingParameters::new(
35            BitFlipNeighborhood::new(),
36            TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(180)]),
37        );
38
39    let genetic_algorithm_case = GeneticAlgorithmParameters::new(
40            80,
41            0.90,
42            0.06,
43            SinglePointCrossover::new(),
44            BitFlipMutation::new(),
45            BinaryTournamentSelection::new(),
46            TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(60)]),
47        )
48        .with_elite_size(1)
49        .with_threads(4);
50
51    let simulated_annealing_case = SimulatedAnnealingParameters::new(
52        BitFlipNeighborhood::new(),
53        45.0,
54        0.985,
55        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(220)]),
56    )
57    .with_seed(777);
58
59    let pso_case = PSOParameters::new(
60        50,
61        0.72,
62        1.49,
63        1.49,
64        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(120)]),
65    )
66    .with_velocity_clamp(4.0)
67    .with_seed(999);
68
69    let report = Experiment::new(problem)
70        .with_runs(24)
71        .add_case(hill_climbing_case)
72        .add_case(genetic_algorithm_case)
73        .add_case(simulated_annealing_case)
74        .add_case(pso_case)
75        .execute();
76
77    match report {
78        Ok(report) => println!("{}", report.to_text_table()),
79        Err(error) => eprintln!("Experiment execution failed: {}", error),
80    }
81}
Source

pub fn with_minimum_temperature(self, minimum_temperature: f64) -> Self

Source

pub fn with_seed(self, seed: u64) -> Self

Examples found in repository?
examples/experiment_parallel_vs_sequential.rs (line 64)
35fn run_experiment(parallel: bool, runs: usize) -> Result<(Duration, ExperimentReport), String> {
36    let problem = build_problem();
37
38    let hill_climbing_case = HillClimbingParameters::new(
39        BitFlipNeighborhood::new(),
40        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(180)]),
41    )
42    .with_seed(111);
43
44    // Keep GA internally sequential to focus the comparison on experiment-level parallelism.
45    let genetic_algorithm_case = GeneticAlgorithmParameters::new(
46            80,
47            0.90,
48            0.06,
49            SinglePointCrossover::new(),
50            BitFlipMutation::new(),
51            BinaryTournamentSelection::new(),
52            TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(60)]),
53        )
54        .with_elite_size(1)
55        .with_seed(222)
56        .sequential();
57
58    let simulated_annealing_case = SimulatedAnnealingParameters::new(
59        BitFlipNeighborhood::new(),
60        45.0,
61        0.985,
62        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(220)]),
63    )
64    .with_seed(333);
65
66    let pso_case = PSOParameters::new(
67        50,
68        0.72,
69        1.49,
70        1.49,
71        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(120)]),
72    )
73    .with_velocity_clamp(4.0)
74    .with_seed(444);
75
76    let experiment = Experiment::new(problem)
77        .with_runs(runs)
78        .add_case(hill_climbing_case)
79        .add_case(genetic_algorithm_case)
80        .add_case(simulated_annealing_case)
81        .add_case(pso_case);
82
83    measure_result(|| {
84        if parallel {
85            experiment.with_parallel().execute()
86        } else {
87            experiment.sequential().execute()
88        }
89    })
90}
More examples
Hide additional examples
examples/mono_objective_experiment.rs (line 57)
13fn main() {
14    let problem = KnapsackBuilder::new()
15        .with_capacity(150.0)
16        .add_item(1.0, 2.0)
17        .add_item(1.0, 2.0)
18        .add_item(2.0, 6.0)
19        .add_item(2.0, 6.5)
20        .add_item(3.0, 7.0)
21        .add_item(10.0, 20.0)
22        .add_item(20.0, 30.0)
23        .add_item(30.0, 60.0)
24        .add_item(35.0, 65.0)
25        .add_item(45.0, 100.0)
26        .add_item(55.0, 120.0)
27        .add_item(75.0, 211.0)
28        .add_item(75.0, 211.0)
29        .add_item(80.0, 160.0)
30        .add_item(90.0, 301.0)
31        .add_item(150.0, 301.0)
32        .build();
33
34    let hill_climbing_case = HillClimbingParameters::new(
35            BitFlipNeighborhood::new(),
36            TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(180)]),
37        );
38
39    let genetic_algorithm_case = GeneticAlgorithmParameters::new(
40            80,
41            0.90,
42            0.06,
43            SinglePointCrossover::new(),
44            BitFlipMutation::new(),
45            BinaryTournamentSelection::new(),
46            TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(60)]),
47        )
48        .with_elite_size(1)
49        .with_threads(4);
50
51    let simulated_annealing_case = SimulatedAnnealingParameters::new(
52        BitFlipNeighborhood::new(),
53        45.0,
54        0.985,
55        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(220)]),
56    )
57    .with_seed(777);
58
59    let pso_case = PSOParameters::new(
60        50,
61        0.72,
62        1.49,
63        1.49,
64        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(120)]),
65    )
66    .with_velocity_clamp(4.0)
67    .with_seed(999);
68
69    let report = Experiment::new(problem)
70        .with_runs(24)
71        .add_case(hill_climbing_case)
72        .add_case(genetic_algorithm_case)
73        .add_case(simulated_annealing_case)
74        .add_case(pso_case)
75        .execute();
76
77    match report {
78        Ok(report) => println!("{}", report.to_text_table()),
79        Err(error) => eprintln!("Experiment execution failed: {}", error),
80    }
81}

Trait Implementations§

Source§

impl<T, N> Clone for SimulatedAnnealingParameters<T, N>
where T: Clone + Clone, N: NeighborhoodOperator<T> + Clone,

Source§

fn clone(&self) -> SimulatedAnnealingParameters<T, N>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, N, P> ExperimentalCase<T, f64, P> for SimulatedAnnealingParameters<T, N>
where T: Clone + Send + Sync + 'static + Display + FromStr, N: NeighborhoodOperator<T> + Clone + Send + Sync + 'static, P: Problem<T, f64> + Sync,

Source§

fn algorithm_name(&self) -> &str

Source§

fn case_name(&self) -> String

Human-readable identifier for this concrete configuration.
Source§

fn parameters(&self) -> Vec<CaseParameter>

Returns generic parameter key/value pairs for reporting.
Source§

fn run(&self, problem: &P) -> Result<Box<dyn SolutionSet<T, f64>>, String>

Creates and executes the algorithm with its configured parameters.
Source§

fn parameters_as_text(&self) -> String

Helper to print all parameters in a single textual line.

Auto Trait Implementations§

§

impl<T, N> Freeze for SimulatedAnnealingParameters<T, N>
where N: Freeze,

§

impl<T, N> RefUnwindSafe for SimulatedAnnealingParameters<T, N>

§

impl<T, N> Send for SimulatedAnnealingParameters<T, N>
where N: Send, T: Send,

§

impl<T, N> Sync for SimulatedAnnealingParameters<T, N>
where N: Sync, T: Sync,

§

impl<T, N> Unpin for SimulatedAnnealingParameters<T, N>
where N: Unpin, T: Unpin,

§

impl<T, N> UnsafeUnpin for SimulatedAnnealingParameters<T, N>
where N: UnsafeUnpin,

§

impl<T, N> UnwindSafe for SimulatedAnnealingParameters<T, N>
where N: UnwindSafe, T: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.