Class PetriNet
java.lang.Object
org.tweetyproject.logics.petri.syntax.PetriNet
- All Implemented Interfaces:
Iterable<PetriNetNode>
,GeneralGraph<PetriNetNode>
,Graph<PetriNetNode>
A class to represent a Petri net
- Author:
- Benedikt Knopp, Matthias Thimm
-
Field Summary
Fields inherited from interface org.tweetyproject.graphs.Graph
IGNORE_SELFLOOPS, INVERT_SELFLOOPS, REMOVE_SELFLOOPS
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
add
(Edge<PetriNetNode> edge) Return addboolean
add
(GeneralEdge<PetriNetNode> edge) Adds the given edge to this graph.boolean
add
(PetriNetNode node) Adds the given node to this graph.boolean
Add a place to the Petri netboolean
add
(Transition transition) Add a transition to the Petri netboolean
addInitialMarking
(Marking initialMarking) add a designated initial markingboolean
Returns "true" iff the two nodes are connected by a directed edge from a to b or an undirected edge.boolean
check if this Petri net is short-circuitedboolean
Returns "true" when this graph contains the given node or edge.createEmptyTransition
(Marking marking) Add a transition which is enabled at the specified marking and does not change the markingboolean
existsDirectedPath
(PetriNetNode node1, PetriNetNode node2) Checks whether there is a (directed) path from node1 to node2.void
fire
(Transition transition) FireReturns the adjacency matrix of this graph (the order of the nodes is the same as returned by "iterator()").getChildren
(Node node) Returns the set of children (node connected via an undirected edge or a directed edge where the given node is the parent) of the given node.getComplementGraph
(int selfloops) Returns the complement graph of this graph, i.e.getEdge
(PetriNetNode a, PetriNetNode b) Returns the corresponding edge (a,b) if a and b are adjacent.getEdges()
Returns the edges of this graph.Retrieve the transitions that are enabled in the current state (token distribution) of the netReturn the initialMarkingsGet the marking of this graph, based on the current token distribution at the placesgetNeighbors
(PetriNetNode node) Returns the set of neighbors of the given node.getNodes()
Returns the nodes of this graph.int
Returns the number of edges in this graph.int
Returns the number of nodes in this graph.getParents
(Node node) Returns the set of parents (node connected via an undirected edge or a directed edge where the given node is the child) of the given node.Return the placesgetRestriction
(Collection<PetriNetNode> nodes) Returns a copy of this graph that contains only the specified nodes and all corresponding edges between them.Returns the strongly connected components of this graph.Returns the set of sub graphs of this graph.Return the transitionsboolean
Returns "true" iff the graph has a self loop (an edge from a node to itself).boolean
Check whether the marking is an initial markingboolean
Checks whether this graph only contains weighted edges.iterator()
void
setEdges
(Set<Edge<PetriNetNode>> edges) Setter Edgesvoid
Setter placesvoid
Set the state (token distribution) according to the provided markingvoid
setTransitions
(List<Transition> transitions) Setter transitionsvoid
Transform the Petri net to the short-circuited version, where the final place and initial place are linked via a transitionMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
PetriNet
public PetriNet()Default
-
-
Method Details
-
add
Description copied from interface:Graph
Adds the given node to this graph.- Specified by:
add
in interfaceGraph<PetriNetNode>
- Parameters:
node
- some node.- Returns:
- "true" iff the edge has been added successfully.
-
add
Add a place to the Petri net- Parameters:
place
- the place- Returns:
- true iff adding the place was successful
-
add
Add a transition to the Petri net- Parameters:
transition
- the transition- Returns:
- true iff adding the transition was successful
-
add
-
getNodes
Description copied from interface:Graph
Returns the nodes of this graph.- Specified by:
getNodes
in interfaceGeneralGraph<PetriNetNode>
- Specified by:
getNodes
in interfaceGraph<PetriNetNode>
- Returns:
- the nodes of this graph.
-
getNumberOfNodes
public int getNumberOfNodes()Description copied from interface:Graph
Returns the number of nodes in this graph.- Specified by:
getNumberOfNodes
in interfaceGraph<PetriNetNode>
- Returns:
- the number of nodes in this graph.
-
getNumberOfEdges
public int getNumberOfEdges()Description copied from interface:Graph
Returns the number of edges in this graph.- Specified by:
getNumberOfEdges
in interfaceGraph<PetriNetNode>
- Returns:
- the number of edges in this graph.
-
areAdjacent
Description copied from interface:Graph
Returns "true" iff the two nodes are connected by a directed edge from a to b or an undirected edge.- Specified by:
areAdjacent
in interfaceGraph<PetriNetNode>
- Parameters:
a
- some nodeb
- some node- Returns:
- "true" iff the two nodes are connected by a directed edge from a to b or an undirected edge.
-
getEdge
Description copied from interface:Graph
Returns the corresponding edge (a,b) if a and b are adjacent. Otherwise it returns null.- Specified by:
getEdge
in interfaceGraph<PetriNetNode>
- Parameters:
a
- some nodeb
- some node- Returns:
- the edge (a,b) or null.
-
getEdges
Description copied from interface:Graph
Returns the edges of this graph.- Specified by:
getEdges
in interfaceGeneralGraph<PetriNetNode>
- Specified by:
getEdges
in interfaceGraph<PetriNetNode>
- Returns:
- the edges of this graph.
-
getPlaces
-
getTransitions
-
setPlaces
-
getInitialMarkings
-
iterator
- Specified by:
iterator
in interfaceGraph<PetriNetNode>
- Specified by:
iterator
in interfaceIterable<PetriNetNode>
-
contains
Description copied from interface:Graph
Returns "true" when this graph contains the given node or edge.- Specified by:
contains
in interfaceGraph<PetriNetNode>
- Parameters:
obj
- an object- Returns:
- "true" if this graph contains the given node or edge.
-
getChildren
Description copied from interface:Graph
Returns the set of children (node connected via an undirected edge or a directed edge where the given node is the parent) of the given node.- Specified by:
getChildren
in interfaceGraph<PetriNetNode>
- Parameters:
node
- some node (must be in the graph).- Returns:
- the set of children of the given node.
-
getParents
Description copied from interface:Graph
Returns the set of parents (node connected via an undirected edge or a directed edge where the given node is the child) of the given node.- Specified by:
getParents
in interfaceGraph<PetriNetNode>
- Parameters:
node
- some node (must be in the graph).- Returns:
- the set of parents of the given node.
-
existsDirectedPath
Description copied from interface:Graph
Checks whether there is a (directed) path from node1 to node2.- Specified by:
existsDirectedPath
in interfaceGraph<PetriNetNode>
- Parameters:
node1
- some node.node2
- some node.- Returns:
- "true" if there is a directed path from node1 to node2.
-
getNeighbors
Description copied from interface:Graph
Returns the set of neighbors of the given node.- Specified by:
getNeighbors
in interfaceGraph<PetriNetNode>
- Parameters:
node
- some node (must be in the graph).- Returns:
- the set of neighbors of the given node.
-
getAdjacencyMatrix
Description copied from interface:Graph
Returns the adjacency matrix of this graph (the order of the nodes is the same as returned by "iterator()").- Specified by:
getAdjacencyMatrix
in interfaceGraph<PetriNetNode>
- Returns:
- the adjacency matrix of this graph
-
getComplementGraph
Description copied from interface:Graph
Returns the complement graph of this graph, i.e. the graph on the same set of vertices as this graph that connects two vertices v and w with an edge if and only if v and w are not connected in this graph.- Specified by:
getComplementGraph
in interfaceGraph<PetriNetNode>
- Parameters:
selfloops
- Indicates how to deal with selfloops:
IGNORE_SELFLOOPS - ignore self loops (don't add and don't remove)
INVERT_SELFLOOPS - deal with self loops like ordinary edges (add if not present and remove if present)
REMOVE_SELFLOOPS - simple remove self loops, but don't add new ones.- Returns:
- the complement graph of this graph.
-
getStronglyConnectedComponents
Description copied from interface:Graph
Returns the strongly connected components of this graph. A set of nodes is strongly connected, if there is a path from each node to each other. A set of nodes is called strongly connected component if it is strongly connected and maximal with respect to set inclusion.- Specified by:
getStronglyConnectedComponents
in interfaceGraph<PetriNetNode>
- Returns:
- the strongly connected components of this graph.
-
getSubgraphs
Description copied from interface:Graph
Returns the set of sub graphs of this graph.- Specified by:
getSubgraphs
in interfaceGraph<PetriNetNode>
- Returns:
- the set of sub graphs of this graph.
-
getRestriction
Description copied from interface:GeneralGraph
Returns a copy of this graph that contains only the specified nodes and all corresponding edges between them.This method generates a subgraph (or restricted graph) from the current graph by including only the given nodes and the edges that connect them. The returned graph is a new instance and does not modify the original graph.
- Specified by:
getRestriction
in interfaceGeneralGraph<PetriNetNode>
- Parameters:
nodes
- a collection of nodes to be included in the restricted graph.- Returns:
- a `GeneralGraph` object representing the restricted graph.
-
hasSelfLoops
public boolean hasSelfLoops()Description copied from interface:Graph
Returns "true" iff the graph has a self loop (an edge from a node to itself).- Specified by:
hasSelfLoops
in interfaceGraph<PetriNetNode>
- Returns:
- "true" iff the graph has a self loop (an edge from a node to itself).
-
isWeightedGraph
public boolean isWeightedGraph()Description copied from interface:Graph
Checks whether this graph only contains weighted edges.- Specified by:
isWeightedGraph
in interfaceGraph<PetriNetNode>
- Returns:
- "true" if all edges are weighted in this graph.
-
fire
-
getMarking
Get the marking of this graph, based on the current token distribution at the places- Returns:
- the current marking
-
getEnabledTransitions
Retrieve the transitions that are enabled in the current state (token distribution) of the net- Returns:
- the enabled transitions
-
addInitialMarking
add a designated initial marking- Parameters:
initialMarking
- the initial marking- Returns:
- true iff adding the marking was successful
-
isInitial
Check whether the marking is an initial marking- Parameters:
marking
- the marking- Returns:
- true iff the marking is initial
-
setState
Set the state (token distribution) according to the provided marking- Parameters:
marking
- the marking
-
add
Description copied from interface:Graph
Adds the given edge to this graph. If at least one of the nodes the given edge connects is not in the graph, an illegal argument exception is thrown.- Specified by:
add
in interfaceGraph<PetriNetNode>
- Parameters:
edge
- some edge.- Returns:
- "true" iff the edge has been added successfully.
-
createEmptyTransition
Add a transition which is enabled at the specified marking and does not change the marking- Parameters:
marking
- the marking- Returns:
- a empty transition
-
transformToShortCircuit
Transform the Petri net to the short-circuited version, where the final place and initial place are linked via a transition- Throws:
IllegalStateException
- if the transformation is not possible due to violations of syntactical requirements
-
setEdges
Setter Edges- Parameters:
edges
- the arks (edges)
-
setTransitions
Setter transitions- Parameters:
transitions
- the transitions
-
checkShortCircuit
check if this Petri net is short-circuited- Returns:
- true if this Petri net is short-circuited
- Throws:
IllegalStateException
- if the number of initial and final places in this net is not equal to 1
-