Skip to content

Commit d07c678

Browse files
committed
Method to set the objective coeff vector
1 parent 3aabc14 commit d07c678

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/model.rs

+24
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,18 @@ impl Model {
417417
ffi::SoPlex_setIntParam(*self.inner, crate::SCALAR_PARAM_ID, scalar_type.into());
418418
}
419419
}
420+
421+
/// Sets the objective function vector.
422+
///
423+
/// # Arguments
424+
/// * `objvals` - The objective function vector.
425+
pub fn set_obj_vals(&mut self, objvals: &mut [f64]) {
426+
let num_cols = self.num_cols();
427+
assert_eq!(objvals.len(), num_cols, "objvals must have the same length as the number of columns");
428+
unsafe {
429+
ffi::SoPlex_changeObjReal(*self.inner, objvals.as_mut_ptr(), objvals.len() as i32);
430+
}
431+
}
420432
}
421433

422434
/// A solved linear programming model.
@@ -690,4 +702,16 @@ mod tests {
690702
assert_eq!(result, Status::Optimal);
691703
assert!((lp.obj_val() - 5.0).abs() < 1e-6);
692704
}
705+
706+
#[test]
707+
fn set_objective() {
708+
let mut lp = Model::new();
709+
lp.add_col([], 1.0, 1.0, 1.0);
710+
lp.add_col([], 1.0, 1.0, 1.0);
711+
lp.set_obj_vals(&mut [2.0, 3.0]);
712+
let lp = lp.optimize();
713+
let result = lp.status();
714+
assert_eq!(result, Status::Optimal);
715+
assert!((lp.obj_val() - 5.0).abs() < 1e-6);
716+
}
693717
}

0 commit comments

Comments
 (0)