pub struct Model {
pub vars: Vec<Var>,
pub constraints: Vec<Constraint>,
pub objective: Option<Objective>,
}Expand description
Represents an optimization model containing variables, constraints, and an objective.
The Model struct is the central container for defining a linear (or eventually more general)
optimization problem. Users add variables, set an objective function, and add constraints.
Solvers then operate on a Model to produce a Solution.
§Examples
let mut model = Model::new();
// Add variables
let x1 = model.add_var().finish();
let x2 = model.add_var().finish();
// Define objective: maximize x1 + 2*x2
model.add_objective(Objective::maximize(x1 + 2.0 * x2).name("Z"));
// Add constraints
model += (x1 + x2).leq(10.0);
model += x1.geq(0.0);
model += x2.geq(0.0);Fields§
§vars: Vec<Var>List of variables in the model.
constraints: Vec<Constraint>List of constraints in the model.
objective: Option<Objective>Optional objective function. Currently supports only a single objective.
TODO: Replace with Vec<Objective> for multi-objective optimization.
Implementations§
Source§impl Model
impl Model
pub fn shape(&self) -> (usize, usize)
Sourcepub fn add_var(&mut self) -> VarBuilder<'_>
pub fn add_var(&mut self) -> VarBuilder<'_>
Adds a new variable to the model and returns a VarBuilder for ergonomic configuration.
§Example
let mut model = Model::new();
let x = model.add_var().integer().finish();Sourcepub fn add_objective(&mut self, obj: Objective)
pub fn add_objective(&mut self, obj: Objective)
Sets the objective function of the model.
§Example
let mut model = Model::new();
let x = model.add_var().finish();
model.add_objective(Objective::maximize(1.0 * x).name("Profit"));Sourcepub fn constraints(&self) -> &[Constraint]
pub fn constraints(&self) -> &[Constraint]
Returns a read-only slice of constraints.
Trait Implementations§
Source§impl AddAssign<Constraint> for Model
Allows adding constraints to the model using the += operator.
impl AddAssign<Constraint> for Model
Allows adding constraints to the model using the += operator.
§Example
let mut model = Model::new();
let x = model.add_var().finish();
model += x.geq(0.0);Source§fn add_assign(&mut self, rhs: Constraint)
fn add_assign(&mut self, rhs: Constraint)
+= operation. Read more