Skip to main content

ProgramGraphBuilder

Struct ProgramGraphBuilder 

Source
pub struct ProgramGraphBuilder { /* private fields */ }
Expand description

Defines and builds a PG.

Implementations§

Source§

impl ProgramGraphBuilder

Source

pub fn new() -> Self

Creates a new ProgramGraphBuilder. At creation, this will only have the initial location with no variables, no actions and no transitions.

Source

pub fn new_var(&mut self, val: Val) -> Result<Var, PgError>

Adds a new variable with the given initial value (and the inferred type) to the PG. It creates and uses a default RNG for probabilistic expressions.

It fails if the expression giving the initial value of the variable is not well-typed.

// Create a new action
let action = pg_builder.new_action();

// Create a value to assign the expression.
let val = (PgExpression::from(40i64) + PgExpression::from(40i64)).unwrap().eval_constant().unwrap();

// Create a new variable
let var = pg_builder
    .new_var(val)
    .unwrap();
Source

pub fn new_clock(&mut self) -> Clock

Adds a new clock and returns a Clock id object.

See also crate::channel_system::ChannelSystemBuilder::new_clock.

Source

pub fn new_action(&mut self) -> Action

Adds a new action to the PG.

// Create a new action
let action: Action = pg_builder.new_action();
Source

pub fn add_reset(&mut self, action: Action, clock: Clock) -> Result<(), PgError>

Associates a clock reset to an action.

Returns an error if the clock to be reset does not belong to the Program Graph.

let action = pg_builder.new_action();
let clock = other_pg_builder.new_clock();
// Associate action with clock reset
pg_builder
    .add_reset(action, clock)
    .expect_err("the clock does not belong to this PG");
Source

pub fn add_effect( &mut self, action: Action, var: Var, effect: PgExpression, ) -> Result<(), PgError>

Adds an effect to the given action. Requires specifying which variable is assigned the value of which expression whenever the action triggers a transition.

It fails if the type of the variable and that of the expression do not match.

// Create a new action
let action: Action = pg_builder.new_action();

// Create a new variable
let var: Var = pg_builder.new_var(Val::from(true)).expect("expression is well-typed");

// Add an effect to the action
pg_builder
    .add_effect(action, var, PgExpression::from(1i64))
    .expect_err("var is of type bool but expression is of type integer");
pg_builder
    .add_effect(action, var, PgExpression::from(false))
    .expect("var and expression type match");
Source

pub fn new_location(&mut self) -> Location

Adds a new location to the PG and returns its Location indexing object.

Source

pub fn new_timed_location( &mut self, invariants: Vec<TimeConstraint>, ) -> Result<Location, PgError>

Adds a new location to the PG with the given time invariants, and returns its Location indexing object.

Source

pub fn new_process(&mut self, location: Location) -> Result<(), PgError>

Adds a new (synchronous) process to the PG starting from the given Location.

Source

pub fn new_initial_location(&mut self) -> Location

Adds a new process starting at a new location to the PG and returns the Location indexing object.

Source

pub fn new_initial_timed_location( &mut self, invariants: Vec<TimeConstraint>, ) -> Result<Location, PgError>

Adds a new process starting at a new location to the PG with the given time invariants, and returns the Location indexing object.

Source

pub fn add_transition( &mut self, pre: Location, action: Action, post: Location, guard: Option<PgGuard>, ) -> Result<(), PgError>

Adds a transition to the PG. Requires specifying:

  • state pre-transition,
  • action triggering the transition,
  • state post-transition, and
  • (optionally) boolean expression guarding the transition.

Fails if the provided guard is not a boolean expression.

// The builder is initialized with an initial location
let initial_loc = pg_builder.new_initial_location();

// Create a new action
let action = pg_builder.new_action();

// Add a transition
pg_builder
    .add_transition(initial_loc, action, initial_loc, None)
    .expect("this transition can be added");
pg_builder
    .add_transition(initial_loc, action, initial_loc, Some(BooleanExpr::from(false)))
    .expect("this one too");
Source

pub fn add_timed_transition( &mut self, pre: Location, action: Action, post: Location, guard: Option<PgGuard>, constraints: Vec<TimeConstraint>, ) -> Result<(), PgError>

Adds a timed transition to the PG under timed constraints. Requires specifying the same data as ProgramGraphBuilder::add_transition, plus a slice of time constraints.

Fails if the provided guard is not a boolean expression.

// The builder is initialized with an initial location
let initial_loc = pg_builder.new_initial_location();

// Create a new action
let action = pg_builder.new_action();

// Add a new clock
let clock = pg_builder.new_clock();

// Add a timed transition
pg_builder
    .add_timed_transition(initial_loc, action, initial_loc, None, vec![(clock, None, Some(1))])
    .expect("this transition can be added");
pg_builder
    .add_timed_transition(initial_loc, action, initial_loc, Some(BooleanExpr::from(false)), vec![(clock, Some(1), None)])
    .expect("this one too");
Source

pub fn add_autonomous_transition( &mut self, pre: Location, post: Location, guard: Option<PgGuard>, ) -> Result<(), PgError>

Adds an autonomous transition to the PG, i.e., a transition enabled by the epsilon action. Requires specifying:

  • state pre-transition,
  • state post-transition, and
  • (optionally) boolean expression guarding the transition.

Fails if the provided guard is not a boolean expression.

// The builder is initialized with an initial location
let initial_loc = pg_builder.new_initial_location();

// Add a transition
pg_builder
    .add_autonomous_transition(initial_loc, initial_loc, None)
    .expect("this autonomous transition can be added");
pg_builder
    .add_autonomous_transition(initial_loc, initial_loc, Some(BooleanExpr::from(false)))
    .expect("this one too");
Source

pub fn add_autonomous_timed_transition( &mut self, pre: Location, post: Location, guard: Option<PgGuard>, constraints: Vec<TimeConstraint>, ) -> Result<(), PgError>

Adds an autonomous timed transition to the PG, i.e., a transition enabled by the epsilon action under time constraints. Requires specifying the same data as ProgramGraphBuilder::add_autonomous_transition, plus a slice of time constraints.

Fails if the provided guard is not a boolean expression.

// The builder is initialized with an initial location
let initial_loc = pg_builder.new_initial_location();

// Add a new clock
let clock = pg_builder.new_clock();

// Add an autonomous timed transition
pg_builder
    .add_autonomous_timed_transition(initial_loc, initial_loc, None, vec![(clock, None, Some(1))])
    .expect("this transition can be added");
pg_builder
    .add_autonomous_timed_transition(initial_loc, initial_loc, Some(BooleanExpr::from(false)), vec![(clock, Some(1), None)])
    .expect("this one too");
Source

pub fn build(self) -> ProgramGraph

Produces a ProgramGraph defined by the ProgramGraphBuilder’s data and consuming it.

Since the construction of the builder is already checked ad every step, this method cannot fail.

Trait Implementations§

Source§

impl Clone for ProgramGraphBuilder

Source§

fn clone(&self) -> ProgramGraphBuilder

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 ProgramGraphBuilder

Source§

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

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

impl Default for ProgramGraphBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.