PetriNet

Struct PetriNet 

Source
pub struct PetriNet {
    pub places: HashMap<Uuid, Place>,
    pub transitions: HashMap<Uuid, Transition>,
    pub arcs: Vec<Arc>,
    pub initial_marking: Option<Marking>,
    pub final_markings: Option<Vec<Marking>>,
}
Expand description

A Petri net of Places and Transitions

Bipartite graph of Places and Transitions with Arcs connecting them, as well as initial and final Markings

Fields§

§places: HashMap<Uuid, Place>

Places

§transitions: HashMap<Uuid, Transition>

Transitions

§arcs: Vec<Arc>

Arcs

§initial_marking: Option<Marking>

Initial marking

§final_markings: Option<Vec<Marking>>

Final markings (any of them are accepted as a final marking)

Implementations§

Source§

impl PetriNet

Source

pub fn new() -> Self

Create new PetriNet with no places or transitions

Source

pub fn to_json(self) -> String

Serialize to JSON string

Source

pub fn add_place(&mut self, place_id: Option<Uuid>) -> PlaceID

Add a place (with an optional passed UUID)

If no ID is passed, a new UUID will be generated

Source

pub fn add_transition( &mut self, label: Option<String>, transition_id: Option<Uuid>, ) -> TransitionID

Add a transition with an label (and with an optional passed UUID)

If no ID is passed, a new UUID will be generated

Source

pub fn add_arc(&mut self, from_to: ArcType, weight: Option<u32>)

Add an arc

Source

pub fn remove_node(&mut self, id: &Uuid)

Remove any node (Transition/Place) from the Petri net

Source

pub fn remove_place(&mut self, place_id: &Uuid)

Remove a Place from the Petri net

Source

pub fn remove_transition(&mut self, transition_id: &Uuid)

Remove a Transition from the Petri net

Source

pub fn preset_of(&self, id: Uuid) -> PetriNetNodes

Get the preset of a PetriNet node referred to by passed id

Source

pub fn preset_of_place(&self, p: PlaceID) -> Vec<TransitionID>

Get the preset of a PetriNet place

Source

pub fn preset_of_transition(&self, t: TransitionID) -> Vec<PlaceID>

Get the preset of PetriNet transition referred to by passed id

Source

pub fn postset_of(&self, id: &Uuid) -> PetriNetNodes

Get postset of PetriNet node referred to by passed id

Source

pub fn postset_of_place(&self, p: PlaceID) -> Vec<TransitionID>

Get postset of PetriNet place referred to by passed id

Source

pub fn postset_of_transition(&self, t: TransitionID) -> Vec<PlaceID>

Get postset of PetriNet transition referred to by passed id

Source

pub fn is_in_initial_marking(&self, p: &PlaceID) -> bool

Check if place is in initial marking

Source

pub fn is_in_a_final_marking(&self, p: &PlaceID) -> bool

Check if place is in any final marking

Source

pub fn export_png<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>

Export Petri net as a PNG image

The PNG file is written to the specified filepath

Note: This is an export method for visualizing the Petri net. The resulting PNG file cannot be imported as a Petri net again (for that functionality, see PetriNet::export_pnml).

Only available with the graphviz-export feature.

Source

pub fn export_svg<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>

Export Petri net as a SVG image

The SVG file is written to the specified filepath

Note: This is an export method for visualizing the Petri net. The resulting SVG file cannot be imported as a Petri net again (for that functionality, see PetriNet::export_pnml).

Only available with the graphviz-export feature.

Source

pub fn export_pnml<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>

Export Petri net to a PNML file

The PNML file is written to the specified filepath

Note: This is an export method for saving the Petri net data. The resulting file can also be imported as a Petri net again (see PetriNet::import_pnml).

Source

pub fn import_pnml<P: AsRef<Path>>(path: P) -> Result<PetriNet, PNMLParseError>

Import Petri net from a PNML file

The PNML file is read from the specified filepath

For the related export function, see PetriNet::export_pnml)

Trait Implementations§

Source§

impl Clone for PetriNet

Source§

fn clone(&self) -> PetriNet

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 PetriNet

Source§

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

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

impl Default for PetriNet

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for PetriNet

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for PetriNet

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,