pub struct Model { /* private fields */ }Expand description
A linear programming model built using the algebraic modeling API.
Implementations§
Source§impl Model
impl Model
Sourcepub fn set_timeout(&mut self, secs: f64)
pub fn set_timeout(&mut self, secs: f64)
Set a timeout for QP solve operations.
Sourcepub fn try_set_timeout(&mut self, secs: f64) -> Result<&mut Self, ModelError>
pub fn try_set_timeout(&mut self, secs: f64) -> Result<&mut Self, ModelError>
Set a timeout for solve operations, returning an error for invalid input.
Sourcepub fn set_threads(&mut self, n: usize) -> &mut Self
pub fn set_threads(&mut self, n: usize) -> &mut Self
並列 thread 上限を設定する。0 は 1 に補正、default は SolverOptions の 1。 LP / QP / 非凸 multistart すべてに影響する共通設定。
Sourcepub fn set_use_ruiz_scaling(&mut self, flag: bool)
pub fn set_use_ruiz_scaling(&mut self, flag: bool)
Ruiz equilibration スケーリングの有効/無効を設定する(デフォルト: true)
Sourcepub fn set_tolerance(&mut self, tol: Tolerance) -> &mut Self
pub fn set_tolerance(&mut self, tol: Tolerance) -> &mut Self
精度プリセットを設定する。
Sourcepub fn set_presolve(&mut self, flag: bool) -> &mut Self
pub fn set_presolve(&mut self, flag: bool) -> &mut Self
Presolve の有効/無効を設定する(デフォルト: true)。
Sourcepub fn add_var(&mut self, name: &str, lb: f64, ub: f64) -> Variable
pub fn add_var(&mut self, name: &str, lb: f64, ub: f64) -> Variable
Add a decision variable to the model.
Records an error (deferred to solve()) if lb > ub or either bound is NaN.
Use try_add_var to get an immediate Result.
Sourcepub fn try_add_var(
&mut self,
name: &str,
lb: f64,
ub: f64,
) -> Result<Variable, ModelError>
pub fn try_add_var( &mut self, name: &str, lb: f64, ub: f64, ) -> Result<Variable, ModelError>
Add a decision variable, returning an error for invalid bounds.
Sourcepub fn add_int_var(&mut self, name: &str, lb: f64, ub: f64) -> Variable
pub fn add_int_var(&mut self, name: &str, lb: f64, ub: f64) -> Variable
Add an integer decision variable (must take integral values within [lb, ub]).
Records an error (deferred to solve()) if lb > ub or either bound is NaN.
Use try_add_int_var to get an immediate Result.
Presence of any integer/binary variable routes solve() through the
MILP/MIQP branch-and-bound solver instead of the continuous LP/QP path.
Sourcepub fn try_add_int_var(
&mut self,
name: &str,
lb: f64,
ub: f64,
) -> Result<Variable, ModelError>
pub fn try_add_int_var( &mut self, name: &str, lb: f64, ub: f64, ) -> Result<Variable, ModelError>
Add an integer decision variable, returning an error for invalid bounds.
Sourcepub fn add_binary_var(&mut self, name: &str) -> Variable
pub fn add_binary_var(&mut self, name: &str) -> Variable
Add a binary decision variable (integer, fixed to the {0, 1} box).
Sourcepub fn var_name(&self, var: Variable) -> &str
pub fn var_name(&self, var: Variable) -> &str
Return the name of a variable as given to add_var.
Sourcepub fn add_constraint(&mut self, c: Constraint) -> &mut Self
pub fn add_constraint(&mut self, c: Constraint) -> &mut Self
Add a constraint to the model.
Sourcepub fn minimize(&mut self, obj: impl Into<QuadExpr>) -> &mut Self
pub fn minimize(&mut self, obj: impl Into<QuadExpr>) -> &mut Self
Set the objective to minimize the given expression.
Accepts any linear Expression or quadratic QuadExpr (e.g. x * x,
x * y, x.pow2()). When quadratic terms are present the Q matrix is
built automatically using the 1/2 xᵀQx convention and the model is routed
through the QP solver.
Sourcepub fn maximize(&mut self, obj: impl Into<QuadExpr>) -> &mut Self
pub fn maximize(&mut self, obj: impl Into<QuadExpr>) -> &mut Self
Set the objective to maximize the given expression.
See minimize for details on quadratic support.
For maximization the Q matrix is negated internally (Q → -Q).
Sourcepub fn set_obj_offset(&mut self, offset: f64) -> &mut Self
pub fn set_obj_offset(&mut self, offset: f64) -> &mut Self
Set the quadratic objective Q matrix for QP problems.
Convention (“1/2あり”): the objective is min 1/2 x^T Q x + c^T x
目的関数の定数オフセットを設定する。
objective_value = (1/2 x^T Q x +) c^T x + offset として最終結果に加算される。
Sourcepub fn solve(&mut self) -> Result<ModelResult, ModelError>
pub fn solve(&mut self) -> Result<ModelResult, ModelError>
Solve the model and return the result.
§Errors
ModelError::NoObjectiveifminimizeormaximizewas not called.ModelError::SolveErrorif the solver returns Infeasible or Unbounded.
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> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
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