Class EfficientPetrinetSemanticsImpl
- java.lang.Object
-
- org.processmining.models.semantics.petrinet.impl.EfficientPetrinetSemanticsImpl
-
- All Implemented Interfaces:
java.io.Serializable,EfficientPetrinetSemantics,PetrinetSemantics,org.processmining.models.semantics.Semantics<Marking,Transition>
public final class EfficientPetrinetSemanticsImpl extends java.lang.Object implements EfficientPetrinetSemantics
More efficient implementation thanPetrinetSemanticsImplavoiding object creation.- Author:
- F. Mannhardt, S.J. van Zelst
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.processmining.models.semantics.petrinet.EfficientPetrinetSemantics
EfficientPetrinetSemantics.PlaceVisitor
-
-
Constructor Summary
Constructors Constructor Description EfficientPetrinetSemanticsImpl(PetrinetGraph net)Creates the semantics for the suppliedPetrinetGraphand an empty initial marking.EfficientPetrinetSemanticsImpl(PetrinetGraph net, Marking initialMarking)Creates the semantics for the suppliedPetrinetGraphand initialMarking.EfficientPetrinetSemanticsImpl(EfficientPetrinetSemanticsImpl semantics)Creates a copy of the supplied semantics with an independent state.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Markingconvert(byte[] marking)convert a primative int array to a marking object based on the internal index representation of the petri net's places.byte[]convert(Marking marking)allows to convert a given marking to an equivalent int array based on the internal index representation of the petri net's places.voiddirectExecuteExecutableTransition(Transition transition)Executes (fires) a transition.booleanequalMarking(byte[] marking1, Marking marking2)booleanequalOrLessMarking(byte[] marking1, Marking marking2)org.processmining.models.semantics.ExecutionInformationexecuteExecutableTransition(Transition transition)For a more efficient implementation usedirectExecuteExecutableTransition(Transition), which does not return any information about the execution.voidforEachMarkedPlace(EfficientPetrinetSemantics.PlaceVisitor placeVisitor)Visits each place that is marked with one or more tokens.voidforEachPlace(EfficientPetrinetSemantics.PlaceVisitor placeVisitor)Visits each place.MarkinggetCurrentState()Convenience method of the originalPetrinetSemanticsinterface.java.util.Collection<Transition>getExecutableTransitions()For better performance, use methodEfficientPetrinetSemantics.isEnabled(Transition)instead.intgetIndex(Place p)intgetIndex(Transition t)byte[]getMissingTokensToEnable(int transitionIndex)byte[]getMissingTokensToEnable(Transition t)figures out whether a certain transition t is missing any tokens to be fired.PlacegetPlace(int index)java.util.Map<Place,java.lang.Integer>getPlaceMap()byte[]getState()MarkinggetStateAsMarking()UsegetCurrentState()instead.TransitiongetTransition(int index)voidinitialize(java.util.Collection<Transition> transitions, Marking initialState)This method cannot be used in this implementation.booleanisEnabled(int transitionIndex)booleanisEnabled(Transition transition)booleanisMarked(byte[] marking, Place place)voidsetCurrentState(Marking marking)Convenience method of the originalPetrinetSemanticsinterface.voidsetState(byte[] marking)Sets the state to the supplied state (marking).voidsetStateAsMarking(Marking marking)UsesetCurrentState(Marking)instead.
-
-
-
Constructor Detail
-
EfficientPetrinetSemanticsImpl
public EfficientPetrinetSemanticsImpl(EfficientPetrinetSemanticsImpl semantics)
Creates a copy of the supplied semantics with an independent state. All other data structures are shared to minimize copying of data.- Parameters:
semantics-
-
EfficientPetrinetSemanticsImpl
public EfficientPetrinetSemanticsImpl(PetrinetGraph net)
Creates the semantics for the suppliedPetrinetGraphand an empty initial marking. This semantics class treat allPetrinetGraphs as aPetrinet(so do not honor the semantics of reset or inhibitor nets).- Parameters:
net- with the graph structure
-
EfficientPetrinetSemanticsImpl
public EfficientPetrinetSemanticsImpl(PetrinetGraph net, Marking initialMarking)
Creates the semantics for the suppliedPetrinetGraphand initialMarking. This semantics class treat allPetrinetGraphs as aPetrinet(so do not honor the semantics of reset or inhibitor nets).- Parameters:
net- with the graph structureinitialMarking-
-
-
Method Detail
-
getState
public byte[] getState()
- Specified by:
getStatein interfaceEfficientPetrinetSemantics- Returns:
- a copy of the underlying array of tokens in the current state (marking).
-
setState
public void setState(byte[] marking)
Description copied from interface:EfficientPetrinetSemanticsSets the state to the supplied state (marking). The state array is copied into the internal data structure.- Specified by:
setStatein interfaceEfficientPetrinetSemantics
-
directExecuteExecutableTransition
public void directExecuteExecutableTransition(Transition transition)
Description copied from interface:EfficientPetrinetSemanticsExecutes (fires) a transition. For performance reasons, this method does not check whether the transition is actually enabled and does not return information on what changed.- Specified by:
directExecuteExecutableTransitionin interfaceEfficientPetrinetSemantics
-
isEnabled
public boolean isEnabled(Transition transition)
- Specified by:
isEnabledin interfaceEfficientPetrinetSemantics- Returns:
- whether the transition is enabled
-
isEnabled
public boolean isEnabled(int transitionIndex)
- Specified by:
isEnabledin interfaceEfficientPetrinetSemantics
-
isMarked
public boolean isMarked(byte[] marking, Place place)- Specified by:
isMarkedin interfaceEfficientPetrinetSemantics- Parameters:
marking- obtained withEfficientPetrinetSemantics.getState()place- of the net- Returns:
- where place p is marked
-
forEachMarkedPlace
public void forEachMarkedPlace(EfficientPetrinetSemantics.PlaceVisitor placeVisitor)
Description copied from interface:EfficientPetrinetSemanticsVisits each place that is marked with one or more tokens.- Specified by:
forEachMarkedPlacein interfaceEfficientPetrinetSemantics
-
forEachPlace
public void forEachPlace(EfficientPetrinetSemantics.PlaceVisitor placeVisitor)
Description copied from interface:EfficientPetrinetSemanticsVisits each place.- Specified by:
forEachPlacein interfaceEfficientPetrinetSemantics
-
equalMarking
public boolean equalMarking(byte[] marking1, Marking marking2)- Specified by:
equalMarkingin interfaceEfficientPetrinetSemantics- Returns:
- whether marking2 is equal to marking1
-
equalOrLessMarking
public boolean equalOrLessMarking(byte[] marking1, Marking marking2)- Specified by:
equalOrLessMarkingin interfaceEfficientPetrinetSemantics- Returns:
- whether marking2 has equal or less tokens on each place than marking1
-
setCurrentState
public void setCurrentState(Marking marking)
Convenience method of the originalPetrinetSemanticsinterface. Use#setState(int[])instead for a more efficient implementation.- Specified by:
setCurrentStatein interfaceorg.processmining.models.semantics.Semantics<Marking,Transition>
-
getCurrentState
public Marking getCurrentState()
Convenience method of the originalPetrinetSemanticsinterface. UsegetState()instead for a more efficient implementation.- Specified by:
getCurrentStatein interfaceorg.processmining.models.semantics.Semantics<Marking,Transition>
-
getExecutableTransitions
public java.util.Collection<Transition> getExecutableTransitions()
Description copied from interface:EfficientPetrinetSemanticsFor better performance, use methodEfficientPetrinetSemantics.isEnabled(Transition)instead.- Specified by:
getExecutableTransitionsin interfaceEfficientPetrinetSemantics- Specified by:
getExecutableTransitionsin interfaceorg.processmining.models.semantics.Semantics<Marking,Transition>- Returns:
- a collection of all enabled transitions
-
executeExecutableTransition
public org.processmining.models.semantics.ExecutionInformation executeExecutableTransition(Transition transition) throws org.processmining.models.semantics.IllegalTransitionException
For a more efficient implementation usedirectExecuteExecutableTransition(Transition), which does not return any information about the execution.- Specified by:
executeExecutableTransitionin interfaceEfficientPetrinetSemantics- Specified by:
executeExecutableTransitionin interfaceorg.processmining.models.semantics.Semantics<Marking,Transition>- Throws:
org.processmining.models.semantics.IllegalTransitionException
-
initialize
public void initialize(java.util.Collection<Transition> transitions, Marking initialState)
This method cannot be used in this implementation. Please use the normal way to initialize an instance (the constructor).- Specified by:
initializein interfaceorg.processmining.models.semantics.Semantics<Marking,Transition>
-
getStateAsMarking
public Marking getStateAsMarking()
UsegetCurrentState()instead.- Specified by:
getStateAsMarkingin interfaceEfficientPetrinetSemantics- Returns:
- the current state as a
Marking
-
setStateAsMarking
public void setStateAsMarking(Marking marking)
UsesetCurrentState(Marking)instead.- Specified by:
setStateAsMarkingin interfaceEfficientPetrinetSemantics
-
getPlaceMap
public java.util.Map<Place,java.lang.Integer> getPlaceMap()
- Returns:
- a map from
Placeto its index in the marking returned bygetState().
-
getIndex
public int getIndex(Transition t)
- Specified by:
getIndexin interfaceEfficientPetrinetSemantics- Returns:
- the index used (internally) for this transition.
-
getIndex
public int getIndex(Place p)
- Specified by:
getIndexin interfaceEfficientPetrinetSemantics- Returns:
- the index used for this place, corresponds to an index in
EfficientPetrinetSemantics.getState()
-
getMissingTokensToEnable
public byte[] getMissingTokensToEnable(Transition t)
Description copied from interface:EfficientPetrinetSemanticsfigures out whether a certain transition t is missing any tokens to be fired.- Specified by:
getMissingTokensToEnablein interfaceEfficientPetrinetSemantics- Parameters:
t- transition to fire- Returns:
- array of the number of tokens missing for each indexed place to enable t
-
getPlace
public Place getPlace(int index)
- Specified by:
getPlacein interfaceEfficientPetrinetSemantics- Parameters:
index- of the place- Returns:
- the Place object corresponding to the index
-
getTransition
public Transition getTransition(int index)
- Specified by:
getTransitionin interfaceEfficientPetrinetSemantics- Parameters:
index- of the transition- Returns:
- the Transition Object corresponding to the index
-
getMissingTokensToEnable
public byte[] getMissingTokensToEnable(int transitionIndex)
- Specified by:
getMissingTokensToEnablein interfaceEfficientPetrinetSemantics
-
convert
public byte[] convert(Marking marking)
Description copied from interface:EfficientPetrinetSemanticsallows to convert a given marking to an equivalent int array based on the internal index representation of the petri net's places.- Specified by:
convertin interfaceEfficientPetrinetSemantics- Parameters:
marking- of the petri net used wihtin semantics- Returns:
- corresponding int array
-
convert
public Marking convert(byte[] marking)
Description copied from interface:EfficientPetrinetSemanticsconvert a primative int array to a marking object based on the internal index representation of the petri net's places.- Specified by:
convertin interfaceEfficientPetrinetSemantics- Parameters:
marking- to transform (int arr)- Returns:
- fresh marking object
-
-