pub struct InitializedGeneralThresholdAutomatonBuilder {
ta: GeneralThresholdAutomaton,
}Expand description
A builder for a threshold automaton where parameters, variables, and locations have already been added and are now fixed.
In this stage, rules, resilience conditions, and initial constraints can be added to the threshold automaton.
§Example
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;
use taco_threshold_automaton::LocationConstraint;
// Building a threshold automaton
let ta = GeneralThresholdAutomatonBuilder::new("test_ta1")
.with_parameter(Parameter::new("n")).unwrap()
.with_variable(Variable::new("var1")).unwrap()
.with_locations(vec![
Location::new("loc1"),
Location::new("loc2"),
]).unwrap()
.initialize()
.with_rules(vec![
RuleBuilder::new(0, Location::new("loc1"), Location::new("loc2")).build(),
]).unwrap()
.with_initial_location_constraint(
LocationConstraint::ComparisonExpression(
Box::new(IntegerExpression::Atom(Location::new("loc1"))),
ComparisonOp::Eq,
Box::new(IntegerExpression::Param(Parameter::new("n"))),
)).unwrap()
.build();Fields§
§ta: GeneralThresholdAutomatonImplementations§
Source§impl InitializedGeneralThresholdAutomatonBuilder
impl InitializedGeneralThresholdAutomatonBuilder
Sourcefn contains_rule_or_rule_id(&self, rule: &Rule) -> Option<BuilderError>
fn contains_rule_or_rule_id(&self, rule: &Rule) -> Option<BuilderError>
Checks whether the rule or rule id is already present in the threshold automaton
Returns an error if the rule or rule id is already present, otherwise returns None
Sourcefn validate_integer_expr<T: Atomic>(
&self,
int_expr: &IntegerExpression<T>,
known_atoms: &HashSet<T>,
) -> Option<BuilderError>
fn validate_integer_expr<T: Atomic>( &self, int_expr: &IntegerExpression<T>, known_atoms: &HashSet<T>, ) -> Option<BuilderError>
Check whether a integer expression int_expr only uses components appearing in known_atoms
Returns an error if the constraint does contain unknown components, otherwise returns None
Sourcefn validate_constraint<T: Atomic>(
&self,
constraint: &BooleanExpression<T>,
known_atoms: &HashSet<T>,
) -> Option<BuilderError>
fn validate_constraint<T: Atomic>( &self, constraint: &BooleanExpression<T>, known_atoms: &HashSet<T>, ) -> Option<BuilderError>
Check whether a constraint constraint only uses components appearing in known_atoms
Returns an error if the constraint does contain unknown components, otherwise returns None
Sourcefn validate_action(&self, action: &Action) -> Option<BuilderError>
fn validate_action(&self, action: &Action) -> Option<BuilderError>
Check whether an action is valid
Returns an error if the action is invalid, otherwise returns None
Sourcefn validate_rule(&self, rule: &Rule) -> Option<BuilderError>
fn validate_rule(&self, rule: &Rule) -> Option<BuilderError>
Check whether components of a rule are valid
Returns an error if the rule is malformed, otherwise returns None
Sourcepub fn with_rule(self, rule: Rule) -> Result<Self, BuilderError>
pub fn with_rule(self, rule: Rule) -> Result<Self, BuilderError>
Add a rule to the threshold automaton
Adds a rule to the threshold automaton. It returns an error if a rule is added twice, the rule id is already taken or one of the rules expressions is invalid.
§Example
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::*;
use taco_threshold_automaton::general_threshold_automaton::builder::GeneralThresholdAutomatonBuilder;
use taco_threshold_automaton::general_threshold_automaton::builder::RuleBuilder;
let ta = GeneralThresholdAutomatonBuilder::new("test_ta1")
.with_locations(vec![
Location::new("loc1"),
Location::new("loc2"),
]).unwrap()
.initialize()
.with_rule(
RuleBuilder::new(0, Location::new("loc1"), Location::new("loc2")).build(),
).unwrap()
.build();Sourcepub fn with_rules(
self,
rules: impl IntoIterator<Item = Rule>,
) -> Result<Self, BuilderError>
pub fn with_rules( self, rules: impl IntoIterator<Item = Rule>, ) -> Result<Self, BuilderError>
Add multiple rules to the threshold automaton
Adds multiple rules to the threshold automaton. It returns an error if a rule is added twice, the rule id is already taken or one of the rules expressions is invalid.
§Example
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;
use taco_threshold_automaton::general_threshold_automaton::builder::GeneralThresholdAutomatonBuilder;
let ta = GeneralThresholdAutomatonBuilder::new("test_ta1")
.with_locations(vec![
Location::new("loc1"),
Location::new("loc2"),
]).unwrap()
.initialize()
.with_rules(vec![
RuleBuilder::new(0, Location::new("loc1"), Location::new("loc2")).build(),
RuleBuilder::new(1, Location::new("loc2"), Location::new("loc1")).build(),
]).unwrap()
.build();Sourcefn canonicalize_parameter_integer_expr(
rc: IntegerExpression<Parameter>,
) -> IntegerExpression<Parameter>
fn canonicalize_parameter_integer_expr( rc: IntegerExpression<Parameter>, ) -> IntegerExpression<Parameter>
The representation of a resilience condition is currently not unique because in this case parameters are also atoms. This function converts all atoms into parameters.
Sourcefn canonicalize_resilience_condition(
rc: ParameterConstraint,
) -> ParameterConstraint
fn canonicalize_resilience_condition( rc: ParameterConstraint, ) -> ParameterConstraint
The representation of a resilience condition is currently not unique because in this case parameters are also atoms. This function converts all atoms into parameters.
Sourcepub fn with_resilience_condition(
self,
rc: ParameterConstraint,
) -> Result<Self, BuilderError>
pub fn with_resilience_condition( self, rc: ParameterConstraint, ) -> Result<Self, BuilderError>
Add a resilience condition to the threshold automaton
Adds a resilience condition to the threshold automaton. It returns an error if the resilience condition already exists or contains unknown parameters.
§Example
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;
use taco_threshold_automaton::ParameterConstraint;
let ta = GeneralThresholdAutomatonBuilder::new("test_ta1")
.with_parameter(Parameter::new("n")).unwrap()
.initialize()
.with_resilience_condition(
ParameterConstraint::ComparisonExpression(
Box::new(IntegerExpression::Atom(Parameter::new("n"))),
ComparisonOp::Eq,
Box::new(IntegerExpression::Const(0)),
)).unwrap()
.build();Sourcepub fn with_resilience_conditions(
self,
rcs: impl IntoIterator<Item = ParameterConstraint>,
) -> Result<Self, BuilderError>
pub fn with_resilience_conditions( self, rcs: impl IntoIterator<Item = ParameterConstraint>, ) -> Result<Self, BuilderError>
Add multiple resilience conditions to the threshold automaton
Adds multiple resilience conditions to the threshold automaton. It returns an error if a resilience condition already exists or contains unknown parameters.
§Example
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;
use taco_threshold_automaton::ParameterConstraint;
let ta = GeneralThresholdAutomatonBuilder::new("test_ta1")
.with_parameters(vec![
Parameter::new("n"),
Parameter::new("m"),
]).unwrap()
.initialize()
.with_resilience_conditions(vec![
ParameterConstraint::ComparisonExpression(
Box::new(IntegerExpression::Atom(Parameter::new("n"))),
ComparisonOp::Eq,
Box::new(IntegerExpression::Const(0)),
),
ParameterConstraint::ComparisonExpression(
Box::new(IntegerExpression::Atom(Parameter::new("m"))),
ComparisonOp::Eq,
Box::new(IntegerExpression::Const(0)),
)]).unwrap()
.build();Sourcepub fn with_initial_location_constraint(
self,
constraint: LocationConstraint,
) -> Result<Self, BuilderError>
pub fn with_initial_location_constraint( self, constraint: LocationConstraint, ) -> Result<Self, BuilderError>
Add an initial location constraint to the threshold automaton
Adds an initial location constraint to the threshold automaton. It returns an error if the constraint already exists or contains unknown locations.
§Example
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;
use taco_threshold_automaton::LocationConstraint;
let ta = GeneralThresholdAutomatonBuilder::new("test_ta1")
.with_location(Location::new("loc1")).unwrap()
.initialize()
.with_initial_location_constraint(
LocationConstraint::ComparisonExpression(
Box::new(IntegerExpression::Atom(Location::new("loc1"))),
ComparisonOp::Eq,
Box::new(IntegerExpression::Const(0)),
)).unwrap()
.build();Sourcepub fn with_initial_location_constraints(
self,
constraints: impl IntoIterator<Item = LocationConstraint>,
) -> Result<Self, BuilderError>
pub fn with_initial_location_constraints( self, constraints: impl IntoIterator<Item = LocationConstraint>, ) -> Result<Self, BuilderError>
Add multiple initial location constraints to the threshold automaton
Adds multiple initial location constraints to the threshold automaton. It returns an error if a constraint already exists or contains unknown locations.
§Example
use taco_threshold_automaton::ParameterConstraint;
use taco_threshold_automaton::LocationConstraint;
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;
let ta = GeneralThresholdAutomatonBuilder::new("test_ta1")
.with_locations(vec![
Location::new("loc1"),
Location::new("loc2"),
]).unwrap()
.initialize()
.with_initial_location_constraints(vec![
LocationConstraint::ComparisonExpression(
Box::new(IntegerExpression::Atom(Location::new("loc1"))),
ComparisonOp::Eq,
Box::new(IntegerExpression::Const(0)),
),
LocationConstraint::ComparisonExpression(
Box::new(IntegerExpression::Atom(Location::new("loc2"))),
ComparisonOp::Eq,
Box::new(IntegerExpression::Const(0)),
),
]).unwrap()
.build();Sourcepub fn with_initial_variable_constraint(
self,
constraint: BooleanVarConstraint,
) -> Result<Self, BuilderError>
pub fn with_initial_variable_constraint( self, constraint: BooleanVarConstraint, ) -> Result<Self, BuilderError>
Add initial variable constraint to the threshold automaton
Adds an initial variable constraint to the threshold automaton. It returns an error if the constraint already exists or contains unknown variables.
§Example
use taco_threshold_automaton::BooleanVarConstraint;
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;
let ta = GeneralThresholdAutomatonBuilder::new("test_ta1")
.with_variable(Variable::new("var1")).unwrap()
.initialize()
.with_initial_variable_constraint(
BooleanVarConstraint::ComparisonExpression(
Box::new(IntegerExpression::Atom(Variable::new("var1"))),
ComparisonOp::Eq,
Box::new(IntegerExpression::Const(0)),
)).unwrap()
.build();Sourcepub fn with_initial_variable_constraints(
self,
constraints: impl IntoIterator<Item = BooleanVarConstraint>,
) -> Result<Self, BuilderError>
pub fn with_initial_variable_constraints( self, constraints: impl IntoIterator<Item = BooleanVarConstraint>, ) -> Result<Self, BuilderError>
Add multiple initial variable constraints to the threshold automaton
Adds multiple initial variable constraints to the threshold automaton. It returns an error if a constraint already exists or contains unknown variables.
§Example
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::BooleanVarConstraint;
use taco_threshold_automaton::general_threshold_automaton::builder::*;
let ta = GeneralThresholdAutomatonBuilder::new("test_ta1")
.with_variables(vec![
Variable::new("var1"),
Variable::new("var2"),
]).unwrap()
.initialize()
.with_initial_variable_constraints(vec![
BooleanVarConstraint::ComparisonExpression(
Box::new(IntegerExpression::Atom(Variable::new("var1"))),
ComparisonOp::Eq,
Box::new(IntegerExpression::Const(0)),
),
BooleanVarConstraint::ComparisonExpression(
Box::new(IntegerExpression::Atom(Variable::new("var2"))),
ComparisonOp::Eq,
Box::new(IntegerExpression::Const(0)),
)]).unwrap()
.build();Sourcepub fn has_parameter(&self, param: &Parameter) -> bool
pub fn has_parameter(&self, param: &Parameter) -> bool
Check whether the threshold automaton has a specific parameter
§Example
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;
let builder = GeneralThresholdAutomatonBuilder::new("test_ta1")
.with_parameter(Parameter::new("n")).unwrap()
.initialize();
assert!(builder.has_parameter(&Parameter::new("n")));Sourcepub fn has_variable(&self, var: &Variable) -> bool
pub fn has_variable(&self, var: &Variable) -> bool
Check whether the threshold automaton has a specific variable
§Example
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;
let builder = GeneralThresholdAutomatonBuilder::new("test_ta1")
.with_variable(Variable::new("var1")).unwrap()
.initialize();
assert!(builder.has_variable(&Variable::new("var1")));Sourcepub fn has_location(&self, loc: &Location) -> bool
pub fn has_location(&self, loc: &Location) -> bool
Check whether the threshold automaton has a specific location
Returns true if the location is present.
§Example
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;
let builder = GeneralThresholdAutomatonBuilder::new("test_ta1")
.with_location(Location::new("loc1")).unwrap()
.initialize();
assert!(builder.has_location(&Location::new("loc1")));Sourcepub fn locations(&self) -> impl Iterator<Item = &Location>
pub fn locations(&self) -> impl Iterator<Item = &Location>
Get an iterator over all locations known to the builder
§Example
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;
let builder = GeneralThresholdAutomatonBuilder::new("test_ta1")
.with_location(Location::new("loc1")).unwrap()
.initialize();
let locations: Vec<&Location> = builder
.locations()
.into_iter()
.collect();
assert_eq!(locations, vec![&Location::new("loc1")]);Sourcepub fn variables(&self) -> impl Iterator<Item = &Variable>
pub fn variables(&self) -> impl Iterator<Item = &Variable>
Get an iterator over all variables known to the builder
§Example
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;
let builder = GeneralThresholdAutomatonBuilder::new("test_ta1")
.with_variable(Variable::new("var1")).unwrap()
.initialize();
let variables: Vec<&Variable> = builder
.variables()
.into_iter()
.collect();
assert_eq!(variables, vec![&Variable::new("var1")]);Sourcepub fn parameters(&self) -> impl Iterator<Item = &Parameter>
pub fn parameters(&self) -> impl Iterator<Item = &Parameter>
Get an iterator over all parameters known to the builder
§Example
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;
let builder = GeneralThresholdAutomatonBuilder::new("test_ta1")
.with_parameter(Parameter::new("var1")).unwrap()
.initialize();
let parameters: Vec<&Parameter> = builder
.parameters()
.into_iter()
.collect();
assert_eq!(parameters, vec![&Parameter::new("var1")]);Sourcepub fn build(self) -> GeneralThresholdAutomaton
pub fn build(self) -> GeneralThresholdAutomaton
Complete the build step and construct the threshold automaton
Trait Implementations§
Source§impl Clone for InitializedGeneralThresholdAutomatonBuilder
impl Clone for InitializedGeneralThresholdAutomatonBuilder
Source§fn clone(&self) -> InitializedGeneralThresholdAutomatonBuilder
fn clone(&self) -> InitializedGeneralThresholdAutomatonBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl IsDeclared<Location> for InitializedGeneralThresholdAutomatonBuilder
impl IsDeclared<Location> for InitializedGeneralThresholdAutomatonBuilder
Source§fn is_declared(&self, loc: &Location) -> bool
fn is_declared(&self, loc: &Location) -> bool
Source§impl IsDeclared<Parameter> for InitializedGeneralThresholdAutomatonBuilder
impl IsDeclared<Parameter> for InitializedGeneralThresholdAutomatonBuilder
Source§fn is_declared(&self, param: &Parameter) -> bool
fn is_declared(&self, param: &Parameter) -> bool
Source§impl IsDeclared<Variable> for InitializedGeneralThresholdAutomatonBuilder
impl IsDeclared<Variable> for InitializedGeneralThresholdAutomatonBuilder
Source§fn is_declared(&self, var: &Variable) -> bool
fn is_declared(&self, var: &Variable) -> bool
Source§impl PartialEq for InitializedGeneralThresholdAutomatonBuilder
impl PartialEq for InitializedGeneralThresholdAutomatonBuilder
Source§fn eq(&self, other: &InitializedGeneralThresholdAutomatonBuilder) -> bool
fn eq(&self, other: &InitializedGeneralThresholdAutomatonBuilder) -> bool
self and other values to be equal, and is used by ==.