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
impl PetriNet
Sourcepub fn add_place(&mut self, place_id: Option<Uuid>) -> PlaceID
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
Sourcepub fn add_transition(
&mut self,
label: Option<String>,
transition_id: Option<Uuid>,
) -> TransitionID
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
Sourcepub fn remove_node(&mut self, id: &Uuid)
pub fn remove_node(&mut self, id: &Uuid)
Remove any node (Transition/Place) from the Petri net
Sourcepub fn remove_place(&mut self, place_id: &Uuid)
pub fn remove_place(&mut self, place_id: &Uuid)
Remove a Place from the Petri net
Sourcepub fn remove_transition(&mut self, transition_id: &Uuid)
pub fn remove_transition(&mut self, transition_id: &Uuid)
Remove a Transition from the Petri net
Sourcepub fn preset_of(&self, id: Uuid) -> PetriNetNodes
pub fn preset_of(&self, id: Uuid) -> PetriNetNodes
Get the preset of a PetriNet node referred to by passed id
Sourcepub fn preset_of_place(&self, p: PlaceID) -> Vec<TransitionID>
pub fn preset_of_place(&self, p: PlaceID) -> Vec<TransitionID>
Get the preset of a PetriNet place
Sourcepub fn preset_of_transition(&self, t: TransitionID) -> Vec<PlaceID>
pub fn preset_of_transition(&self, t: TransitionID) -> Vec<PlaceID>
Get the preset of PetriNet transition referred to by passed id
Sourcepub fn postset_of(&self, id: &Uuid) -> PetriNetNodes
pub fn postset_of(&self, id: &Uuid) -> PetriNetNodes
Get postset of PetriNet node referred to by passed id
Sourcepub fn postset_of_place(&self, p: PlaceID) -> Vec<TransitionID>
pub fn postset_of_place(&self, p: PlaceID) -> Vec<TransitionID>
Get postset of PetriNet place referred to by passed id
Sourcepub fn postset_of_transition(&self, t: TransitionID) -> Vec<PlaceID>
pub fn postset_of_transition(&self, t: TransitionID) -> Vec<PlaceID>
Get postset of PetriNet transition referred to by passed id
Sourcepub fn is_in_initial_marking(&self, p: &PlaceID) -> bool
pub fn is_in_initial_marking(&self, p: &PlaceID) -> bool
Check if place is in initial marking
Sourcepub fn is_in_a_final_marking(&self, p: &PlaceID) -> bool
pub fn is_in_a_final_marking(&self, p: &PlaceID) -> bool
Check if place is in any final marking
Sourcepub fn export_png<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>
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.
Sourcepub fn export_svg<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>
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.
Sourcepub fn export_pnml<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>
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).
Sourcepub fn import_pnml<P: AsRef<Path>>(path: P) -> Result<PetriNet, PNMLParseError>
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<'de> Deserialize<'de> for PetriNet
impl<'de> Deserialize<'de> for PetriNet
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for PetriNet
impl RefUnwindSafe for PetriNet
impl Send for PetriNet
impl Sync for PetriNet
impl Unpin for PetriNet
impl UnwindSafe for PetriNet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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