optim/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use std::collections::HashMap;

pub struct Model {
  variables: HashMap<String, Option<f64>>,
  constraints: Vec<Constraint>,
}

impl Model {
  pub fn new() -> Self {
    Model {
      variables: HashMap::new(),
      constraints: vec![],
    }
  }

  pub fn solve() -> Result<Solution, SolverError> {
    Ok(Solution)
  }

  pub fn add_variable(&mut self, variable: Variable) {
    self.variables.insert(variable.name, variable.value);
  }

  pub fn add_constraint(&mut self, constraint: Constraint) {}
  pub fn maximise(&mut self, variable: Variable) {}
  pub fn minimise(&mut self, variable: Variable) {}
}

pub struct Variable {
  name: String,
  value: Option<f64>,
}

impl Variable {
  pub fn new(name: String) -> Self {
    Variable { name, value: None }
  }
}

pub struct Constraint;
pub struct Solution;
pub struct SolverError;