Skip to main content

parameters/
parameters.rs

1//
2//   Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved.
3//
4//   File :      parameters.rs
5//
6//   Purpose :   Demonstrates a very simple example about how to get/set
7//               parameters with MOSEK Julia API
8//
9
10extern crate mosek;
11
12use mosek::{Task,Iparam,Dparam,Dinfitem,Iinfitem,Optimizertype,Basindtype};
13
14fn main() -> Result<(),String> {
15    let mut task = Task::new().unwrap();
16    println!("Test MOSEK parameter get/set functions");
17
18    // Set log level (integer parameter)
19    task.put_int_param(Iparam::LOG, 1)?;
20    // Select interior-point optimizer... (integer parameter)
21    task.put_int_param(Iparam::OPTIMIZER, Optimizertype::INTPNT)?;
22    // ... without basis identification (integer parameter)
23    task.put_int_param(Iparam::INTPNT_BASIS,Basindtype::NEVER)?;
24    // Set relative gap tolerance (double parameter)
25    task.put_dou_param(Dparam::INTPNT_CO_TOL_REL_GAP, 1.0e-7)?;
26
27    // The same using explicit string names
28    task.put_param("MSK_DPAR_INTPNT_CO_TOL_REL_GAP", "1.0e-7")?;
29    task.put_na_dou_param("MSK_DPAR_INTPNT_CO_TOL_REL_GAP",  1.0e-7 )?;
30
31    // Incorrect value
32
33    if let Err(_) = task.put_dou_param(Dparam::INTPNT_CO_TOL_REL_GAP, -1.0) {
34        println!("Wrong parameter value");
35    }
36
37
38    let param = task.get_dou_param(Dparam::INTPNT_CO_TOL_REL_GAP)?;
39    println!("Current value for parameter intpnt_co_tol_rel_gap = {}",param);
40
41    // Define and solve an optimization problem here
42    // optimize(task,)
43    // After optimization:
44
45    println!("Get MOSEK information items");
46
47    let tm = task.get_dou_inf(Dinfitem::OPTIMIZER_TIME)?;
48    let iter = task.get_int_inf(Iinfitem::INTPNT_ITER)?;
49
50    println!("Time: {}",tm);
51    println!("Iterations: {}",iter);
52    Ok(())
53}