Skip to content

Commit

Permalink
revise sensitivity.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
ubnt-intrepid committed Aug 29, 2016
1 parent 49f4551 commit fa44092
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 1 addition & 5 deletions examples/sensitivity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
extern crate gurobi;
use gurobi::*;
use std::env::args;
use std::mem::transmute;

fn main() {
let env = Env::new("").unwrap();
Expand All @@ -31,10 +30,7 @@ fn main() {
// iterate through unfixed, binary variables in model
let vars: Vec<_> = model.get_vars().cloned().collect();
for (v, &orig_x) in vars.iter().zip(orig_sol.iter()) {
let lb = v.get(&model, attr::LB).unwrap();
let ub = v.get(&model, attr::UB).unwrap();
let vtype = v.get(&model, attr::VType).unwrap();
let vtype = unsafe { transmute::<_, u8>(vtype) } as char;
let (vtype, lb, ub) = v.get_type(&model).unwrap();

if lb == 0.0 && ub == 1.0 && (vtype == 'B' || vtype == 'I') {
let vname = v.get(&model, attr::VarName).unwrap();
Expand Down
10 changes: 10 additions & 0 deletions src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ pub trait Proxy: ProxyBase {
#[derive(Clone)]
pub struct Var(Rc<Cell<i32>>);

impl Var {
pub fn get_type(&self, model: &Model) -> Result<(char, f64, f64)> {
let lb = try!(self.get(&model, attr::exports::LB));
let ub = try!(self.get(&model, attr::exports::UB));
let vtype = try!(self.get(&model, attr::exports::VType));
let vtype = unsafe { transmute::<_, u8>(vtype) } as char;
Ok((vtype, lb, ub))
}
}

/// Proxy object of a linear constraint
#[derive(Clone)]
pub struct Constr(Rc<Cell<i32>>);
Expand Down

0 comments on commit fa44092

Please sign in to comment.