Skip to main content

Model

Struct Model 

Source
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

Source

pub fn new() -> Self

Creates a new model with logging enabled by default.

Source

pub fn shape(&self) -> (usize, usize)

Source

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();
Source

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"));
Source

pub fn vars(&self) -> &[Var]

Returns a read-only slice of variables.

Source

pub fn constraints(&self) -> &[Constraint]

Returns a read-only slice of constraints.

Source

pub fn objective(&self) -> Option<&Objective>

Returns a reference to the model’s objective function, if set.

Trait Implementations§

Source§

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)

Performs the += operation. Read more
Source§

impl Debug for Model

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Model

Source§

fn default() -> Model

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Model

§

impl RefUnwindSafe for Model

§

impl Send for Model

§

impl Sync for Model

§

impl Unpin for Model

§

impl UnsafeUnpin for Model

§

impl UnwindSafe for Model

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.