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
impl LinearModel
Sourcepub fn new_from_parts(
objective: Vec<f64>,
optimization_type: OptimizationType,
objective_offset: f64,
constraints: Vec<LinearConstraint>,
variables: Vec<String>,
domain: IndexMap<String, DomainVariable>,
) -> LinearModel
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 coefficientsoptimization_type
- Whether to minimize or maximizeobjective_offset
- Constant term in objective functionconstraints
- Vector of linear constraintsvariables
- Vector of variable namesdomain
- Map of variable domains
Sourcepub fn new() -> LinearModel
pub fn new() -> LinearModel
Creates a new empty LinearModel.
Sourcepub fn into_parts(
self,
) -> (Vec<f64>, OptimizationType, f64, Vec<LinearConstraint>, Vec<String>, IndexMap<String, DomainVariable>)
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)
Sourcepub fn add_variable(&mut self, name: &str, domain: VariableType)
pub fn add_variable(&mut self, name: &str, domain: VariableType)
Adds a new variable to the model.
§Arguments
name
- Name of the variabledomain
- Type/domain of the variable (e.g., Boolean, Integer, etc.)
Sourcepub fn add_constraint(
&mut self,
coefficients: Vec<f64>,
constraint_type: Comparison,
rhs: f64,
)
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 constraintconstraint_type
- Type of comparison operatorrhs
- Right-hand side value
§Returns
Ok(())
if successfulErr(LinearModelError)
if too many coefficients provided
§Panics
If there are more coefficient than how many variables there are
Sourcepub fn set_objective(
&mut self,
objective: Vec<f64>,
optimization_type: OptimizationType,
)
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 coefficientsoptimization_type
- Whether to minimize or maximize
§Returns
Ok(())
if successfulErr(LinearModelError)
if too many coefficients provided
§Panics
If there are more coefficient than how many variables there are
Sourcepub fn optimization_type(&self) -> &OptimizationType
pub fn optimization_type(&self) -> &OptimizationType
Returns the optimization type (minimize/maximize).
Sourcepub fn into_standard_form(self) -> Result<StandardLinearModel, SolverError>
pub fn into_standard_form(self) -> Result<StandardLinearModel, SolverError>
Converts the model to standard form.
Sourcepub fn objective(&self) -> &Vec<f64>
pub fn objective(&self) -> &Vec<f64>
Returns a reference to the objective function coefficients.
Sourcepub fn constraints(&self) -> &Vec<LinearConstraint>
pub fn constraints(&self) -> &Vec<LinearConstraint>
Returns a reference to the model’s constraints.
Sourcepub fn objective_offset(&self) -> f64
pub fn objective_offset(&self) -> f64
Returns the constant term in the objective function.
Sourcepub fn domain(&self) -> &IndexMap<String, DomainVariable>
pub fn domain(&self) -> &IndexMap<String, DomainVariable>
Returns a reference to the variable domains.
Trait Implementations§
Source§impl Clone for LinearModel
impl Clone for LinearModel
Source§fn clone(&self) -> LinearModel
fn clone(&self) -> LinearModel
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for LinearModel
impl Debug for LinearModel
Source§impl Default for LinearModel
impl Default for LinearModel
Auto Trait Implementations§
impl Freeze for LinearModel
impl RefUnwindSafe for LinearModel
impl Send for LinearModel
impl Sync for LinearModel
impl Unpin for LinearModel
impl UnwindSafe for LinearModel
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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