Package 'petrinetR'

Title: Building, Visualizing, Exporting and Replaying Petri Nets
Description: Functions for the construction of Petri Nets. Petri Nets can be replayed by firing enabled transitions. Silent transitions will be hidden by the execution handler. Also includes functionalities for the visualization of Petri Nets and export of Petri Nets to PNML (Petri Net Markup Language) files.
Authors: Gert Janssenswillen [aut, cre], Ivan Esin [ctb]
Maintainer: Gert Janssenswillen <[email protected]>
License: GPL-3
Version: 0.3.0
Built: 2024-11-27 06:11:54 UTC
Source: https://github.com/bupaverse/petrinetr

Help Index


Create marked Petri Net

Description

Function to create a marked_petrinet, consisting of a petrinet, an initial marking, and a final marking.

Usage

create_marked_PN(PN, initial_marking, final_marking)

Arguments

PN

petrinet: Object of class petrinet.

initial_marking

character: A vector with place ids representing the initial marking.

final_marking

character: A vector with place ids representing the final marking.

Value

A marked_petrinet


Create Petri Net

Description

Function to create a petrinet by specifying places, transitions and flows.

Usage

create_PN(places, transitions, flows)

Arguments

places

data.frame or tibble of places, with columns id and label. Both columns should be characters.

transitions

data.frame or tibble of transitions, with columns id and label. Both columns should be characters.

flows

data.frame or tibble of flows, with columns named "from" and "to", referring to ids of places and transitions. Both columns should be characters.

Value

A petrinet

Examples

library(dplyr)
create_PN(tibble(id = "p1", label = "place_1"),
			tibble(id = "t1", label = "transition_1"),
			tibble(from = "t1",to = "p1"))

Enabled transitions

Description

List the enabled transitions in a marked Petri Net. Silent transitions, i.e. starting with "inv_" or "tau" are assumed to be able to fire silently, thereby possible enabling other transitions.

Usage

enabled(PN)

Arguments

PN

A Petri Net


Enabled Transition

Description

Check if a transition is currently enabled

Usage

enabled_transition(PN, transition)

Arguments

PN

A Petri Net

transition

A Transition


Execute

Description

Executes (fire) an enabled transition and returns the Petri Net with the New marking. If the transition is enabled via the firing of silent transition (i.e. starting with "inv_" of "tau"), it will fire these first. If the transition is not enabled, it will return FALSE.

Usage

execute(PN, transition)

Arguments

PN

A Petri Net

transition

The transition to be fired


Final Marking

Description

Get the final marking of a marked_petrinet

Usage

final_marking(PN)

Arguments

PN

A marked_petrinet


Flows

Description

Extracts the flows from a (marked) Petri Net

Usage

flows(PN)

## S3 method for class 'petrinet'
flows(PN)

## S3 method for class 'marked_petrinet'
flows(PN)

Arguments

PN

petrinet or marked_petrinet

Value

A data.frame containing the flows of the petri net.

Methods (by class)

  • flows(petrinet): Flow of petrinet

  • flows(marked_petrinet): Flow of marked petrinet


Initial Marking

Description

Get the initial marking of a marked_petrinet

Usage

initial_marking(PN)

Arguments

PN

A marked_petrinet


Is node

Description

Check if a node is part of a petri net

Usage

is_node(node, PN)

Arguments

node

character of length one: the node id to check.

PN

petrinet or marked_petrinet

Value

logical that indicates whether node is a node in PN


Is place

Description

Check if a place is part of a petri net.

Usage

is_place(place, PN)

Arguments

place

character of length one: the place id to check.

PN

petrinet or marked_petrinet

Value

logical that indicates whether place is a place in PN


Is transition

Description

Check if a transition is part of a petri net.

Usage

is_transition(transition, PN)

Arguments

transition

character of length one: the transition id to check.

PN

petrinet or marked_petrinet

Value

logical that indicates whether transition is a transition in PN


Marked petrinet

Description

Object consisting of a petrinet, initial marking, and final marking


