Skip to main content

func

Function func 

Source
pub fn func<F>(bounds: Vec<Bound>, f: F) -> Func<F>
where F: Fn(&[f64]) -> f64,
Expand description

A Problem defined inline by a closure and a bounds vector.

use forge_core::problem::{func, Problem};
let sphere = func(vec![(-5.0, 5.0); 3], |x| x.iter().map(|v| v * v).sum());
assert_eq!(sphere.dim(), 3);
assert_eq!(sphere.objective(&[0.0, 0.0, 0.0]), 0.0);