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: GeneralThresholdAutomatonImplementations§
Source§impl GeneralThresholdAutomatonBuilder
impl GeneralThresholdAutomatonBuilder
Sourcefn check_for_name_clash(&self, name: &str) -> bool
fn check_for_name_clash(&self, name: &str) -> bool
Checks whether a name is already present in the threshold automaton
Sourcepub fn with_parameter(self, param: Parameter) -> Result<Self, BuilderError>
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")));Sourcepub fn with_parameters(
self,
params: impl IntoIterator<Item = Parameter>,
) -> Result<Self, BuilderError>
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")));Sourcepub fn with_variable(self, var: Variable) -> Result<Self, BuilderError>
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")));Sourcepub fn with_variables(
self,
vars: impl IntoIterator<Item = Variable>,
) -> Result<Self, BuilderError>
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")));Sourcepub fn with_location(self, loc: Location) -> Result<Self, BuilderError>
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")));Sourcepub fn with_locations(
self,
locs: impl IntoIterator<Item = Location>,
) -> Result<Self, BuilderError>
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")));Sourcepub fn initialize(self) -> InitializedGeneralThresholdAutomatonBuilder
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
impl Clone for GeneralThresholdAutomatonBuilder
Source§fn clone(&self) -> GeneralThresholdAutomatonBuilder
fn clone(&self) -> GeneralThresholdAutomatonBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl PartialEq for GeneralThresholdAutomatonBuilder
impl PartialEq for GeneralThresholdAutomatonBuilder
Source§fn eq(&self, other: &GeneralThresholdAutomatonBuilder) -> bool
fn eq(&self, other: &GeneralThresholdAutomatonBuilder) -> bool
self and other values to be equal, and is used by ==.