DFG

Process Discovery using Directly-Follows Graphs

Process models modeled using Petri nets have a well-defined semantic: a process execution starts from the places included in the initial marking and finishes at the places included in the final marking. In this section, another class of process models, Directly-Follows Graphs, are introduced. Directly-Follows graphs are graphs where the nodes represent the events/activities in the log and directed edges are present between nodes if there is at least a trace in the log where the source event/activity is followed by the target event/activity. On top of these directed edges, it is easy to represent metrics like frequency (counting the number of times the source event/activity is followed by the target event/activity) and performance (some aggregation, for example, the mean, of time inter-lapsed between the two events/activities).

We extract a Directly-Follows graph from the log running-example.xes.

To read the running-example.xes log, the following Python code could be used:

import os
from pm4py.objects.log.importer.xes import factory as xes_importer

log = xes_importer.import_log(os.path.join("tests","input_data","running-example.xes"))

Then, the following code could be used to extract a Directly-Follows graph from the log:

from pm4py.algo.discovery.dfg import factory as dfg_factory

dfg = dfg_factory.apply(log)

A colored visualization of the Directly-Follows graph decorated with the frequency of activities and edges can be then obtained by using the following code:

from pm4py.visualization.dfg import factory as dfg_vis_factory

gviz = dfg_vis_factory.apply(dfg, log=log, variant="frequency")
dfg_vis_factory.view(gviz)

To get a Directly-Follows graph decorated with the performance between the edges, the following code can replace the previous two pieces of code. The specification of performance should be included in both the Directly-Follows application and the visualization part:

from pm4py.algo.discovery.dfg import factory as dfg_factory
from pm4py.visualization.dfg import factory as dfg_vis_factory

dfg = dfg_factory.apply(log, variant="performance")
gviz = dfg_vis_factory.apply(dfg, log=log, variant="performance")
dfg_vis_factory.view(gviz)

To save the DFG decorated with frequency or performance, instead of displaying it on screen, in svg format, the following code could be used:

from pm4py.algo.discovery.dfg import factory as dfg_factory
from pm4py.visualization.dfg import factory as dfg_vis_factory

dfg = dfg_factory.apply(log, variant="performance")
parameters = {"format":"svg"}
gviz = dfg_vis_factory.apply(dfg, log=log, variant="performance", parameters=parameters)
dfg_vis_factory.save(gviz, "dfg.svg")