Skip to content

Commit

Permalink
Merge branch 'release' of https://github.com/pm4py/pm4py-core into gi…
Browse files Browse the repository at this point in the history
…thub-release
  • Loading branch information
fit-sebastiaan-van-zelst committed May 12, 2022
2 parents bf88107 + 0c1eb9e commit 4d85c2c
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 5 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ RUN apt-get -y install g++ libboost-all-dev libncurses5-dev wget
RUN apt-get -y install libtool flex bison pkg-config g++ libssl-dev automake
RUN apt-get -y install libjemalloc-dev libboost-dev libboost-filesystem-dev libboost-system-dev libboost-regex-dev python3-dev autoconf flex bison cmake
RUN apt-get -y install libxml2-dev libxslt-dev libfreetype6-dev libsuitesparse-dev
RUN pip install -U cvxopt
RUN pip install -U wheel six pytest
RUN pip install asttokens==2.0.5 backcall==0.2.0 colorama==0.4.4 cycler==0.11.0 decorator==5.1.1 deprecation==2.1.0 executing==0.8.3 fonttools==4.32.0 graphviz==0.19.2 intervaltree==3.1.0 ipython==8.2.0 jedi==0.18.1 jinja2==3.1.1 jsonpickle==2.1.0 kiwisolver==1.4.2 lxml==4.8.0 MarkupSafe==2.1.1 matplotlib==3.5.1 matplotlib-inline==0.1.3 mpmath==1.2.1 networkx==2.8 numpy==1.22.3 packaging==21.3 pandas==1.4.2 parso==0.8.3 pickleshare==0.7.5 pillow==9.1.0 prompt-toolkit==3.0.29 pure-eval==0.2.2 pydotplus==2.0.2 pygments==2.11.2 pyparsing==3.0.8 python-dateutil==2.8.2 pytz==2022.1 pyvis==0.1.9 scipy==1.8.0 setuptools==62.0.0 six==1.16.0 sortedcontainers==2.4.0 stack-data==0.2.0 stringdist==1.0.9 sympy==1.10.1 tqdm==4.64.0 traitlets==5.1.1 wcwidth==0.2.5

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pm4py.view_petri_net(pnet, initial_marking, final_marking, format="svg")
```

## Installation
pm4py can be installed on Python 3.7.x / 3.8.x / 3.9.x by doing:
pm4py can be installed on Python 3.7.x / 3.8.x / 3.9.x / 3.10.x by doing:
```bash
pip install -U pm4py
```
Expand Down
20 changes: 17 additions & 3 deletions pm4py/algo/simulation/playout/petri_net/variants/basic_playout.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ class Parameters(Enum):
NO_TRACES = "noTraces"
MAX_TRACE_LENGTH = "maxTraceLength"
PETRI_SEMANTICS = "petri_semantics"
INITIAL_TIMESTAMP = "initial_timestamp"
INITIAL_CASE_ID = "initial_case_id"


def apply_playout(net, initial_marking, no_traces=100, max_trace_length=100,
initial_timestamp=10000000, initial_case_id=0,
case_id_key=xes_constants.DEFAULT_TRACEID_KEY,
activity_key=xes_constants.DEFAULT_NAME_KEY, timestamp_key=xes_constants.DEFAULT_TIMESTAMP_KEY,
final_marking=None, return_visited_elements=False, semantics=petri_net.semantics.ClassicSemantics()):
Expand All @@ -56,6 +59,10 @@ def apply_playout(net, initial_marking, no_traces=100, max_trace_length=100,
Number of traces to generate
max_trace_length
Maximum number of events per trace (do break)
initial_timestamp
Increased timestamp from 1970 for the first event
initial_case_id
Case id of the first event
case_id_key
Trace attribute that is the case ID
activity_key
Expand All @@ -68,7 +75,7 @@ def apply_playout(net, initial_marking, no_traces=100, max_trace_length=100,
Semantics of the Petri net to be used (default: petri_net.semantics.ClassicSemantics())
"""
# assigns to each event an increased timestamp from 1970
curr_timestamp = 10000000
curr_timestamp = initial_timestamp
all_visited_elements = []

for i in range(no_traces):
Expand Down Expand Up @@ -104,7 +111,7 @@ def apply_playout(net, initial_marking, no_traces=100, max_trace_length=100,

for index, visited_elements in enumerate(all_visited_elements):
trace = log_instance.Trace()
trace.attributes[case_id_key] = str(index)
trace.attributes[case_id_key] = str(index+initial_case_id)
for element in visited_elements:
if type(element) is PetriNet.Transition and element.label is not None:
event = log_instance.Event()
Expand Down Expand Up @@ -135,6 +142,8 @@ def apply(net: PetriNet, initial_marking: Marking, final_marking: Marking = None
Parameters of the algorithm:
Parameters.NO_TRACES -> Number of traces of the log to generate
Parameters.MAX_TRACE_LENGTH -> Maximum trace length
Parameters.INITIAL_TIMESTAMP -> The first event is set with INITIAL_TIMESTAMP increased from 1970
Parameters.INITIAL_CASE_ID -> Numeric case id for the first trace
Parameters.PETRI_SEMANTICS -> Petri net semantics to be used (default: petri_nets.semantics.ClassicSemantics())
"""
if parameters is None:
Expand All @@ -145,10 +154,15 @@ def apply(net: PetriNet, initial_marking: Marking, final_marking: Marking = None
xes_constants.DEFAULT_TIMESTAMP_KEY)
no_traces = exec_utils.get_param_value(Parameters.NO_TRACES, parameters, 1000)
max_trace_length = exec_utils.get_param_value(Parameters.MAX_TRACE_LENGTH, parameters, 1000)
initial_timestamp = exec_utils.get_param_value(Parameters.INITIAL_TIMESTAMP, parameters, 10000000)
initial_case_id = exec_utils.get_param_value(Parameters.INITIAL_CASE_ID, parameters, 0)
return_visited_elements = exec_utils.get_param_value(Parameters.RETURN_VISITED_ELEMENTS, parameters, False)
semantics = exec_utils.get_param_value(Parameters.PETRI_SEMANTICS, parameters, petri_net.semantics.ClassicSemantics())

return apply_playout(net, initial_marking, max_trace_length=max_trace_length, no_traces=no_traces,
return apply_playout(net, initial_marking, max_trace_length=max_trace_length,
initial_timestamp=initial_timestamp,
initial_case_id=initial_case_id,
no_traces=no_traces,
case_id_key=case_id_key, activity_key=activity_key, timestamp_key=timestamp_key,
final_marking=final_marking, return_visited_elements=return_visited_elements,
semantics=semantics)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ pyvis
scipy
stringdist
sympy
tqdm
tqdm
2 changes: 2 additions & 0 deletions tests/execute_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from tests.simplified_interface import SimplifiedInterfaceTest
from tests.ocel_filtering_test import OcelFilteringTest
from tests.ocel_discovery_test import OcelDiscoveryTest
from tests.simulation_test import SimulationTest

ocel_filtering_test = OcelFilteringTest()
ocel_discovery_test = OcelDiscoveryTest()
Expand Down Expand Up @@ -74,5 +75,6 @@
woflan_test = WoflanTest()
diagn_dataframe_test = DiagnDfConfChecking()
simplified_test = SimplifiedInterfaceTest()
simulation_test = SimulationTest()

unittest.main()
46 changes: 46 additions & 0 deletions tests/simulation_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
import unittest

from pm4py.objects.petri_net.importer import importer as pnml_importer
from pm4py.algo.simulation.playout.petri_net import algorithm as simulator
from tests.constants import INPUT_DATA_DIR
from datetime import datetime


class SimulationTest(unittest.TestCase):
def test_simulate_petrinet(self):
net, im, fm = pnml_importer.apply(
os.path.join(INPUT_DATA_DIR, "running-example.pnml"))
number_of_traces = 10
eventlog = simulator.apply(net, im, fm, variant=simulator.Variants.BASIC_PLAYOUT,
parameters={
simulator.Variants.BASIC_PLAYOUT.value.Parameters.NO_TRACES: number_of_traces})
self.assertEqual(len(eventlog), number_of_traces)
case_id_default = 0
last_case_id = case_id_default + number_of_traces - 1
timestamp_default = 10000000
self.assertEqual(eventlog[0].attributes['concept:name'], str(case_id_default))
self.assertEqual(datetime.timestamp(eventlog[0][0]['time:timestamp']), timestamp_default)
self.assertEqual(eventlog[-1].attributes['concept:name'], str(last_case_id))

def test_simulate_petrinet_start_params(self):
net, im, fm = pnml_importer.apply(
os.path.join(INPUT_DATA_DIR, "running-example.pnml"))
number_of_traces = 10
timestamp = 50000000
case_id = 5
eventlog = simulator.apply(net, im, fm, variant=simulator.Variants.BASIC_PLAYOUT,
parameters={
simulator.Variants.BASIC_PLAYOUT.value.Parameters.NO_TRACES: number_of_traces,
simulator.Variants.BASIC_PLAYOUT.value.Parameters.INITIAL_TIMESTAMP:
timestamp,
simulator.Variants.BASIC_PLAYOUT.value.Parameters.INITIAL_CASE_ID: case_id})
self.assertEqual(len(eventlog), number_of_traces)
last_case_id = case_id + number_of_traces - 1
self.assertEqual(eventlog[0].attributes['concept:name'], str(case_id))
self.assertEqual(datetime.timestamp(eventlog[0][0]['time:timestamp']), timestamp)
self.assertEqual(eventlog[-1].attributes['concept:name'], str(last_case_id))


if __name__ == "__main__":
unittest.main()

0 comments on commit 4d85c2c

Please sign in to comment.