pub struct Model {
pub variables: HashMap<Name, DecisionVariable>,
pub constraints: Expression,
pub context: Arc<RwLock<Context<'static>>>,
/* private fields */
}
Expand description
Represents a computational model containing variables, constraints, and a shared context.
The Model
struct holds a set of variables and constraints for manipulating and evaluating symbolic expressions.
§Fields
-
variables
:- Type:
SymbolTable
- A table that links each variable’s name to its corresponding
DecisionVariable
. - For example, the name
x
might be linked to aDecisionVariable
that saysx
can only take values between 1 and 10.
- Type:
-
constraints
:- Type:
Expression
- Represents the logical constraints applied to the model’s variables.
- Can be a single constraint or a combination of various expressions, such as logical operations (e.g.,
AND
,OR
), arithmetic operations (e.g.,SafeDiv
,UnsafeDiv
), or specialized constraints likeSumEq
.
- Type:
-
context
:- Type:
Arc<RwLock<Context<'static>>>
- A shared object that stores global settings and state for the model.
- Can be safely read or changed by multiple parts of the program at the same time, making it good for multi-threaded use.
- Type:
-
next_var
:- Type:
RefCell<i32>
- A counter used to create new, unique variable names.
- Allows updating the counter inside the model without making the whole model mutable.
- Type:
§Usage
This struct is typically used to:
- Define a set of variables and constraints for rule-based evaluation.
- Have transformations, optimizations, and simplifications applied to it using a set of rules.
Fields§
§variables: HashMap<Name, DecisionVariable>
§constraints: Expression
§context: Arc<RwLock<Context<'static>>>
Implementations§
Source§impl Model
impl Model
pub fn new( variables: HashMap<Name, DecisionVariable>, constraints: Expression, context: Arc<RwLock<Context<'static>>>, ) -> Model
pub fn new_empty(context: Arc<RwLock<Context<'static>>>) -> Model
pub fn update_domain(&mut self, name: &Name, new_domain: Domain)
pub fn get_domain(&self, name: &Name) -> Option<&Domain>
pub fn add_variable(&mut self, name: Name, decision_var: DecisionVariable)
pub fn get_constraints_vec(&self) -> Vec<Expression>
pub fn set_constraints(&mut self, constraints: Vec<Expression>)
pub fn set_context(&mut self, context: Arc<RwLock<Context<'static>>>)
pub fn add_constraint(&mut self, expression: Expression)
pub fn add_constraints(&mut self, expressions: Vec<Expression>)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Model
impl<'de> Deserialize<'de> for Model
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Model, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Model, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for Model
impl Serialize for Model
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Eq for Model
Auto Trait Implementations§
impl !Freeze for Model
impl !RefUnwindSafe for Model
impl Send for Model
impl !Sync for Model
impl Unpin 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
Mutably borrows from an owned value. Read more
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)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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 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>
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