Skip to main content

Model

Struct Model 

Source
pub struct Model { /* private fields */ }
Expand description

A linear programming model built using the algebraic modeling API.

Implementations§

Source§

impl Model

Source

pub fn new(name: &str) -> Self

Create a new, empty model with the given name.

Source

pub fn set_timeout(&mut self, secs: f64)

Set a timeout for QP solve operations.

Source

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.

Source

pub fn set_threads(&mut self, n: usize) -> &mut Self

並列 thread 上限を設定する。0 は 1 に補正、default は SolverOptions の 1。 LP / QP / 非凸 multistart すべてに影響する共通設定。

Source

pub fn set_use_ruiz_scaling(&mut self, flag: bool)

Ruiz equilibration スケーリングの有効/無効を設定する(デフォルト: true)

Source

pub fn set_tolerance(&mut self, tol: Tolerance) -> &mut Self

精度プリセットを設定する。

Source

pub fn set_presolve(&mut self, flag: bool) -> &mut Self

Presolve の有効/無効を設定する(デフォルト: true)。

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn add_binary_var(&mut self, name: &str) -> Variable

Add a binary decision variable (integer, fixed to the {0, 1} box).

Source

pub fn var_name(&self, var: Variable) -> &str

Return the name of a variable as given to add_var.

§Panics

Panics if var.index is out of range. Passing a Variable from a different model is unchecked and may index into unrelated data. Use try_var_name for a checked variant.

Source

pub fn try_var_name(&self, var: Variable) -> Result<&str, ModelError>

Return the name of a variable, returning an error instead of panicking.

Returns Err if:

  • var was created by a different model.
  • var.index is out of range for this model’s variable list.
Source

pub fn add_constraint(&mut self, c: Constraint) -> &mut Self

Add a constraint to the model.

Source

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.

Source

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).

Source

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 として最終結果に加算される。

Source

pub fn solve(&mut self) -> Result<ModelResult, ModelError>

Solve the model and return the result.

§Errors
  • ModelError::NoObjective if minimize or maximize was not called.
  • ModelError::SolveError if 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> 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> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

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

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,