pub struct Model {
pub name: String,
/* private fields */
}Expand description
The optimization model. Owns the expression arena, variable/parameter registries, constraints, and (optional) objective.
Model uses interior mutability so the builder API can take &self
references.
Variables, constraints, and the objective are added through
RefCells under the hood.
Fields§
§name: StringImplementations§
Source§impl Model
impl Model
pub fn new(name: impl Into<String>) -> Self
pub fn var(&self, name: impl Into<SmolStr>) -> VarBuilder<'_>
pub fn indexed_var<'a>( &'a self, name: impl Into<String>, set: &Set, ) -> IndexedVarBuilder<'a>
pub fn variable_id(&self, name: &str) -> Option<VarId>
pub fn variables(&self) -> Ref<'_, Vec<Variable>>
pub fn arena(&self) -> Ref<'_, ExprArena>
pub fn num_variables(&self) -> usize
Sourcepub fn fix_var(&self, id: VarId, value: f64)
pub fn fix_var(&self, id: VarId, value: f64)
Fix variable id to value by setting lb = ub = value.
Sourcepub fn unfix_var(&self, id: VarId, lb: f64, ub: f64)
pub fn unfix_var(&self, id: VarId, lb: f64, ub: f64)
Restore bounds on variable id. Pass f64::NEG_INFINITY / f64::INFINITY
to restore an unbounded direction.
Sourcepub fn constraint(
&self,
name: impl Into<SmolStr>,
c: ConstraintExpr<'_>,
) -> ConstraintId
pub fn constraint( &self, name: impl Into<SmolStr>, c: ConstraintExpr<'_>, ) -> ConstraintId
Register a new constraint.
§Panics
Panics if a constraint with the same name is already registered, or if
the constraint count exceeds u32::MAX.
Sourcepub fn add_constraints<'a, I>(&'a self, items: I)
pub fn add_constraints<'a, I>(&'a self, items: I)
Bulk-register constraints. Each entry is (name, ConstraintExpr).
Useful with .par_iter().map(...).collect() style construction.
Sourcepub fn add_constraints_over<'a, K, F>(
&'a self,
name_prefix: &str,
set: &Set,
rule: F,
)
pub fn add_constraints_over<'a, K, F>( &'a self, name_prefix: &str, set: &Set, rule: F, )
Rule-style bulk constraint registration.
The closure receives the index as a typed value K. Any type
implementing FromIndexKey is accepted. Built-in impls cover i64,
i32, usize, String, raw IndexKey, and tuples up to arity 4.
The user states the expected shape via the closure-arg annotation.
§Example
// Scalar set: closure receives a usize directly.
m.add_constraints_over("upper", &i, |i: usize| x[i].le(b[i]));
// Tuple set: destructure inline.
m.add_constraints_over("blo", &(&tasks * &events), |(t, n): (usize, usize)| {
(b[(t, n)] - b_min[t] * w[(t, n)]).ge(0.0)
});pub fn constraints(&self) -> Ref<'_, Vec<Constraint>>
pub fn num_constraints(&self) -> usize
pub fn constraint_id(&self, name: &str) -> Option<ConstraintId>
pub fn minimize(&self, expr: Expr<'_>)
pub fn maximize(&self, expr: Expr<'_>)
pub fn objective(&self) -> Ref<'_, Option<Objective>>
Sourcepub fn try_objective(&self) -> Result<Objective>
pub fn try_objective(&self) -> Result<Objective>
Try to get a cloned copy of the objective.
§Errors
Returns Error::NoObjective if no objective is set on this model.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more