Simple, lightweight optimisation algorithms in pure Rust
This crate aims to mimic the scipy.optimize module in pure Rust.
This crate has an asynchronous API and all examples use Tokio. To start your Cargo.toml should at least include
toml
[dependencies]
swoop = { "git" = "https://github.com/benjaminjellis/swoop" }
tokio = { version = "1", features = ["full"] }
To minimise the function f(x) = 3x^2 + 4x + 50
in the bound -10 <= x <= 10
you can use the bounded
optimiser
```rust use swoop::minimise_scalar::{bounded, ScalarObjectiveFunction}; use swoop::SwoopErrors;
struct MyObjectiveFunction { a: f64, b: f64, c: f64, }
impl MyObjectiveFunction { fn new(a: f64, b: f64, c: f64) -> Self { Self { a, b, c } } }
impl ScalarObjectiveFunction for MyObjectiveFunction { fn evaluate(&self, x: f64) -> f64 { self.a * x.powf(2f64) + self.b * x + self.c } }
async fn main() -> Result<(), SwoopErrors> { let objectivefunction = MyObjectiveFunction::new(3f64, 4f64, 50f64); let result = bounded(objectivefunction, (-10f64, 10f64), 500usize).await?; println!("{:?}", result); Ok(()) } ```