def transform_event_log_to_trace_log( log, case_glue=log_util.CASE_ATTRIBUTE_GLUE, includes_case_attributes=True, case_attribute_prefix=log_util.CASE_ATTRIBUTE_PREFIX): """ Converts the event log to a trace log Parameters ---------- log: :class:`pm4py.log.log.EventLog` An event Log case_glue: Case identifier. Default is 'case:concept:name' includes_case_attributes: Default is True case_attribute_prefix: Default is 'case:' Returns ------- log : :class:`pm4py.log.log.TraceLog` A trace log """ traces = {} for event in log: glue = event[case_glue] if glue not in traces: trace_attr = {} if includes_case_attributes: for k in event.keys(): if k.startswith(case_attribute_prefix): trace_attr[k.replace(case_attribute_prefix, '')] = event[k] traces[glue] = log_instance.Trace(attributes=trace_attr) if includes_case_attributes: for k in list(event.keys()): if k.startswith(case_attribute_prefix): del event[k] traces[glue].append(event) return log_instance.TraceLog(traces.values(), attributes=log.attributes, classifiers=log.classifiers, omni_present=log.omni_present, extensions=log.extensions)
def apply_playout(net, initial_marking, no_traces=100, max_trace_length=100): """ Do the playout of a Petrinet generating a log Parameters ---------- net Petri net to play-out initial_marking Initial marking of the Petri net no_traces Number of traces to generate max_trace_length Maximum number of events per trace (do break) """ log = log_instance.TraceLog() for i in range(no_traces): trace = log_instance.Trace() trace.attributes["concept:name"] = str(i) marking = copy(initial_marking) for j in range(100000): if not semantics.enabled_transitions(net, marking): break all_enabled_trans = semantics.enabled_transitions(net, marking) all_enabled_trans = list(all_enabled_trans) shuffle(all_enabled_trans) trans = all_enabled_trans[0] if trans.label is not None: event = log_instance.Event() event["concept:name"] = trans.label trace.append(event) marking = semantics.execute(trans, net, marking) if len(trace) > max_trace_length: break if len(trace) > 0: log.append(trace) return log