Browse Source

Changed test case

karmarkar
Thomas Johnson 3 years ago
parent
commit
daf786bba5
  1. 53
      src/affine_scaling.rs

53
src/affine_scaling.rs

@ -660,20 +660,55 @@ macro_rules! linear_vars {
mod test {
use super::*;
// #[test]
// fn inequality_test() {
// linear_vars![x, y, z, w];
// let mut constraints = Vec::<LeqInequality>::new();
// constraints.push(Expr::from(&x) + &y + &z + &w << 5.0.into());
// constraints.push(Expr::from(&x) << 4.0.into());
// constraints.push(Expr::from(&y) << 4.0.into());
// constraints.push(Expr::from(&z) << 4.0.into());
// constraints.push(Expr::from(&w) << 4.0.into());
// let mut objective = LinearCombination::new();
// objective.insert_variable(x.clone(), 1.0);
// objective.insert_variable(y.clone(), 2.0);
// objective.insert_variable(z.clone(), 3.0);
// objective.insert_variable(w.clone(), 4.0);
// println!("Maximize {}", objective);
// println!("subject to");
// for constraint in constraints.iter() {
// println!("{}", constraint);
// }
//
// let sf = StandardFormLP::from_ineqs_and_objective(constraints, objective);
// println!("");
// println!("{}", sf);
// let frp = sf.clone().to_feasible_region_problem();
// println!("");
// println!("{}", frp);
// let len = frp.vars.len();
// let mut fras =
// AffineScaling::from_feasible_point(frp, DVector::from_element(len, 1.0)).unwrap();
// println!("");
// println!("{}", fras);
//
// for _ in 0..10 {
// println!("{:?}", fras.iterate());
// println!("{}", fras.x);
// }
// }
#[test]
fn inequality_test() {
linear_vars![x, y, z, w];
linear_vars![x, y];
let mut constraints = Vec::<LeqInequality>::new();
constraints.push(Expr::from(&x) + &y + &z + &w << 5.0.into());
constraints.push(Expr::from(&x) << 4.0.into());
constraints.push(Expr::from(&y) << 4.0.into());
constraints.push(Expr::from(&z) << 4.0.into());
constraints.push(Expr::from(&w) << 4.0.into());
constraints.push(Term::from(&x) * 50.0 + Term::from(&y) * 24.0 << 2400.0.into());
constraints.push(Term::from(&x) * 30.0 + Term::from(&y) * 33.0 << 2100.0.into());
constraints.push(Expr::from(-Term::from(&x)) << Expr::from(-45.0));
constraints.push(Expr::from(-Term::from(&y)) << Expr::from(-5.0));
let mut objective = LinearCombination::new();
objective.insert_variable(x.clone(), 1.0);
objective.insert_variable(y.clone(), 2.0);
objective.insert_variable(z.clone(), 3.0);
objective.insert_variable(w.clone(), 4.0);
objective.insert_variable(x.clone(), 2.0);
println!("Maximize {}", objective);
println!("subject to");
for constraint in constraints.iter() {

Loading…
Cancel
Save