helloworld/
helloworld.rs

1//!
2//!  Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved.
3//!
4//!  File : helloworld.rs
5//!
6//!  The most basic example of how to get started with MOSEK.
7//!
8
9extern crate mosek;
10
11use mosek::{Task,Boundkey,Objsense,Soltype};
12
13fn main() -> Result<(),String> {
14    /* Create the optimization task. */
15    let mut task = match Task::new() {
16        Some(e) => e,
17        None => return Err("Failed to create task".to_string()),
18        };
19
20    task.append_vars(1)?;                           // 1 variable x
21    task.put_c_j(0, 1.0)?;                          // c_0 = 1.0
22    task.put_var_bound(0, Boundkey::RA, 2.0, 3.0)?; // 2.0 <= x <= 3.0
23    task.put_obj_sense(Objsense::MINIMIZE)?;        // minimize
24
25    task.optimize()?;                               // Optimize
26
27    let mut x = vec![0.0; 1];
28    task.get_xx(Soltype::ITR, x.as_mut_slice())?;   // Get solution
29    println!("Solution x = {}", x[0]);              // Print solution
30    return Result::Ok(());
31}
32
33#[cfg(test)]
34mod tests {
35    #[test]
36    fn test() {
37        super::main().unwrap();
38    }
39}