GeneralThresholdAutomatonBuilder

Struct GeneralThresholdAutomatonBuilder 

Source
pub struct GeneralThresholdAutomatonBuilder {
    ta: GeneralThresholdAutomaton,
}
Expand description

Builder for constructing a GeneralThresholdAutomaton

A builder can be used to construct a GeneralThresholdAutomaton, ensuring that the threshold automaton is valid. The builder has two stages: In the first stage, parameters, variables, and locations can be added to the threshold automaton. This stage is completed by calling GeneralThresholdAutomatonBuilder::initialize, transforming the builder into an InitializedGeneralThresholdAutomatonBuilder.

In the second stage, rules, resilience conditions, and initial location constraints are added. The threshold automaton is then constructed by calling InitializedGeneralThresholdAutomatonBuilder::build.

§Example

use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;

// 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()
           .build();


let builder = 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"),
               Location::new("loc3"),
           ]).unwrap()
           .initialize();

assert!(builder.has_parameter(&Parameter::new("n")));
assert!(builder.has_variable(&Variable::new("var1")));
assert!(builder.has_location(&Location::new("loc1")));
assert!(builder.has_location(&Location::new("loc2")));

Fields§

§ta: GeneralThresholdAutomaton

Implementations§

Source§

impl GeneralThresholdAutomatonBuilder

Source

pub fn new(name: impl ToString) -> Self

Create a new threshold automaton builder

Source

fn check_for_name_clash(&self, name: &str) -> bool

Checks whether a name is already present in the threshold automaton

Source

pub fn with_parameter(self, param: Parameter) -> Result<Self, BuilderError>

Adds a parameter to the threshold automaton

Adds a parameter to the threshold automaton. If the parameter is already present or its name is already taken an error is returned.

§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 with_parameters( self, params: impl IntoIterator<Item = Parameter>, ) -> Result<Self, BuilderError>

Adds multiple parameters to the threshold automaton

Adds multiple parameters to the threshold automaton. If any of the parameters are duplicates or a name is already taken an error is returned.

§Example
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;

let builder = GeneralThresholdAutomatonBuilder::new("test_ta1")
           .with_parameters(vec![
                Parameter::new("n"),
                Parameter::new("t")]
           ).unwrap()
           .initialize();

assert!(builder.has_parameter(&Parameter::new("n")));
assert!(builder.has_parameter(&Parameter::new("t")));
Source

pub fn with_variable(self, var: Variable) -> Result<Self, BuilderError>

Adds a variable to the threshold automaton

Adds a variable to the threshold automaton. If the variable is already present or its name is already taken an error is returned.

§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 with_variables( self, vars: impl IntoIterator<Item = Variable>, ) -> Result<Self, BuilderError>

Adds multiple variables to the threshold automaton

Adds multiple variables to the threshold automaton. If any of the variables are duplicates or a name is already taken an error is returned.

§Example
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;

let builder = GeneralThresholdAutomatonBuilder::new("test_ta1")
        .with_variables(vec![
            Variable::new("var1"),
            Variable::new("var2"),
        ]).unwrap()
        .initialize();

assert!(builder.has_variable(&Variable::new("var1")));
assert!(builder.has_variable(&Variable::new("var2")));
Source

pub fn with_location(self, loc: Location) -> Result<Self, BuilderError>

Adds a location to the threshold automaton

Adds a location to the threshold automaton. If the location is already present or its name is already taken an error is returned.

§Example
use taco_threshold_automaton::expressions::Location;
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 with_locations( self, locs: impl IntoIterator<Item = Location>, ) -> Result<Self, BuilderError>

Adds multiple locations to the threshold automaton

Adds multiple locations to the threshold automaton. If any of the locations are duplicates or a name is already taken an error is returned.

§Example
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;

let builder = GeneralThresholdAutomatonBuilder::new("test_ta1")
        .with_locations(vec![
            Location::new("loc1"),
            Location::new("loc2"),
        ]).unwrap()
       .initialize();

assert!(builder.has_location(&Location::new("loc1")));
Source

pub fn initialize(self) -> InitializedGeneralThresholdAutomatonBuilder

Completes the first stage of the builder, transforming it into an InitializedGeneralThresholdAutomatonBuilder.

This method should be called after all parameters, variables, and locations have been added.

Trait Implementations§

Source§

impl Clone for GeneralThresholdAutomatonBuilder

Source§

fn clone(&self) -> GeneralThresholdAutomatonBuilder

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 GeneralThresholdAutomatonBuilder

Source§

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

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

impl PartialEq for GeneralThresholdAutomatonBuilder

Source§

fn eq(&self, other: &GeneralThresholdAutomatonBuilder) -> 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 GeneralThresholdAutomatonBuilder

Source§

impl StructuralPartialEq for GeneralThresholdAutomatonBuilder

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.