Crate good_lp[−][src]
A Linear Programming modeler that is easy to use, performant with large problems, and well-typed.
use good_lp::{variables, variable, coin_cbc, SolverModel, Solution}; let mut vars = variables!(); let a = vars.add(variable().max(1)); let b = vars.add(variable().min(2).max(4)); let solution = vars.maximise(10 * (a - b / 5) - b) .using(coin_cbc) .with(a + 2. << b) // or (a + 2).leq(b) .with(1 + a >> 4. - b) .solve()?; assert_eq!(solution.value(a), 1.); assert_eq!(solution.value(b), 3.);
Solvers
This crate supports multiple solvers, that can be activated using feature flags.
Usage
You initially create your variables using variables and ProblemVariables::add.
Then you create your objective function.If it's large, you can write rust functions to split complex expressions into components.
use good_lp::{Expression, Variable}; fn total_cost<V>(energy: Variable<V>, time: Variable<V>) -> Expression<V> { energy_cost(energy) + dollars_per_hour * time } fn energy_cost<V>(energy: Variable<V>) -> Expression<V> { let price = fetch_energy_price(energy); energy * price }
Then you create a solver problem model instance
let mut model = my_variables.minimise(my_objective).using(my_solver);
Then you add constraints and solve your problem using the methods in SolverModel.
Re-exports
pub use constraint::Constraint; |
pub use solvers::ResolutionError; |
pub use solvers::Solution; |
pub use solvers::SolverModel; |
pub use variable::variable; |
pub use variable::ProblemVariables; |
pub use variable::Variable; |
pub use variable::VariableDefinition; |
pub use solvers::coin_cbc::coin_cbc; |
Modules
constraint | Constraints define the inequalities that must hold in the solution. |
solvers | Included solvers that find the actual solution to linear problems. The number of solvers available in this module depends on which cargo features you have activated. |
variable | A Variable is the base element used to create an Expression. The goal of the solver is to find optimal values for all variables in a problem. |
Macros
variables | Instantiates ProblemVariables, to create a set of related variables. |
Structs
Expression | Represents an affine expression, such as |