Struct Model

Source
pub struct Model { /* private fields */ }
Expand description

A model to solve

Implementations§

Source§

impl Model

Source

pub fn set_sense(&mut self, sense: Sense)

Set the optimization sense (minimize by default)

Source

pub fn new<P: Into<Problem<ColMatrix>>>(problem: P) -> Self

Create a Highs model to be optimized (but don’t solve it yet). If the given problem is a RowProblem, it will have to be converted to a ColProblem first, which takes an amount of time proportional to the size of the problem. Panics if the problem is incoherent

Source

pub fn try_new<P: Into<Problem<ColMatrix>>>( problem: P, ) -> Result<Self, HighsStatus>

Create a Highs model to be optimized (but don’t solve it yet). If the given problem is a RowProblem, it will have to be converted to a ColProblem first, which takes an amount of time proportional to the size of the problem. Returns an error if the problem is incoherent

Source

pub fn make_quiet(&mut self)

Prevents writing anything to the standard output or to files when solving the model

Source

pub fn set_option<STR: Into<Vec<u8>>, V: HighsOptionValue>( &mut self, option: STR, value: V, )

Set a custom parameter on the model. For the list of available options and their documentation, see: https://ergo-code.github.io/HiGHS/dev/options/definitions/

let mut model = ColProblem::default().optimise(Maximise);
model.set_option("presolve", "off"); // disable the presolver
model.set_option("solver", "ipm"); // use the ipm solver
model.set_option("time_limit", 30.0); // stop after 30 seconds
model.set_option("parallel", "on"); // use multiple cores
model.set_option("threads", 4); // solve on 4 threads
Source

pub fn solve(self) -> SolvedModel

Find the optimal value for the problem, panic if the problem is incoherent

Source

pub fn try_solve(self) -> Result<SolvedModel, HighsStatus>

Find the optimal value for the problem, return an error if the problem is incoherent

Source

pub fn add_row( &mut self, bounds: impl RangeBounds<f64>, row_factors: impl IntoIterator<Item = (Col, f64)>, ) -> Row

Adds a new constraint to the highs model.

Returns the added row index.

§Panics

If HIGHS returns an error status value.

Source

pub fn try_add_row( &mut self, bounds: impl RangeBounds<f64>, row_factors: impl IntoIterator<Item = (Col, f64)>, ) -> Result<Row, HighsStatus>

Tries to add a new constraint to the highs model.

Returns the added row index, or the error status value if HIGHS returned an error status.

Source

pub fn add_col( &mut self, col_factor: f64, bounds: impl RangeBounds<f64>, row_factors: impl IntoIterator<Item = (Row, f64)>, ) -> Col

Adds a new variable to the highs model.

Returns the added column index.

§Panics

If HIGHS returns an error status value.

Source

pub fn try_add_column( &mut self, col_factor: f64, bounds: impl RangeBounds<f64>, row_factors: impl IntoIterator<Item = (Row, f64)>, ) -> Result<Col, HighsStatus>

Tries to add a new variable to the highs model.

Returns the added column index, or the error status value if HIGHS returned an error status.

Source

pub fn set_solution( &mut self, cols: Option<&[f64]>, rows: Option<&[f64]>, col_duals: Option<&[f64]>, row_duals: Option<&[f64]>, )

Hot-starts at the initial guess. See HIGHS documentation for further details.

§Panics

If HIGHS returns an error status value.

If the data passed in do not have the correct lengths. cols and col_duals should have the lengths of num_cols. rows and row_duals should have the lengths of num_rows.

Source

pub fn try_set_solution( &mut self, cols: Option<&[f64]>, rows: Option<&[f64]>, col_duals: Option<&[f64]>, row_duals: Option<&[f64]>, ) -> Result<(), HighsStatus>

Tries to hot-start using an initial guess by passing the column and row primal and dual solution values. See highs_c_api.h for further details.

If the data passed in do not have the correct lengths, an Err is returned. cols and col_duals should have the lengths of num_cols. rows and row_duals should have the lengths of num_rows.

Trait Implementations§

Source§

impl Debug for Model

Source§

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

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

impl From<SolvedModel> for Model

Source§

fn from(solved: SolvedModel) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Model

§

impl RefUnwindSafe for Model

§

impl !Send for Model

§

impl !Sync for Model

§

impl Unpin for Model

§

impl UnwindSafe for Model

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> 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, 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.