swoop 0.1.0

Simple, lightweight optimisation algorithms in pure Rust
Documentation
  • Coverage
  • 100%
    17 out of 17 items documented0 out of 4 items with examples
  • Size
  • Source code size: 36.02 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.18 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 15s Average build duration of successful builds.
  • all releases: 15s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • benjaminjellis

CircleCI MSRV version

swoop

Simple, lightweight optimisation algorithms in pure Rust

Motivation

This crate aims to mimic the scipy.optimize module in pure Rust.

Example

This crate has an asynchronous API and all examples use Tokio. To start your Cargo.toml should at least include

[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

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
    }
}

#[tokio::main]
async fn main() -> Result<(), SwoopErrors> {
    let objective_function = MyObjectiveFunction::new(3f64, 4f64, 50f64);
    let result = bounded(objective_function, (-10f64, 10f64), 500usize).await?;
    println!("{:?}", result);
    Ok(())
}