rooc::linear_model

Struct LinearModel

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

Represents a complete linear programming model including variables, constraints, and objective function.

§Example

use rooc::{OptimizationType, VariableType, Comparison, LinearModel};
use rooc::model_transformer::DomainVariable;
let mut model = LinearModel::new();

// Add variables
model.add_variable("x", VariableType::non_negative_real());
model.add_variable("y", VariableType::non_negative_real());

// Set objective function: minimize x + 2y
model.set_objective(vec![1.0, 2.0], OptimizationType::Min);

// Add constraint: x + y <= 10
model.add_constraint(vec![1.0, 1.0], Comparison::LessOrEqual, 10.0);

Implementations§

Source§

impl LinearModel

Source

pub fn new_from_parts( objective: Vec<f64>, optimization_type: OptimizationType, objective_offset: f64, constraints: Vec<LinearConstraint>, variables: Vec<String>, domain: IndexMap<String, DomainVariable>, ) -> LinearModel

Creates a new LinearModel from its constituent parts.

§Arguments
  • objective - Vector of objective function coefficients
  • optimization_type - Whether to minimize or maximize
  • objective_offset - Constant term in objective function
  • constraints - Vector of linear constraints
  • variables - Vector of variable names
  • domain - Map of variable domains
Source

pub fn new() -> LinearModel

Creates a new empty LinearModel.

Source

pub fn into_parts( self, ) -> (Vec<f64>, OptimizationType, f64, Vec<LinearConstraint>, Vec<String>, IndexMap<String, DomainVariable>)

Decomposes the model into its constituent parts.

§Returns

A tuple containing (objective coefficients, optimization type, objective offset, constraints, variables, domain)

Source

pub fn add_variable(&mut self, name: &str, domain: VariableType)

Adds a new variable to the model.

§Arguments
  • name - Name of the variable
  • domain - Type/domain of the variable (e.g., Boolean, Integer, etc.)
Source

pub fn add_constraint( &mut self, coefficients: Vec<f64>, constraint_type: Comparison, rhs: f64, )

Adds a new constraint to the model.

§Arguments
  • coefficients - Vector of coefficients for the constraint
  • constraint_type - Type of comparison operator
  • rhs - Right-hand side value
§Returns
  • Ok(()) if successful
  • Err(LinearModelError) if too many coefficients provided
§Panics

If there are more coefficient than how many variables there are

Source

pub fn set_objective( &mut self, objective: Vec<f64>, optimization_type: OptimizationType, )

Sets the objective function of the model.

§Arguments
  • objective - Vector of objective function coefficients
  • optimization_type - Whether to minimize or maximize
§Returns
  • Ok(()) if successful
  • Err(LinearModelError) if too many coefficients provided
§Panics

If there are more coefficient than how many variables there are

Source

pub fn optimization_type(&self) -> &OptimizationType

Returns the optimization type (minimize/maximize).

Source

pub fn into_standard_form(self) -> Result<StandardLinearModel, SolverError>

Converts the model to standard form.

Source

pub fn objective(&self) -> &Vec<f64>

Returns a reference to the objective function coefficients.

Source

pub fn constraints(&self) -> &Vec<LinearConstraint>

Returns a reference to the model’s constraints.

Source

pub fn variables(&self) -> &Vec<String>

Returns a reference to the variable names.

Source

pub fn objective_offset(&self) -> f64

Returns the constant term in the objective function.

Source

pub fn domain(&self) -> &IndexMap<String, DomainVariable>

Returns a reference to the variable domains.

Trait Implementations§

Source§

impl Clone for LinearModel

Source§

fn clone(&self) -> LinearModel

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LinearModel

Source§

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

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

impl Default for LinearModel

Source§

fn default() -> Self

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

impl Display for LinearModel

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. 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<T> MaybeBlasFloatT for T

Source§

impl<T> MaybeFaerFloatT for T