Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add with_all function to model #80

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/solvers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,30 @@ pub trait SolverModel {
self
}

/// Takes a model and adds a list of constraints to it
lovasoa marked this conversation as resolved.
Show resolved Hide resolved
///
/// # Examples
/// ```rust
/// use good_lp::*;
/// let mut vars = variables!();
/// let x = vars.add_variable(); // unbounded variable
/// let result = vars.maximise(x)
/// .using(default_solver)
/// .with_all([constraint!(x >= 1), constraint!(x <= 10)])
/// .solve()
/// .expect("example model, trivial to solve"); //
/// assert_eq!(result.eval(&x), 10.);
/// ```
fn with_all(mut self, constraints: impl IntoIterator<Item = Constraint>) -> Self
where
Self: Sized,
{
for constraint in constraints {
self.add_constraint(constraint);
}
self
}

/// Find the solution for the problem being modeled
fn solve(self) -> Result<Self::Solution, Self::Error>;

Expand Down
Loading