pub struct Model {
pub constraints: Vec<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
-
constraints
:- Type:
Vec<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:
§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§
§constraints: Vec<Expression>
§context: Arc<RwLock<Context<'static>>>
Implementations§
Source§impl Model
impl Model
Sourcepub fn new(
symbols: SymbolTable,
constraints: Vec<Expression>,
context: Arc<RwLock<Context<'static>>>,
) -> Model
pub fn new( symbols: SymbolTable, constraints: Vec<Expression>, context: Arc<RwLock<Context<'static>>>, ) -> Model
Creates a new model.
pub fn new_empty(context: Arc<RwLock<Context<'static>>>) -> Model
Sourcepub fn symbols(&self) -> &SymbolTable
pub fn symbols(&self) -> &SymbolTable
The global symbol table for this model.
Sourcepub fn symbols_mut(&mut self) -> &mut SymbolTable
pub fn symbols_mut(&mut self) -> &mut SymbolTable
The global symbol table for this model, as a mutable reference.
pub fn update_domain(&mut self, name: &Name, new_domain: Domain)
Sourcepub fn get_domain(&self, name: &Name) -> Option<&Domain>
pub fn get_domain(&self, name: &Name) -> Option<&Domain>
Gets the domain of name
if it exists and has one.
Sourcepub fn add_variable(
&mut self,
name: Name,
decision_var: DecisionVariable,
) -> Option<()>
pub fn add_variable( &mut self, name: Name, decision_var: DecisionVariable, ) -> Option<()>
Adds a decision variable to the model.
Returns None
if there is a decision variable or other object with that name in the symbol
table.
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>)
Sourcepub fn extend_sym_table(&mut self, other: SymbolTable)
pub fn extend_sym_table(&mut self, other: SymbolTable)
Extends the models symbol table with the given symbol table, updating the gensym counter if necessary.
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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.§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