pub struct Model { /* private fields */ }
Expand description
A model to solve
Implementations§
Source§impl Model
impl Model
Sourcepub fn new<P: Into<Problem<ColMatrix>>>(problem: P) -> Self
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
Sourcepub fn try_new<P: Into<Problem<ColMatrix>>>(
problem: P,
) -> Result<Self, HighsStatus>
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
Sourcepub fn make_quiet(&mut self)
pub fn make_quiet(&mut self)
Prevents writing anything to the standard output or to files when solving the model
Sourcepub fn set_option<STR: Into<Vec<u8>>, V: HighsOptionValue>(
&mut self,
option: STR,
value: V,
)
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
Sourcepub fn solve(self) -> SolvedModel
pub fn solve(self) -> SolvedModel
Find the optimal value for the problem, panic if the problem is incoherent
Sourcepub fn try_solve(self) -> Result<SolvedModel, HighsStatus>
pub fn try_solve(self) -> Result<SolvedModel, HighsStatus>
Find the optimal value for the problem, return an error if the problem is incoherent
Sourcepub fn add_row(
&mut self,
bounds: impl RangeBounds<f64>,
row_factors: impl IntoIterator<Item = (Col, f64)>,
) -> Row
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.
Sourcepub fn try_add_row(
&mut self,
bounds: impl RangeBounds<f64>,
row_factors: impl IntoIterator<Item = (Col, f64)>,
) -> Result<Row, HighsStatus>
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.
Sourcepub fn add_col(
&mut self,
col_factor: f64,
bounds: impl RangeBounds<f64>,
row_factors: impl IntoIterator<Item = (Row, f64)>,
) -> Col
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.
Sourcepub fn try_add_column(
&mut self,
col_factor: f64,
bounds: impl RangeBounds<f64>,
row_factors: impl IntoIterator<Item = (Row, f64)>,
) -> Result<Col, HighsStatus>
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.
Sourcepub fn set_solution(
&mut self,
cols: Option<&[f64]>,
rows: Option<&[f64]>,
col_duals: Option<&[f64]>,
row_duals: Option<&[f64]>,
)
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
.
Sourcepub fn try_set_solution(
&mut self,
cols: Option<&[f64]>,
rows: Option<&[f64]>,
col_duals: Option<&[f64]>,
row_duals: Option<&[f64]>,
) -> Result<(), HighsStatus>
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
.