Class ReachabilityGraph
java.lang.Object
org.tweetyproject.logics.petri.syntax.reachability_graph.ReachabilityGraph
- All Implemented Interfaces:
Iterable<Marking>,BeliefBase,GeneralGraph<Marking>,Graph<Marking>
A class to describe the graph of reachability between possible markings of a Petri net
- Author:
- Benedikt Knopp
-
Field Summary
Fields inherited from interface org.tweetyproject.graphs.Graph
IGNORE_SELFLOOPS, INVERT_SELFLOOPS, REMOVE_SELFLOOPS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(GeneralEdge<Marking> edge) Adds the given edge to this graph.booleanAdds the given node to this graph.booleanadd(MarkingEdge edge) add a marking edge to this graphbooleanareAdjacent(Marking a, Marking b) Returns "true" iff the two nodes are connected by a directed edge from a to b or an undirected edge.booleancheck if all nodes (markings) of this graph describe the same Petri net, i.e.booleanReturns "true" when this graph contains the given node or edge.booleanexistsDirectedPath(Marking node1, Marking node2) Checks whether there is a (directed) path from node1 to node2.Returns 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.Returns the set of (simple) connected components of this graph.Retrieve a matrix that specifies for each pair of marking and transition how likely that transition is going to occur at that marking, based on the probability function that describes this graph.Returns the corresponding edge (a,b) if a and b are adjacent.getEdges()Returns the edges of this graph.Retrieve the designated initial markingsgetMarking(Marking marking) Retrieve, if present, the marking in this graph that equals the query marking in the sense that both markings describe the same token distribution over placesRetrieve the markingsReturns the signature of the language of this knowledge base.getNeighbors(Marking node) Returns the set of neighbors of the given node.getNodes()Returns the nodes of this graph.intthe number of edges in this graphintReturns the number of nodes in this graph.getOutgoing(Marking marking) For one particular marking, retrieve all outgoing edgesgetParents(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 petriNetthe probability function of this graph, which is null for defaultgetRestriction(Collection<Marking> 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.Retrieve a matrix that specifies for each pair of markings how likely a transition between these markings is going to happen, based on the probability function that describes this graph.booleanhasMarking(Marking marking) Determine if the specified marking is present as a node in the graphbooleanReturns "true" iff the graph has a self loop (an edge from a node to itself).booleanspecifies if the probability function of this graph is 1.voidinitializes a probability function over the edges of this graph according to Random Walk, i.e.voidInitialize a probability function over the edges of this graph according to a stochastic walk.voidInitialize a probability function over the edges of this graph according to a stochastic walk.booleanCheck whether a marking is a designated initial markingbooleanChecks whether this graph only contains weighted edges.iterator()voidsetPetriNet(PetriNet petriNet) Setter petriNetvoidsetProbabilityFunction(ProbabilityFunction<MarkingEdge> probabilityFunction) sets the probability function of this graphvoidfix the sorting to prepare linear algebra analysis in particular, assert a fixed ordering for index-based matrix/vector-accessMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.tweetyproject.commons.BeliefBase
toStringMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ReachabilityGraph
Create a new instance- Parameters:
petriNet- the underlying Petri net
-
-
Method Details
-
add
-
add
add a marking edge to this graph- Parameters:
edge- the edge- Returns:
- true iff adding the edge was successful
-
add
Description copied from interface:GraphAdds 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. -
getNodes
-
getNumberOfNodes
public int getNumberOfNodes()Description copied from interface:GraphReturns the number of nodes in this graph.- Specified by:
getNumberOfNodesin interfaceGraph<Marking>- Returns:
- the number of nodes in this graph.
-
getNumberOfEdges
public int getNumberOfEdges()the number of edges in this graph- Specified by:
getNumberOfEdgesin interfaceGraph<Marking>- Returns:
- the number of edges in this graph
-
areAdjacent
Description copied from interface:GraphReturns "true" iff the two nodes are connected by a directed edge from a to b or an undirected edge.- Specified by:
areAdjacentin interfaceGraph<Marking>- 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:GraphReturns the corresponding edge (a,b) if a and b are adjacent. Otherwise it returns null. -
getEdges
Description copied from interface:GraphReturns the edges of this graph. -
getPetriNet
-
setPetriNet
Setter petriNet- Parameters:
petriNet- the petriNet to set
-
getProbabilityFunction
the probability function of this graph, which is null for default- Returns:
- the probabilityFunction
-
setProbabilityFunction
sets the probability function of this graph- Parameters:
probabilityFunction- the probability function to set
-
initializeDefaultProbabilityFunction
public void initializeDefaultProbabilityFunction()initializes a probability function over the edges of this graph according to Random Walk, i.e. all outgoing edges of one particular node are assigned to the same probability and the sum of these probabilities equals to 1. -
initializeRandomProbabilityFunction
public void initializeRandomProbabilityFunction()Initialize a probability function over the edges of this graph according to a stochastic walk. The sum of probabilities of outgoing edges at each node equals to 1, and for multiple outgoing edges, probabilities are randomized. -
initializeIrregularProbabilityFunction
public void initializeIrregularProbabilityFunction()Initialize a probability function over the edges of this graph according to a stochastic walk. For multiple outgoing edges, exactly one edge receives a probability of 1 and all other edges a probability of 0. This may turn some transitions dead. -
hasValidProbabilityFunction
public boolean hasValidProbabilityFunction()specifies if the probability function of this graph is 1. initialized, and 2. assigns for each marking a total (summed up) probability of 1 for all successor edges. This implies that each marking needs to have at least one successor marking.- Returns:
- true iff the probability function is valid
-
sortMarkings
public void sortMarkings()fix the sorting to prepare linear algebra analysis in particular, assert a fixed ordering for index-based matrix/vector-access -
getTransitionMatrix
Retrieve a matrix that specifies for each pair of markings how likely a transition between these markings is going to happen, based on the probability function that describes this graph.- Returns:
- the transition matrix
- Throws:
IllegalStateException- iff the probability function of this graph is invalid
-
getControlMatrix
Retrieve a matrix that specifies for each pair of marking and transition how likely that transition is going to occur at that marking, based on the probability function that describes this graph.- Returns:
- the control matrix
- Throws:
IllegalStateException- iff the probability function of this graph is invalid
-
iterator
-
contains
-
getChildren
Description copied from interface:GraphReturns 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:
getChildrenin interfaceGraph<Marking>- Parameters:
node- some node (must be in the graph).- Returns:
- the set of children of the given node.
-
getParents
Description copied from interface:GraphReturns 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:
getParentsin interfaceGraph<Marking>- Parameters:
node- some node (must be in the graph).- Returns:
- the set of parents of the given node.
-
existsDirectedPath
Description copied from interface:GraphChecks whether there is a (directed) path from node1 to node2.- Specified by:
existsDirectedPathin interfaceGraph<Marking>- Parameters:
node1- some node.node2- some node.- Returns:
- "true" if there is a directed path from node1 to node2.
-
getNeighbors
Description copied from interface:GraphReturns the set of neighbors of the given node.- Specified by:
getNeighborsin interfaceGraph<Marking>- Parameters:
node- some node (must be in the graph).- Returns:
- the set of neighbors of the given node.
-
getAdjacencyMatrix
Description copied from interface:GraphReturns the adjacency matrix of this graph (the order of the nodes is the same as returned by "iterator()").- Specified by:
getAdjacencyMatrixin interfaceGraph<Marking>- Returns:
- the adjacency matrix of this graph
-
getComplementGraph
Description copied from interface:GraphReturns 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:
getComplementGraphin interfaceGraph<Marking>- 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.
-
getConnectedComponents
Description copied from interface:GraphReturns the set of (simple) connected components of this graph. A set of nodes is connected, if there is some path (ignoring edge directions) from each node to each other. It is a connected component if it is connected and maximal wrt. set inclusion.- Specified by:
getConnectedComponentsin interfaceGraph<Marking>- Returns:
- the connected components of this graph.
-
getStronglyConnectedComponents
Description copied from interface:GraphReturns 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:
getStronglyConnectedComponentsin interfaceGraph<Marking>- Returns:
- the strongly connected components of this graph.
-
getSubgraphs
Description copied from interface:GraphReturns the set of sub graphs of this graph.- Specified by:
getSubgraphsin interfaceGraph<Marking>- Returns:
- the set of sub graphs of this graph.
-
getRestriction
Description copied from interface:GeneralGraphReturns 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:
getRestrictionin interfaceGeneralGraph<Marking>- 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:GraphReturns "true" iff the graph has a self loop (an edge from a node to itself).- Specified by:
hasSelfLoopsin interfaceGraph<Marking>- Returns:
- "true" iff the graph has a self loop (an edge from a node to itself).
-
isWeightedGraph
public boolean isWeightedGraph()Description copied from interface:GraphChecks whether this graph only contains weighted edges.- Specified by:
isWeightedGraphin interfaceGraph<Marking>- Returns:
- "true" if all edges are weighted in this graph.
-
hasMarking
Determine if the specified marking is present as a node in the graph- Parameters:
marking- the marking- Returns:
- true if the marking is present
-
getMarking
Retrieve, if present, the marking in this graph that equals the query marking in the sense that both markings describe the same token distribution over places- Parameters:
marking- the query marking- Returns:
- the marking that equals the query marking, or null if not present
-
getOutgoing
For one particular marking, retrieve all outgoing edges- Parameters:
marking- the marking of interest- Returns:
- the sequence flow successors
-
checkConsistency
public boolean checkConsistency()check if all nodes (markings) of this graph describe the same Petri net, i.e. the same set of places- Returns:
- true iff all markings describe the same set of places
-
getMinimalSignature
Description copied from interface:BeliefBaseReturns the signature of the language of this knowledge base.- Specified by:
getMinimalSignaturein interfaceBeliefBase- Returns:
- the signature of the language of this knowledge base.
-
getInitialMarkings
-
isInitial
Check whether a marking is a designated initial marking- Parameters:
marking- the marking to check- Returns:
- true iff the marking is initial
-
getMarkings
-