pub fn grid_search<A: 'static + Send + Sync, T: 'static + Copy + Send + Sync + Default + Debug + SampleUniform + PartialOrd + AddAssign + Add<Output = T> + Sub<Output = T> + Div<Output = T> + Mul<Output = T> + FromPrimitive, const N: usize>(
ranges: [Range<T>; N],
f: fn(&[T; N], Option<Arc<A>>) -> f64,
evaluation_data: Option<Arc<A>>,
polling: Option<Polling>,
threads: Option<usize>,
points: [u64; N],
) -> [T; N]Expand description
Evaluate all combinations of values from the 3 values where:
- Value 1 covers
10values at equal intervals from0..10(0,1,2,3,4,5,6,7,8,9). - Value 2 covers
11values at equal intervals from5..15. - Value 3 covers
12values at equal intervals from10..20.
Printing progress every 10ms and exiting early if a value is found which is less than or equal to 15..
use std::{sync::Arc,time::Duration};
use simple_optimization::{grid_search, Polling};
fn simple_function(list: &[f64; 3], _: Option<Arc<()>>) -> f64 { list.iter().sum() }
let best = grid_search(
[0f64..10f64, 5f64..15f64, 10f64..20f64], // Value ranges.
simple_function, // Evaluation function.
None, // No additional evaluation data.
// Polling every `10ms`, printing progress (`true`), exiting early if `15.` or less is reached, and not printing thread execution data (`false`).
Some(Polling { poll_rate: Duration::from_millis(5), printing: true, early_exit_minimum: Some(15.), thread_execution_reporting: false }),
None, // We don't specify the number of threads.
// Take `10` samples along range `0` (`0..10`), `11` along range `1` (`5..15`)
// and `12` along range `2` (`10..20`).
// In total taking `10*11*12=1320` samples.
[10,11,12],
);
assert_eq!(simple_function(&best, None), 15.);Due to specific design the threads parameter is excluded for now.