44 lines
1.0 KiB
Rust
44 lines
1.0 KiB
Rust
//! The weekly menu planner
|
|
//!
|
|
extern crate planner;
|
|
extern crate cookbook;
|
|
|
|
use std::fmt::Debug;
|
|
use std::fmt::Display;
|
|
use std::hash::Hash;
|
|
use cookbook::*;
|
|
use planner::{
|
|
*, Value,
|
|
solver::{
|
|
Variables,
|
|
Domain,
|
|
Problem
|
|
}
|
|
};
|
|
|
|
|
|
fn pretty_output<K: Eq + Hash + Debug>(res: &Variables<Value, K>) -> String {
|
|
let mut repr = String::new();
|
|
for (var,value) in res {
|
|
let value = match value {
|
|
Some(rec) => &rec.title,
|
|
None => "---",
|
|
};
|
|
repr.push_str(&format!("{:?} => {}\n", var, value));
|
|
}
|
|
repr
|
|
}
|
|
|
|
fn main() {
|
|
let conn = establish_connection();
|
|
let possible_values = recipes::load_all(&conn);
|
|
let domain = Domain::new(possible_values);
|
|
let mut problem = Problem::build();
|
|
for (var, dom, ini) in template::Template::generate_variables(&domain) {
|
|
problem = problem.add_variable(var, dom, ini);
|
|
}
|
|
let mut problem = problem.finish();
|
|
let results = problem.solve_all();
|
|
println!("{:?}", pretty_output(results.first().unwrap()));
|
|
}
|