InitializedGeneralThresholdAutomatonBuilder

Struct InitializedGeneralThresholdAutomatonBuilder 

Source
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: GeneralThresholdAutomaton

Implementations§

Source§

impl InitializedGeneralThresholdAutomatonBuilder

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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();
Source

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();
Source

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.

Source

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.

Source

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();
Source

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();
Source

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();
Source

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();
Source

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();
Source

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();
Source

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")));
Source

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")));
Source

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")));
Source

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")]);
Source

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")]);
Source

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")]);
Source

pub fn build(self) -> GeneralThresholdAutomaton

Complete the build step and construct the threshold automaton

Trait Implementations§

Source§

impl Clone for InitializedGeneralThresholdAutomatonBuilder

Source§

fn clone(&self) -> InitializedGeneralThresholdAutomatonBuilder

Returns a duplicate 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 InitializedGeneralThresholdAutomatonBuilder

Source§

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

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

impl IsDeclared<Location> for InitializedGeneralThresholdAutomatonBuilder

Source§

fn is_declared(&self, loc: &Location) -> bool

Check if object of type T is declared
Source§

impl IsDeclared<Parameter> for InitializedGeneralThresholdAutomatonBuilder

Source§

fn is_declared(&self, param: &Parameter) -> bool

Check if object of type T is declared
Source§

impl IsDeclared<Variable> for InitializedGeneralThresholdAutomatonBuilder

Source§

fn is_declared(&self, var: &Variable) -> bool

Check if object of type T is declared
Source§

impl PartialEq for InitializedGeneralThresholdAutomatonBuilder

Source§

fn eq(&self, other: &InitializedGeneralThresholdAutomatonBuilder) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for InitializedGeneralThresholdAutomatonBuilder

Source§

impl StructuralPartialEq for InitializedGeneralThresholdAutomatonBuilder

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> 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, 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.