Marking

Description

Get the current marking of a Petri Net

Usage

marking(PN)

Arguments

PN

A Petri Net


Utils

Description

Several auxilliary functions for Petri Net objects.

Usage

n_places(PN)

n_transitions(PN)

n_flows(PN)

n_nodes(PN)

rename_transitions(PN, .f, ...)

rename_places(PN, .f, ...)

add_places(PN, places)

add_transitions(PN, transitions)

add_flows(PN, flows)

Arguments

PN

A petri net

.f

A function name to apply for renaming

...

Additional arguments

places

data.frame or tibble of places, with columns id and label. Both columns should be characters.

transitions

data.frame or tibble of transitions, with columns id and label. Both columns should be characters.

flows

data.frame or tibble of flows, with columns named "from" and "to", referring to ids of places and transitions. Both columns should be characters.


Get nodes from (marked) petrinet

Description

Get nodes from (marked) petrinet

Usage

nodes(PN)

Arguments

PN

petrinet or marked_petrinet


Parse

Description

Parses a sequence of transitions. If possible returns the Petri Net with the updated marking. Otherwise returns FALSE

Usage

parse_trace(PN, trace)

Arguments

PN

A Petri Net

trace

A sequence of transitions, stored in a vector.


Parse (logical)

Description

Tests whether a sequence of transitions can be fired by a Petri Net. If so returns TRUE, otherwise FALSE.

Usage

parsel_trace(PN, trace)

Arguments

PN

A Petri Net

trace

A sequence of transitions, stored in a vector.


Part of

Description

Check if a node is part of a petri net

Usage

part_of(node, PN)

Arguments

node

A node

PN

A Petri Net


Ppetrinet

Description

Object consisting of places, transitions and flows that denote a petri net


petrinetR - Building, visualizing, exporting and replaying Petri Nets

Description

Functions for the construction of Petri Nets. Petri Nets can be replayed by firing enabled transitions. Silent transitions will be hidden by the execution handler. Also includes functionalities for the visualization of Petri Nets and export of Petri Nets to PNML-files.


Places

Description

Extracts the places from a Petri Net

Usage

places(PN)

## S3 method for class 'petrinet'
places(PN)

## S3 method for class 'marked_petrinet'
places(PN)

Arguments

PN

petrinet or marked_petrinet

Methods (by class)

  • places(petrinet): Places of petrinet

  • places(marked_petrinet): Places of marked petrinet


Postset

Description

Get the postset of a transition or place in a Petri Net

Usage

post_set(PN, node)

Arguments

PN

petrinet or marked_petrinet

node

character of length one: the node id for which to get the postset.


Preset

Description

Get the preset of a transition or place in a Petri Net

Usage

pre_set(PN, node)

Arguments

PN

petrinet or marked_petrinet

node

character of length one: the node id for which to get the postset.


Read .PNML file

Description

Read .PNML file

Usage

read_PN(file, add_final_marking = TRUE)

Arguments

file

Path to .pnml file

add_final_marking

logical (default: TRUE): add final marking. If TRUE, all places without outgoing flows are considered part of a single final marking. Overwrite with set_final_marking() if needed. If FALSE, final_marking is set to NULL

Value

A codemarked_petrinet


Render Petri Net

Description

Visualize Petri Net with bipartite graph.

Usage

render_PN(PN)

Arguments

PN

petrinet or marked_petrinet


Transitions

Description

Extracts the transitions from a Petri Net

Usage

transitions(PN)

## S3 method for class 'petrinet'
transitions(PN)

## S3 method for class 'marked_petrinet'
transitions(PN)

Arguments

PN

petrinet or marked_petrinet

Methods (by class)

  • transitions(petrinet): Transitions of petrinet

  • transitions(marked_petrinet): Transitions of marked petrinet


VisNetwork from PN

Description

Visualize a Petri Net with an interactive network

Usage

visNetwork_from_PN(PN)

Arguments

PN

petrinet or marked_petrinet