Skip to main content

SimulatedAnnealingParameters

Struct SimulatedAnnealingParameters 

Source
pub struct SimulatedAnnealingParameters<T, M>
where T: Clone, M: MutationOperator<T>,
{ pub mutation_operator: M, pub mutation_probability: f64, pub initial_temperature: f64, pub minimum_temperature: f64, pub cooling_rate: f64, pub termination_criteria: TerminationCriteria, pub random_seed: Option<u64>, /* private fields */ }

Fields§

§mutation_operator: M§mutation_probability: f64§initial_temperature: f64§minimum_temperature: f64§cooling_rate: f64§termination_criteria: TerminationCriteria§random_seed: Option<u64>

Implementations§

Source§

impl<T, M> SimulatedAnnealingParameters<T, M>
where T: Clone, M: MutationOperator<T>,

Source

pub fn new( mutation_operator: M, mutation_probability: f64, initial_temperature: f64, cooling_rate: f64, termination_criteria: TerminationCriteria, ) -> Self

Examples found in repository?
examples/experiment_parallel_vs_sequential.rs (lines 59-65)
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        BitFlipMutation::new(),
40        0.12,
41        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(180)]),
42    )
43    .with_seed(111);
44
45    // Keep GA internally sequential to focus the comparison on experiment-level parallelism.
46    let genetic_algorithm_case = GeneticAlgorithmParameters::new(
47            80,
48            0.90,
49            0.06,
50            SinglePointCrossover::new(),
51            BitFlipMutation::new(),
52            BinaryTournamentSelection::new(),
53            TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(60)]),
54        )
55        .with_elite_size(1)
56        .with_seed(222)
57        .sequential();
58
59    let simulated_annealing_case = SimulatedAnnealingParameters::new(
60        BitFlipMutation::new(),
61        0.10,
62        45.0,
63        0.985,
64        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(220)]),
65    )
66    .with_seed(333);
67
68    let pso_case = PSOParameters::new(
69        50,
70        0.72,
71        1.49,
72        1.49,
73        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(120)]),
74    )
75    .with_velocity_clamp(4.0)
76    .with_seed(444);
77
78    let experiment = Experiment::new(problem)
79        .with_runs(runs)
80        .add_case(hill_climbing_case)
81        .add_case(genetic_algorithm_case)
82        .add_case(simulated_annealing_case)
83        .add_case(pso_case);
84
85    measure_result(|| {
86        if parallel {
87            experiment.with_parallel().execute()
88        } else {
89            experiment.sequential().execute()
90        }
91    })
92}
More examples
Hide additional examples
examples/mono_objective_experiment.rs (lines 52-58)
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            BitFlipMutation::new(),
36            0.12,
37            TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(180)]),
38        );
39
40    let genetic_algorithm_case = GeneticAlgorithmParameters::new(
41            80,
42            0.90,
43            0.06,
44            SinglePointCrossover::new(),
45            BitFlipMutation::new(),
46            BinaryTournamentSelection::new(),
47            TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(60)]),
48        )
49        .with_elite_size(1)
50        .with_threads(4);
51
52    let simulated_annealing_case = SimulatedAnnealingParameters::new(
53        BitFlipMutation::new(),
54        0.10,
55        45.0,
56        0.985,
57        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(220)]),
58    )
59    .with_seed(777);
60
61    let pso_case = PSOParameters::new(
62        50,
63        0.72,
64        1.49,
65        1.49,
66        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(120)]),
67    )
68    .with_velocity_clamp(4.0)
69    .with_seed(999);
70
71    let report = Experiment::new(problem)
72        .with_runs(24)
73        .add_case(hill_climbing_case)
74        .add_case(genetic_algorithm_case)
75        .add_case(simulated_annealing_case)
76        .add_case(pso_case)
77        .execute();
78
79    match report {
80        Ok(report) => println!("{}", report.to_text_table()),
81        Err(error) => eprintln!("Experiment execution failed: {}", error),
82    }
83}
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 66)
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        BitFlipMutation::new(),
40        0.12,
41        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(180)]),
42    )
43    .with_seed(111);
44
45    // Keep GA internally sequential to focus the comparison on experiment-level parallelism.
46    let genetic_algorithm_case = GeneticAlgorithmParameters::new(
47            80,
48            0.90,
49            0.06,
50            SinglePointCrossover::new(),
51            BitFlipMutation::new(),
52            BinaryTournamentSelection::new(),
53            TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(60)]),
54        )
55        .with_elite_size(1)
56        .with_seed(222)
57        .sequential();
58
59    let simulated_annealing_case = SimulatedAnnealingParameters::new(
60        BitFlipMutation::new(),
61        0.10,
62        45.0,
63        0.985,
64        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(220)]),
65    )
66    .with_seed(333);
67
68    let pso_case = PSOParameters::new(
69        50,
70        0.72,
71        1.49,
72        1.49,
73        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(120)]),
74    )
75    .with_velocity_clamp(4.0)
76    .with_seed(444);
77
78    let experiment = Experiment::new(problem)
79        .with_runs(runs)
80        .add_case(hill_climbing_case)
81        .add_case(genetic_algorithm_case)
82        .add_case(simulated_annealing_case)
83        .add_case(pso_case);
84
85    measure_result(|| {
86        if parallel {
87            experiment.with_parallel().execute()
88        } else {
89            experiment.sequential().execute()
90        }
91    })
92}
More examples
Hide additional examples
examples/mono_objective_experiment.rs (line 59)
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            BitFlipMutation::new(),
36            0.12,
37            TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(180)]),
38        );
39
40    let genetic_algorithm_case = GeneticAlgorithmParameters::new(
41            80,
42            0.90,
43            0.06,
44            SinglePointCrossover::new(),
45            BitFlipMutation::new(),
46            BinaryTournamentSelection::new(),
47            TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(60)]),
48        )
49        .with_elite_size(1)
50        .with_threads(4);
51
52    let simulated_annealing_case = SimulatedAnnealingParameters::new(
53        BitFlipMutation::new(),
54        0.10,
55        45.0,
56        0.985,
57        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(220)]),
58    )
59    .with_seed(777);
60
61    let pso_case = PSOParameters::new(
62        50,
63        0.72,
64        1.49,
65        1.49,
66        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(120)]),
67    )
68    .with_velocity_clamp(4.0)
69    .with_seed(999);
70
71    let report = Experiment::new(problem)
72        .with_runs(24)
73        .add_case(hill_climbing_case)
74        .add_case(genetic_algorithm_case)
75        .add_case(simulated_annealing_case)
76        .add_case(pso_case)
77        .execute();
78
79    match report {
80        Ok(report) => println!("{}", report.to_text_table()),
81        Err(error) => eprintln!("Experiment execution failed: {}", error),
82    }
83}

Trait Implementations§

Source§

impl<T, M> Clone for SimulatedAnnealingParameters<T, M>
where T: Clone + Clone, M: MutationOperator<T> + Clone,

Source§

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

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, M, P> ExperimentalCase<T, f64, P> for SimulatedAnnealingParameters<T, M>
where T: Clone + Send + Sync + 'static + Display + FromStr, M: MutationOperator<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, M> Freeze for SimulatedAnnealingParameters<T, M>
where M: Freeze,

§

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

§

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

§

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

§

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

§

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

§

impl<T, M> UnwindSafe for SimulatedAnnealingParameters<T, M>
where M: 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.