Crate highs[][src]

Safe rust binding to the HiGHS linear programming solver.

Usage example

Building a problem constraint by constraint

Useful for traditional problem modelling where you first declare your variables, then add constraints one by one.

use highs::{Sense, Model, HighsModelStatus, RowProblem};
// max: x + 2y + z
// under constraints:
// c1: 3x +  y      <= 6
// c2:       y + 2z <= 7
let mut pb = RowProblem::default();
let x = pb.add_column(1., 0..);
let y = pb.add_column(2., 0..);
let z = pb.add_column(1., 0..);
// c1
pb.add_row(..=6, &[(x, 3.), (y, 1.)]);
// c2
pb.add_row(..=7, &[(y, 1.), (z, 2.)]);

let solved = pb.optimise(Sense::Maximise).solve();

assert_eq!(solved.status(), HighsModelStatus::Optimal);

let solution = solved.get_solution();
// The expected solution is x=0  y=6  z=0.5
assert_eq!(solution.columns(), vec![0., 6., 0.5]);
// All the constraints are at their maximum
assert_eq!(solution.rows(), vec![6., 7.]);

Building a problem variable by variable

Useful for resource allocation problems and other problems when you know in advance the number of constraints and their bounds, but dynamically add new variables to the problem.

use highs::{Sense, Model, HighsModelStatus, ColProblem};
// max: x + 2y + z
// under constraints:
// c1: 3x +  y      <= 6
// c2:       y + 2z <= 7
let mut pb = ColProblem::default();
let c1 = pb.add_row(..6.);
let c2 = pb.add_row(..7.);
// x
pb.add_column(1., 0.., &[(c1, 3.)]);
// y
pb.add_column(2., 0.., &[(c1, 1.), (c2, 1.)]);
// z
pb.add_column(1., 0.., vec![(c2, 2.)]);

let solved = pb.optimise(Sense::Maximise).solve();

assert_eq!(solved.status(), HighsModelStatus::Optimal);

let solution = solved.get_solution();
// The expected solution is x=0  y=6  z=0.5
assert_eq!(solution.columns(), vec![0., 6., 0.5]);
// All the constraints are at their maximum
assert_eq!(solution.rows(), vec![6., 7.]);

Structs

Col

Represents a variable

ColMatrix

A constraint matrix to build column-by-column

Model

A model to solve

Problem

A complete optimization problem Depending on the MATRIX type parameter, the problem will be built constraint by constraint (with MATRIX=RowMatrix), or variable by variable (with MATRIX=ColMatrix)

Row

Represents a constraint

RowMatrix

A complete optimization problem stored by row

Solution

Concrete values of the solution

SolvedModel

A solved model

Enums

HighsModelStatus

The kinds of results of an optimization

HighsStatus

The status of a highs operation

Sense

Whether to maximize or minimize the objective function

Type Definitions

ColProblem

A problem where constraints are declared first, and variables are then added dynamically.

RowProblem

A problem where variables are declared first, and constraints are then added dynamically.