Skip to main content

HighsOptions

Struct HighsOptions 

Source
pub struct HighsOptions {
    pub universal: UniversalOptions,
    pub mip_gap: Option<f64>,
    pub presolve: Option<HighsPresolve>,
    pub method: Option<HighsMethod>,
    pub parallel: Option<bool>,
}
Expand description

HiGHS-specific solver options.

Fields§

§universal: UniversalOptions§mip_gap: Option<f64>§presolve: Option<HighsPresolve>§method: Option<HighsMethod>§parallel: Option<bool>

Implementations§

Source§

impl HighsOptions

Source

pub fn mip_gap(self, gap: f64) -> HighsOptions

Examples found in repository?
examples/lot_sizing.rs (line 100)
57fn main() -> Result<(), Box<dyn std::error::Error>> {
58    const T: usize = 12;
59
60    let demand: [f64; T] =
61        [120.0, 90.0, 80.0, 140.0, 160.0, 200.0, 220.0, 190.0, 150.0, 130.0, 100.0, 170.0];
62    let prod_cost: [f64; T] = [5.0, 5.0, 5.0, 5.5, 6.0, 6.5, 6.5, 6.0, 5.5, 5.0, 5.0, 5.5];
63    let setup_cost = 500.0;
64    let hold_cost = 2.0;
65    let capacity = 300.0;
66    let initial_inventory = 50.0;
67    let safety_stock = 30.0;
68
69    let m = Model::new("lot_sizing");
70    let periods = Set::range(0..T);
71
72    variable!(m, 0.0 <= x[t in periods] <= capacity);
73    variable!(m, h[t in periods] >= 0.0);
74    variable!(m, s[t in periods], Bin);
75
76    constraint!(m, inv_bal0, h[0] - x[0] == initial_inventory - demand[0]);
77    constraint!(m, inv_bal[t in 1..T], h[t] - h[t - 1] - x[t] == -demand[t]);
78    constraint!(m, setup[t in periods], x[t] <= capacity * s[t]);
79    constraint!(m, safety_stock, h[T - 1] >= safety_stock);
80
81    objective!(
82        m,
83        Min,
84        sum!(prod_cost[t] * x[t] + setup_cost * s[t] + hold_cost * h[t] for t in periods)
85    );
86
87    #[cfg(feature = "gurobi")]
88    let result = {
89        let opts = GurobiOptions::default()
90            .time_limit(std::time::Duration::from_secs(60))
91            .mip_gap(1e-4)
92            .verbose(true);
93        Gurobi.solve(&m, &opts)?
94    };
95
96    #[cfg(all(feature = "highs", not(feature = "gurobi")))]
97    let result = {
98        let opts = HighsOptions::default()
99            .time_limit(std::time::Duration::from_secs(60))
100            .mip_gap(1e-4)
101            .verbose(true);
102        Highs.solve(&m, &opts)?
103    };
104
105    println!("\nLot-Sizing Result");
106    println!("Status    : {:?}", result.status);
107    if let Some(obj) = result.objective() {
108        println!("Total cost: {obj:.2}");
109    }
110
111    println!(
112        "\n{:<8} {:>10} {:>10} {:>8} {:>12}",
113        "Period", "Produce", "Inventory", "Active", "Period cost"
114    );
115    println!("{}", "-".repeat(55));
116
117    let mut total_check = 0.0;
118    for t in 0..T {
119        let xt = result.value_of(x[t]).unwrap_or(0.0);
120        let ht = result.value_of(h[t]).unwrap_or(0.0);
121        let st = result.value_of(s[t]).unwrap_or(0.0);
122        let period_cost = prod_cost[t] * xt + setup_cost * st + hold_cost * ht;
123        total_check += period_cost;
124        println!(
125            "{:<8} {:>10.1} {:>10.1} {:>8} {:>12.2}",
126            t + 1,
127            xt,
128            ht,
129            if (st - 1.0).abs() < 1e-6 { "Yes" } else { "No" },
130            period_cost
131        );
132    }
133    println!("{}", "-".repeat(55));
134    println!("{:<8} {:>10} {:>10} {:>8} {:>12.2}", "TOTAL", "", "", "", total_check);
135
136    Ok(())
137}
Source

pub fn presolve(self, p: HighsPresolve) -> HighsOptions

Source

pub fn method(self, m: HighsMethod) -> HighsOptions

Source

pub fn parallel(self, on: bool) -> HighsOptions

Trait Implementations§

Source§

impl Clone for HighsOptions

Source§

fn clone(&self) -> HighsOptions

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HighsOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for HighsOptions

Source§

fn default() -> HighsOptions

Returns the “default value” for a type. Read more
Source§

impl HasUniversal for HighsOptions

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UniversalOptionsExt for T
where T: HasUniversal,

Source§

fn time_limit(self, d: Duration) -> Self

Source§

fn threads(self, n: u32) -> Self

Source§

fn verbose(self, on: bool) -> Self