diff --git a/crates/argmin/src/core/executor.rs b/crates/argmin/src/core/executor.rs index a4c546504..545849b38 100644 --- a/crates/argmin/src/core/executor.rs +++ b/crates/argmin/src/core/executor.rs @@ -70,7 +70,7 @@ where checkpoint: None, timeout: None, ctrlc: true, - timer: true, + timer: false, } } @@ -383,9 +383,9 @@ where self } - /// Enables or disables timing of individual iterations (default: enabled). + /// Enables or disables timing of individual iterations (default: false). /// - /// Setting this to false will silently be ignored in case a timeout is set. + /// In case a timeout is set, this will automatically be set to true. /// /// # Example /// @@ -766,7 +766,7 @@ mod tests { let problem = TestProblem::new(); let timeout = std::time::Duration::from_secs(2); - let executor = Executor::new(problem, solver); + let executor = Executor::new(problem, solver).timer(true); assert!(executor.timer); assert!(executor.timeout.is_none()); diff --git a/crates/argmin/src/core/state/iterstate.rs b/crates/argmin/src/core/state/iterstate.rs index d766b49e9..cc7899625 100644 --- a/crates/argmin/src/core/state/iterstate.rs +++ b/crates/argmin/src/core/state/iterstate.rs @@ -82,6 +82,8 @@ pub struct IterState { pub max_iters: u64, /// Evaluation counts pub counts: HashMap, + /// Update evaluation counts? + pub counting_enabled: bool, /// Time required so far pub time: Option, /// Status of optimization execution @@ -1040,6 +1042,7 @@ where last_best_iter: 0, max_iters: std::u64::MAX, counts: HashMap::new(), + counting_enabled: false, time: Some(instant::Duration::new(0, 0)), termination_status: TerminationStatus::NotTerminated, } @@ -1339,7 +1342,7 @@ where /// ``` /// # use std::collections::HashMap; /// # use argmin::core::{Problem, IterState, State, ArgminFloat}; - /// # let mut state: IterState, (), (), (), (), f64> = IterState::new(); + /// # let mut state: IterState, (), (), (), (), f64> = IterState::new().counting(true); /// # assert_eq!(state.counts, HashMap::new()); /// # state.counts.insert("test2".to_string(), 10u64); /// # @@ -1356,9 +1359,11 @@ where /// # assert_eq!(state.counts, hm); /// ``` fn func_counts(&mut self, problem: &Problem) { - for (k, &v) in problem.counts.iter() { - let count = self.counts.entry(k.to_string()).or_insert(0); - *count = v + if self.counting_enabled { + for (k, &v) in problem.counts.iter() { + let count = self.counts.entry(k.to_string()).or_insert(0); + *count = v + } } }