pub struct Problem<MATRIX = ColMatrix> { /* private fields */ }Expand description
A complete optimization problem.
Depending on the MATRIX type parameter, the problem will be built
constraint by constraint (with ColProblem), or
variable by variable (with RowProblem)
Implementations
sourceimpl Problem<ColMatrix>
impl Problem<ColMatrix>
To use these functions, you need to first add all your constraints, and then add variables one by one using the Row objects.
sourcepub fn add_row<N: Into<f64> + Copy, B: RangeBounds<N>>(
&mut self,
bounds: B
) -> Row
pub fn add_row<N: Into<f64> + Copy, B: RangeBounds<N>>(
&mut self,
bounds: B
) -> Row
Add a row (a constraint) to the problem. The concrete factors are added later, when creating columns.
sourcepub fn add_column<N: Into<f64> + Copy, B: RangeBounds<N>, ITEM: Borrow<(Row, f64)>, I: IntoIterator<Item = ITEM>>(
&mut self,
col_factor: f64,
bounds: B,
row_factors: I
)
pub fn add_column<N: Into<f64> + Copy, B: RangeBounds<N>, ITEM: Borrow<(Row, f64)>, I: IntoIterator<Item = ITEM>>(
&mut self,
col_factor: f64,
bounds: B,
row_factors: I
)
Add a continuous variable to the problem.
col_factorrepresents the factor in front of the variable in the objective function.boundsrepresents the maximal and minimal allowed values of the variable.row_factorsdefines how much this variable weights in each constraint.
use highs::{ColProblem, Sense};
let mut pb = ColProblem::new();
let constraint = pb.add_row(..=5); // adds a constraint that cannot take a value over 5
// add a variable that has a coefficient 2 in the objective function, is >=0, and has a coefficient
// 2 in the constraint
pb.add_column(2., 0.., &[(constraint, 2.)]);sourcepub fn add_integer_column<N: Into<f64> + Copy, B: RangeBounds<N>, ITEM: Borrow<(Row, f64)>, I: IntoIterator<Item = ITEM>>(
&mut self,
col_factor: f64,
bounds: B,
row_factors: I
)
pub fn add_integer_column<N: Into<f64> + Copy, B: RangeBounds<N>, ITEM: Borrow<(Row, f64)>, I: IntoIterator<Item = ITEM>>(
&mut self,
col_factor: f64,
bounds: B,
row_factors: I
)
Same as add_column, but forces the solution to contain an integer value for this variable.
use highs::{ColProblem, Sense};
let mut pb = ColProblem::new();
let constraint = pb.add_row(..=5); // adds a constraint that cannot take a value over 5
// add an integer variable that has a coefficient 2 in the objective function, is >=0, and has a coefficient
// 2 in the constraint
pb.add_integer_column(2., 0.., &[(constraint, 2.)]);sourcepub fn add_column_with_integrality<N: Into<f64> + Copy, B: RangeBounds<N>, ITEM: Borrow<(Row, f64)>, I: IntoIterator<Item = ITEM>>(
&mut self,
col_factor: f64,
bounds: B,
row_factors: I,
is_integer: bool
)
pub fn add_column_with_integrality<N: Into<f64> + Copy, B: RangeBounds<N>, ITEM: Borrow<(Row, f64)>, I: IntoIterator<Item = ITEM>>(
&mut self,
col_factor: f64,
bounds: B,
row_factors: I,
is_integer: bool
)
Same as add_column, but lets you define whether the new variable should be integral or continuous.
sourceimpl Problem<RowMatrix>
impl Problem<RowMatrix>
Functions to use when first declaring variables, then constraints.
sourcepub fn add_column<N: Into<f64> + Copy, B: RangeBounds<N>>(
&mut self,
col_factor: f64,
bounds: B
) -> Col
pub fn add_column<N: Into<f64> + Copy, B: RangeBounds<N>>(
&mut self,
col_factor: f64,
bounds: B
) -> Col
add a variable to the problem.
col_factoris the coefficient in front of the variable in the objective function.boundsare the maximal and minimal values that the variable can take.
sourcepub fn add_integer_column<N: Into<f64> + Copy, B: RangeBounds<N>>(
&mut self,
col_factor: f64,
bounds: B
) -> Col
pub fn add_integer_column<N: Into<f64> + Copy, B: RangeBounds<N>>(
&mut self,
col_factor: f64,
bounds: B
) -> Col
Same as add_column, but forces the solution to contain an integer value for this variable.
sourcepub fn add_column_with_integrality<N: Into<f64> + Copy, B: RangeBounds<N>>(
&mut self,
col_factor: f64,
bounds: B,
is_integer: bool
) -> Col
pub fn add_column_with_integrality<N: Into<f64> + Copy, B: RangeBounds<N>>(
&mut self,
col_factor: f64,
bounds: B,
is_integer: bool
) -> Col
Same as add_column, but lets you define whether the new variable should be integral or continuous.
sourcepub fn add_row<N: Into<f64> + Copy, B: RangeBounds<N>, ITEM: Borrow<(Col, f64)>, I: IntoIterator<Item = ITEM>>(
&mut self,
bounds: B,
row_factors: I
)
pub fn add_row<N: Into<f64> + Copy, B: RangeBounds<N>, ITEM: Borrow<(Col, f64)>, I: IntoIterator<Item = ITEM>>(
&mut self,
bounds: B,
row_factors: I
)
Add a constraint to the problem.
boundsare the maximal and minimal allowed values for the linear expression in the constraintrow_factorsare the coefficients in the linear expression expressing the constraint
use highs::*;
let mut pb = RowProblem::new();
// Optimize 3x - 2y with x<=6 and y>=5
let x = pb.add_column(3., ..6);
let y = pb.add_column(-2., 5..);
pb.add_row(2.., &[(x, 3.), (y, 8.)]); // 2 <= x*3 + y*8sourceimpl<MATRIX: Default> Problem<MATRIX> where
Problem<ColMatrix>: From<Problem<MATRIX>>,
impl<MATRIX: Default> Problem<MATRIX> where
Problem<ColMatrix>: From<Problem<MATRIX>>,
sourcepub fn optimise(self, sense: Sense) -> Model
pub fn optimise(self, sense: Sense) -> Model
Create a model based on this problem. Don’t solve it yet. If the 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. If the problem is invalid (according to HiGHS), this function will panic.
sourcepub fn try_optimise(self, sense: Sense) -> Result<Model, HighsStatus>
pub fn try_optimise(self, sense: Sense) -> Result<Model, HighsStatus>
Create a model based on this problem. Don’t solve it yet. If the 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.
Trait Implementations
sourceimpl<MATRIX: PartialEq> PartialEq<Problem<MATRIX>> for Problem<MATRIX>
impl<MATRIX: PartialEq> PartialEq<Problem<MATRIX>> for Problem<MATRIX>
impl<MATRIX> StructuralPartialEq for Problem<MATRIX>
Auto Trait Implementations
impl<MATRIX> RefUnwindSafe for Problem<MATRIX> where
MATRIX: RefUnwindSafe,
impl<MATRIX> Send for Problem<MATRIX> where
MATRIX: Send,
impl<MATRIX> Sync for Problem<MATRIX> where
MATRIX: Sync,
impl<MATRIX> Unpin for Problem<MATRIX> where
MATRIX: Unpin,
impl<MATRIX> UnwindSafe for Problem<MATRIX> where
MATRIX: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more