pm4py.algo.conformance.alignments.dcr.variants package#
Submodules#
pm4py.algo.conformance.alignments.dcr.variants.optimal module#
This module contains the object-oriented implementation of the Optimal Alignments algorithm, based on the paper by Axel Kjeld Fjelrad Christfort and Tijs Slaats [1].
Overview: The implementation encapsulates the core components of the algorithm and provides.
The calculation of the alignments and graph-trace handling are encapsulated in separate, dedicated classes, thereby facilitating modularity and reuse. Central to the module are the following classes:
LogAlignment: A simplified interface to perform optimal alignment through the other classes.
TraceAlignment: Serves as the primary interface for interacting with the algorithm. orchestrating the alignment process and providing access to performance metrics.
TraceHandler: Manages the conversion and handling of event traces, preparing them for alignment.
DCRGraphHandler: Encapsulates operations and checks on DCR graphs relevant for the alignment.
Alignment: Implements the actual algorithm, managing the search space, and constructing optimal alignments.
The module’s classes interact to process an input DCR graph and a trace abd execute the alignment algorithm. This process helps in understanding how closely the behavior described by the trace matches the behavior allowed by the DCR graph, which is essential in the analysis and optimization of business processes.
References#
- class pm4py.algo.conformance.alignments.dcr.variants.optimal.LogAlignment(log: EventLog | DataFrame, parameters: Dict | None = None)[source]#
Bases:
object
The LogAlignment provides the simplified interface to perform optimal alignment for DCR graphs, with a provided event log. Calls TraceAlignment for each trace to compute optimal alignment for each trace.
After intilializing Log alignment, can call perform_log_alignment() to execute the alignment process for all traces in log which returns a list of result for each alignment procedure
Example usage:
Define your instances of DCR graph and trace representation as ‘graph’ and ‘trace’
align_log = LogAlignment(log, parameters)
alignment_result = align_log.perform_log_alignment(graph, parameters)
Note: - The user is expected to have a basic understanding of DCR graphs and trace alignment in the context of process mining.
- Attributes:
traces (list[Tuple]): the list of traces as tuples. Trace_alignments (list[Alignments]): Instance that holds the result of the alignment processes, initialized as an empty list [].
- Methods:
perform_log_alignment(graph, parameters): Performs trace alignment for a log against the DCR graph and returns the list of alignment results.
- perform_log_alignment(graph: DcrGraph, parameters: Dict | None = None)[source]#
Processes an event log and applies a specific operation to each trace.
This method iterates through all traces in the log, and performs alignment operations, and store it in a list
- Parameters:
graph (DcrGraph): the event log used for aligning the traces parameters (Optional[Dict]): A dictionary of parameters that control the behavior of the trace processing.
This can include custom activity and case ID keys, among others.
- Returns:
List[Dict]: a list of dictionaries containing info on alignment and move fitness
- class pm4py.algo.conformance.alignments.dcr.variants.optimal.TraceAlignment(graph: DcrGraph, trace: List[Tuple[str]] | DataFrame | EventLog | Trace, parameters: Dict | None = None)[source]#
Bases:
object
The TraceAlignment class provides a simplified interface to perform optimal alignment for DCR graphs, abstracting the complexity of direct interactions with the DCRGraphHandler, TraceHandler, and Alignment classes.
Users should initialize TraceAlignment with a DCR_Graph object and a trace object, which can be a list of events, a Pandas DataFrame, an EventLog, or a Trace. Optional parameters can also be passed to customize the processing, such as specifying custom activity and case ID keys.
After initializing TraceAlignment, users can call perform_alignment() to execute the alignment process, which returns the result of the alignment procedure.
- Example usage:
Define your instances of DCR graph and trace representation as ‘graph’ and ‘trace’ facade = Facade(graph, trace) alignment_result = facade.perform_alignment()
Note: - The user is expected to have a basic understanding of DCR graphs and trace alignment in the context of process mining.
- Attributes:
graph_handler (DCRGraphHandler): Handler for DCR graph operations. trace_handler (TraceHandler): Handler for trace operations. alignment (Alignment): Instance that holds the result of the alignment process, initialized to None.
- Methods:
perform_alignment(): Performs trace alignment against the DCR graph and returns the alignment result. get_performance_metrics(): Calculates and returns the alignment fitness.
- class pm4py.algo.conformance.alignments.dcr.variants.optimal.Parameters(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
Enum
Enumeration that defines keys and constants for various parameters used in the alignment process.
- Attributes:
CASE_ID_KEY: The key used to identify the case ID in the event log. ACTIVITY_KEY: The key used to identify the activity in the event log. SYNC_COST: The cost of a synchronous move during the alignment. MODEL_COST: The cost of a model move during the alignment. LOG_COST: The cost of a log move during the alignment.
- CASE_ID_KEY = 'pm4py:param:case_id_key'#
- ACTIVITY_KEY = 'pm4py:param:activity_key'#
- SYNC_COST = 0#
- MODEL_COST = 1#
- LOG_COST = 1#
- class pm4py.algo.conformance.alignments.dcr.variants.optimal.Outputs(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
Enum
Enumeration that defines constants for various outputs of the alignment process.
- Attributes:
ALIGNMENT: The key for accessing the final alignment from the result. COST: The key for accessing the total cost of the alignment. VISITED: The key for accessing the number of visited states during the alignment process. CLOSED: The key for accessing the number of closed states during the alignment process. GLOBAL_MIN: The key for accessing the global minimum cost encountered during the alignment. MODEL_MOVE_FITNESS = the key for accessing the model move fitness LOG_MOVE_FITNESS = the key for accessing the log move fitness ALIGN_FITNESS = the key for accessing the alignment fitness
- ALIGNMENT = 'alignment'#
- COST = 'cost'#
- VISITED = 'visited_states'#
- CLOSED = 'closed'#
- GLOBAL_MIN = 'global_min'#
- ALIGN_FITNESS = 'fitness'#
- BEST_WORST_COST = 'bwc'#
- class pm4py.algo.conformance.alignments.dcr.variants.optimal.Performance(alignment, graph_handler, trace_handler)[source]#
Bases:
object
- calculate_fitness() Tuple [source]#
From the Conformance Checking book [1]. Calculate the fitness of the alignment based on the optimal and worst-case costs.
The fitness is calculated as one minus the ratio of the optimal alignment cost to the worst-case alignment cost. If the worst-case alignment cost is zero, fitness is set to zero to avoid division by zero.
Returns#
- float
The calculated fitness value, where higher values indicate a better fit.
References#
[1] C. Josep et al., “Conformance Checking Software”, Springer International Publishing, 82-91, 2018. DOI.
- class pm4py.algo.conformance.alignments.dcr.variants.optimal.TraceHandler(trace: Tuple[str] | Trace, parameters: Dict | None = None)[source]#
Bases:
object
TraceHandler is responsible for managing and converting traces into a format suitable for the alignment algorithm. This class provides functionalities to check if the trace is empty, retrieve the first activity from the trace, and convert the trace format as needed.
A trace can be provided as a list of dictionaries, a pandas DataFrame, an EventLog, or a Trace object. The TraceHandler takes care of converting these into a uniform internal representation.
Attributes#
- traceTuple[Any] | Trace
The trace to be managed and converted. It’s stored internally in a list of dictionaries regardless of the input format.
- activity_keystr
The key to identify activities within the trace data.
Methods#
- is_empty() -> bool:
Checks if the trace is empty (contains no events).
- get_first_activity() -> Any:
Retrieves the first activity from the trace, if available.
- convert_trace(activity_key, case_id_key, parameters):
Converts the trace into a tuple-based format required for processing by the alignment algorithm. This conversion handles both DataFrame and Event Log traces and can be configured via parameters.
Parameters#
- traceTuple[str] | Trace
The initial trace data provided in one of the acceptable formats.
- parametersOptional[Dict]
Optional parameters for trace conversion. These can define the keys for activity and case ID within the trace data and can include other conversion-related parameters.
- class pm4py.algo.conformance.alignments.dcr.variants.optimal.DCRGraphHandler(graph: DcrGraph)[source]#
Bases:
object
DCRGraphHandler manages operations on a DCR graph within the context of an alignment algorithm. It provides methods to check if an event is enabled, if the graph is in an accepting state, and to execute an event on the graph.
The DCR graph follows the semantics defined in the DCR semantics module, and this class acts as an interface to apply these semantics for the purpose of alignment computation.
Attributes#
- graphDcrGraph
The DCR graph on which the operations are to be performed.
Methods#
- is_enabled(event: Any) -> bool:
Determines if an event is enabled in the current state of the DCR graph.
- is_accepting() -> bool:
Checks if the current state of the DCR graph is an accepting state.
- execute(event: Any, curr_graph) -> Any:
Executes an event on the DCR graph, which may result in a transition to a new state. If the execution is not possible, it returns the current graph state.
Parameters#
- graphDcrGraph
An instance of a DCR_Graph object which the handler will manage and manipulate.
Raises#
- TypeError
If the provided graph is not an instance of DCR_Graph.
- class pm4py.algo.conformance.alignments.dcr.variants.optimal.Alignment(graph_handler: DCRGraphHandler, trace_handler: TraceHandler, parameters: Dict | None = None)[source]#
Bases:
object
- handle_state(curr_cost, curr_graph, curr_trace, event, moves, move_type=None)[source]#
Manages the transition to a new state in the alignment algorithm based on the specified move type. It computes the new state, checks for execution equivalency to avoid re-processing, and if unique, updates the visited states and the priority queue for further processing.
Parameters#
- curr_costint
The current cost of the alignment.
- curr_graphDcrGraph
The current state of the DCR graph.
- curr_tracelist
The current state of the trace.
- eventAny
The event from the trace that is being considered in the current alignment step.
- moveslist
The list of moves made so far.
- move_typestr, optional
The type of move to make. This should be one of “sync”, “model”, or “log”. Default is None.
Returns#
None
Raises#
None
Notes#
This method interfaces with the get_new_state method to compute the new state.
It employs a heap-based priority queue to manage the processing order of states based on their costs.
Execution equivalency check is performed to reduce redundant processing of similar states.
- get_new_state(curr_cost, curr_marking, curr_trace, event, move_type)[source]#
Computes the new state of the alignment algorithm based on the current state and the specified move type. The new state includes the updated cost, graph, trace, and move. This method handles three types of moves: synchronous, model, and log.
Parameters#
- curr_costint
The current cost of the alignment.
- curr_graphDcrGraph
The current state of the DCR graph.
- curr_tracelist
The current state of the trace.
- moveslist
The list of moves made so far.
- move_typestr
The type of move to make. This should be one of “sync”, “model”, or “log”.
Returns#
- tuple
A tuple containing four elements: - new_cost : int, the updated cost of the alignment. - new_graph : DCR_Graph, the updated state of the DCR graph. - new_trace : list, the updated state of the trace. - new_move : tuple, a tuple representing the move made, formatted as (move_type, first_activity).
Example#
new_cost, new_graph, new_trace, new_move = get_new_state(curr_cost, curr_graph, curr_trace, moves, “sync”)
- process_current_state(current)[source]#
Process the current state in the alignment process. This method processes the current state of the alignment, updates the graph handler with the current graph, and prepares the state representation for further processing.
Parameters#
- currentTuple
The current state, which is a tuple containing the current cost, current graph, current trace, and the moves made up to this point.
- check_accepting_conditions(curr_cost, is_accepting)[source]#
Check if the current state meets the accepting conditions and update the global minimum cost and final alignment.
Parameters#
- curr_costfloat
The cost associated with the current state.
- is_acceptingbool
Flag indicating whether the current state is an accepting state.
Returns#
- float
The final cost if the accepting conditions are met; float(‘inf’) otherwise.
- apply_trace(parameters=None)[source]#
Applies the alignment algorithm to a trace in order to find an optimal alignment between the DCR graph and the trace based on the algorithm outlined in the paper by Axel Kjeld Fjelrad Christfort and Tijs Slaats.
Parameters#
- parametersdict, optional
A dictionary of parameters to configure the alignment algorithm. Possible keys include: - Parameters.ACTIVITY_KEY: Specifies the key to use for activity names in the trace data. - Parameters.CASE_ID_KEY: Specifies the key to use for case IDs in the trace data. If not provided or None, default values are used.
Returns#
- dict
A dictionary containing the results of the alignment algorithm, with the following keys: - ‘alignment’: List of tuples representing the optimal alignment found. - ‘cost’: The cost of the optimal alignment. - ‘visited’: The number of states visited during the alignment algorithm. - ‘closed’: The number of closed states during the alignment algorithm. - ‘global_min’: The global minimum cost found during the alignment algorithm.
Example#
result = alignment_obj.apply_trace() optimal_alignment = result[‘alignment’] alignment_cost = result[‘cost’]
- perform_moves(curr_cost, current, moves)[source]#
Defines available moves based on the trace and model state.
This method determines which moves are possible (synchronous, model, or log moves) so that they can be processed accordingly. Each move type is defined as: - Synchronous (sync): The activity is both in the trace and the model, and is currently enabled. - Model move: The activity is enabled in the model but not in the trace. - Log move: The activity is in the trace but not enabled in the model.
Parameters#
- curr_costfloat
The cost associated with the current state before performing any moves.
- currenttuple
The current state represented as a tuple containing the following: - current[0]: The current cumulative cost associated with the trace. - current[1]: The current state of the graph representing the model. - current[2]: The current position in the trace. - current[3]: A placeholder for additional information (if any). - current[4]: The list of moves performed to reach this state.
- moveslist
The list of moves performed so far to reach the current state. This will be updated with new moves as they are performed.
- construct_results(visited, closed, final_cost)[source]#
Constructs a dictionary of results from the alignment process containing various metrics and outcomes, such as the final alignment, its cost, and statistics about the search process.
Parameters#
- visitedint
The number of states visited during the alignment process.
- closedint
The number of states that were closed (i.e., fully processed and will not be revisited).
- final_costfloat
The cost associated with the final alignment obtained.
Returns#
- dict
A dictionary with keys corresponding to various outputs of the alignment process: - ‘alignment’: The final alignment between the process model and the trace. - ‘cost’: The cost of the final alignment . - ‘visited’: The total number of visited states. - ‘closed’: The total number of closed states. - ‘model move fitness’: the fitness provided that model moves are used - ‘log move fitness’: the fitness provided by the log moves
- pm4py.algo.conformance.alignments.dcr.variants.optimal.apply(trace_or_log: DataFrame | EventLog | Trace, graph: DcrGraph, parameters=None)[source]#
Applies an alignment operation on a given trace or log against a specified DCR graph.
Depending on the type of input, this function handles the alignment of a single trace or multiple traces contained in an event log. For a single trace, it creates an instance of TraceAlignment and performs the alignment. For an event log, it initializes a LogAlignment object and aligns each trace contained within.
- Parameters:
trace_or_log (Union[pd.DataFrame, EventLog, Trace]): The event log or single trace to align. graph (DcrGraph): The DCR graph against which the alignment is to be performed. parameters (Optional[Dict]): A dictionary of parameters for the alignment (default is None).
- Returns:
If a single trace is provided, returns the result of the TraceAlignment.
If an event log is provided, returns a list of results from LogAlignment for each trace.
- pm4py.algo.conformance.alignments.dcr.variants.optimal.get_diagnostics_dataframe(log: EventLog, conf_result: List[Dict[str, Any]], parameters=None) DataFrame [source]#
Gets the diagnostics dataframe from a log and the conformance results
Parameters#
- log
Event log
- conf_result
Results of conformance checking
- variant
Variant to be used: - Variants.CLASSIC
- parameters
Variant-specific parameters
Returns#
- diagn_dataframe
Diagnostics dataframe
pm4py.algo.conformance.alignments.dcr.variants.optimal_multithreaded module#
This module contains the object-oriented implementation of the Optimal Alignments algorithm, based on the paper by Axel Kjeld Fjelrad Christfort and Tijs Slaats [1].
Overview: The implementation encapsulates the core components of the algorithm and provides.
The calculation of the alignments and graph-trace handling are encapsulated in separate, dedicated classes, thereby facilitating modularity and reuse. Central to the module are the following classes:
LogAlignment: A simplified interface to perform optimal alignment through the other classes.
TraceAlignment: Serves as the primary interface for interacting with the algorithm. orchestrating the alignment process and providing access to performance metrics.
TraceHandler: Manages the conversion and handling of event traces, preparing them for alignment.
DCRGraphHandler: Encapsulates operations and checks on DCR graphs relevant for the alignment.
Alignment: Implements the actual algorithm, managing the search space, and constructing optimal alignments.
The module’s classes interact to process an input DCR graph and a trace abd execute the alignment algorithm. This process helps in understanding how closely the behavior described by the trace matches the behavior allowed by the DCR graph, which is essential in the analysis and optimization of business processes.
This version of the module includes multithreading capabilities to improve performance when processing large logs.
References#
A. K. F. Christfort, T. Slaats, “Efficient Optimal Alignment Between Dynamic Condition Response Graphs and Traces”, in Business Process Management, Springer International Publishing, 2023, pp. 3-19. DOI <https://doi.org/10.1007/978-3-031-41620-0_1>_.
- class pm4py.algo.conformance.alignments.dcr.variants.optimal_multithreaded.LogAlignment(traces: EventLog, parameters: Dict[str, Any] = None)[source]#
Bases:
object
LogAlignment class provides a multithreaded interface to perform optimal alignment for multiple traces in an event log.
This class manages the parallel processing of traces, distributing the workload across multiple CPU cores to improve performance when dealing with large event logs.
- Attributes:
parameters (Dict[str, Any]): Configuration parameters for the alignment process. cpu_count (int): The number of CPU cores available on the system. max_workers (int): The maximum number of worker processes to use for parallel processing. chunk_size (int): The number of traces to process in each chunk. traces (EventLog): The event log containing the traces to be aligned.
- Methods:
- perform_log_alignment(graph: DcrGraph, parameters: Dict[str, Any] = None) -> List[Dict[str, Any]]:
Performs the alignment process for all traces in the log using multiple worker processes.
- process_chunk(graph: DcrGraph, traces: List[Trace], parameters: Dict[str, Any]) -> List[Dict[str, Any]]:
Static method to process a chunk of traces, used by worker processes.
- perform_log_alignment(graph: DcrGraph, parameters: Dict[str, Any] = None) List[Dict[str, Any]] [source]#
Performs the alignment process for all traces in the log using multiple worker processes.
This method divides the traces into chunks and distributes them among worker processes for parallel processing. It then collects and combines the results from all workers.
- Parameters:
graph (DcrGraph): The DCR graph against which the traces will be aligned. parameters (Dict[str, Any], optional): Additional parameters for the alignment process.
- Returns:
List[Dict[str, Any]]: A list of alignment results for all processed traces.
- static process_chunk(graph: DcrGraph, traces: List[Trace], parameters: Dict[str, Any]) List[Dict[str, Any]] [source]#
Static method to process a chunk of traces.
This method is designed to be run in a separate process, aligning each trace in the given chunk against the provided DCR graph.
- Parameters:
graph (DcrGraph): The DCR graph against which the traces will be aligned. traces (List[Trace]): A list of traces to be processed. parameters (Dict[str, Any]): Parameters for the alignment process.
- Returns:
List[Dict[str, Any]]: A list of alignment results for the processed traces.
- class pm4py.algo.conformance.alignments.dcr.variants.optimal_multithreaded.TraceAlignment(graph: DcrGraph, trace: List[Tuple[str]] | DataFrame | EventLog | Trace, parameters: Dict | None = None)[source]#
Bases:
object
The TraceAlignment class provides a simplified interface to perform optimal alignment for DCR graphs, abstracting the complexity of direct interactions with the DCRGraphHandler, TraceHandler, and Alignment classes.
Users should initialize TraceAlignment with a DCR_Graph object and a trace object, which can be a list of events, a Pandas DataFrame, an EventLog, or a Trace. Optional parameters can also be passed to customize the processing, such as specifying custom activity and case ID keys.
After initializing TraceAlignment, users can call perform_alignment() to execute the alignment process, which returns the result of the alignment procedure.
- Example usage:
Define your instances of DCR graph and trace representation as ‘graph’ and ‘trace’ facade = Facade(graph, trace) alignment_result = facade.perform_alignment()
Note: - The user is expected to have a basic understanding of DCR graphs and trace alignment in the context of process mining.
- Attributes:
graph_handler (DCRGraphHandler): Handler for DCR graph operations. trace_handler (TraceHandler): Handler for trace operations. alignment (Alignment): Instance that holds the result of the alignment process, initialized to None.
- Methods:
perform_alignment(): Performs trace alignment against the DCR graph and returns the alignment result. get_performance_metrics(): Calculates and returns the alignment fitness.
- class pm4py.algo.conformance.alignments.dcr.variants.optimal_multithreaded.Parameters(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
Enum
Enumeration that defines keys and constants for various parameters used in the alignment process.
- Attributes:
CASE_ID_KEY: The key used to identify the case ID in the event log. ACTIVITY_KEY: The key used to identify the activity in the event log. SYNC_COST: The cost of a synchronous move during the alignment. MODEL_COST: The cost of a model move during the alignment. LOG_COST: The cost of a log move during the alignment.
- CASE_ID_KEY = 'pm4py:param:case_id_key'#
- ACTIVITY_KEY = 'pm4py:param:activity_key'#
- SYNC_COST = 0#
- MODEL_COST = 1#
- LOG_COST = 1#
- class pm4py.algo.conformance.alignments.dcr.variants.optimal_multithreaded.Outputs(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
Enum
Enumeration that defines constants for various outputs of the alignment process.
- Attributes:
ALIGNMENT: The key for accessing the final alignment from the result. COST: The key for accessing the total cost of the alignment. VISITED: The key for accessing the number of visited states during the alignment process. CLOSED: The key for accessing the number of closed states during the alignment process. GLOBAL_MIN: The key for accessing the global minimum cost encountered during the alignment. MODEL_MOVE_FITNESS = the key for accessing the model move fitness LOG_MOVE_FITNESS = the key for accessing the log move fitness ALIGN_FITNESS = the key for accessing the alignment fitness
- ALIGNMENT = 'alignment'#
- COST = 'cost'#
- VISITED = 'visited_states'#
- CLOSED = 'closed'#
- GLOBAL_MIN = 'global_min'#
- ALIGN_FITNESS = 'fitness'#
- BEST_WORST_COST = 'bwc'#
- class pm4py.algo.conformance.alignments.dcr.variants.optimal_multithreaded.Performance(alignment, graph_handler, trace_handler)[source]#
Bases:
object
- calculate_fitness() Tuple [source]#
From the Conformance Checking book [1]. Calculate the fitness of the alignment based on the optimal and worst-case costs.
The fitness is calculated as one minus the ratio of the optimal alignment cost to the worst-case alignment cost. If the worst-case alignment cost is zero, fitness is set to zero to avoid division by zero.
Returns#
- float
The calculated fitness value, where higher values indicate a better fit.
References#
[1] C. Josep et al., “Conformance Checking Software”, Springer International Publishing, 82-91, 2018. DOI.
- class pm4py.algo.conformance.alignments.dcr.variants.optimal_multithreaded.TraceHandler(trace: Tuple[str] | Trace, parameters: Dict | None = None)[source]#
Bases:
object
TraceHandler is responsible for managing and converting traces into a format suitable for the alignment algorithm. This class provides functionalities to check if the trace is empty, retrieve the first activity from the trace, and convert the trace format as needed.
A trace can be provided as a list of dictionaries, a pandas DataFrame, an EventLog, or a Trace object. The TraceHandler takes care of converting these into a uniform internal representation.
Attributes#
- traceTuple[Any] | Trace
The trace to be managed and converted. It’s stored internally in a list of dictionaries regardless of the input format.
- activity_keystr
The key to identify activities within the trace data.
Methods#
- is_empty() -> bool:
Checks if the trace is empty (contains no events).
- get_first_activity() -> Any:
Retrieves the first activity from the trace, if available.
- convert_trace(activity_key, case_id_key, parameters):
Converts the trace into a tuple-based format required for processing by the alignment algorithm. This conversion handles both DataFrame and Event Log traces and can be configured via parameters.
Parameters#
- traceTuple[str] | Trace
The initial trace data provided in one of the acceptable formats.
- parametersOptional[Dict]
Optional parameters for trace conversion. These can define the keys for activity and case ID within the trace data and can include other conversion-related parameters.
- class pm4py.algo.conformance.alignments.dcr.variants.optimal_multithreaded.DCRGraphHandler(graph: DcrGraph)[source]#
Bases:
object
DCRGraphHandler manages operations on a DCR graph within the context of an alignment algorithm. It provides methods to check if an event is enabled, if the graph is in an accepting state, and to execute an event on the graph.
The DCR graph follows the semantics defined in the DCR semantics module, and this class acts as an interface to apply these semantics for the purpose of alignment computation.
Attributes#
- graphDcrGraph
The DCR graph on which the operations are to be performed.
Methods#
- is_enabled(event: Any) -> bool:
Determines if an event is enabled in the current state of the DCR graph.
- is_accepting() -> bool:
Checks if the current state of the DCR graph is an accepting state.
- execute(event: Any, curr_graph) -> Any:
Executes an event on the DCR graph, which may result in a transition to a new state. If the execution is not possible, it returns the current graph state.
Parameters#
- graphDcrGraph
An instance of a DCR_Graph object which the handler will manage and manipulate.
Raises#
- TypeError
If the provided graph is not an instance of DCR_Graph.
- class pm4py.algo.conformance.alignments.dcr.variants.optimal_multithreaded.Alignment(graph_handler: DCRGraphHandler, trace_handler: TraceHandler, parameters: Dict | None = None)[source]#
Bases:
object
- handle_state(curr_cost, curr_graph, curr_trace, event, moves, move_type=None)[source]#
Manages the transition to a new state in the alignment algorithm based on the specified move type. It computes the new state, checks for execution equivalency to avoid re-processing, and if unique, updates the visited states and the priority queue for further processing.
Parameters#
- curr_costint
The current cost of the alignment.
- curr_graphDcrGraph
The current state of the DCR graph.
- curr_tracelist
The current state of the trace.
- eventAny
The event from the trace that is being considered in the current alignment step.
- moveslist
The list of moves made so far.
- move_typestr, optional
The type of move to make. This should be one of “sync”, “model”, or “log”. Default is None.
Returns#
None
Raises#
None
Notes#
This method interfaces with the get_new_state method to compute the new state.
It employs a heap-based priority queue to manage the processing order of states based on their costs.
Execution equivalency check is performed to reduce redundant processing of similar states.
- get_new_state(curr_cost, curr_marking, curr_trace, event, move_type)[source]#
Computes the new state of the alignment algorithm based on the current state and the specified move type. The new state includes the updated cost, graph, trace, and move. This method handles three types of moves: synchronous, model, and log.
Parameters#
- curr_costint
The current cost of the alignment.
- curr_graphDcrGraph
The current state of the DCR graph.
- curr_tracelist
The current state of the trace.
- moveslist
The list of moves made so far.
- move_typestr
The type of move to make. This should be one of “sync”, “model”, or “log”.
Returns#
- tuple
A tuple containing four elements: - new_cost : int, the updated cost of the alignment. - new_graph : DCR_Graph, the updated state of the DCR graph. - new_trace : list, the updated state of the trace. - new_move : tuple, a tuple representing the move made, formatted as (move_type, first_activity).
Example#
new_cost, new_graph, new_trace, new_move = get_new_state(curr_cost, curr_graph, curr_trace, moves, “sync”)
- process_current_state(current)[source]#
Process the current state in the alignment process. This method processes the current state of the alignment, updates the graph handler with the current graph, and prepares the state representation for further processing.
Parameters#
- currentTuple
The current state, which is a tuple containing the current cost, current graph, current trace, and the moves made up to this point.
- check_accepting_conditions(curr_cost, is_accepting)[source]#
Check if the current state meets the accepting conditions and update the global minimum cost and final alignment.
Parameters#
- curr_costfloat
The cost associated with the current state.
- is_acceptingbool
Flag indicating whether the current state is an accepting state.
Returns#
- float
The final cost if the accepting conditions are met; float(‘inf’) otherwise.
- apply_trace(parameters=None)[source]#
Applies the alignment algorithm to a trace in order to find an optimal alignment between the DCR graph and the trace based on the algorithm outlined in the paper by Axel Kjeld Fjelrad Christfort and Tijs Slaats. https://link.springer.com/chapter/10.1007/978-3-031-41620-0_1
Parameters#
- parametersdict, optional
A dictionary of parameters to configure the alignment algorithm. Possible keys include: - Parameters.ACTIVITY_KEY: Specifies the key to use for activity names in the trace data. - Parameters.CASE_ID_KEY: Specifies the key to use for case IDs in the trace data. If not provided or None, default values are used.
Returns#
- dict
A dictionary containing the results of the alignment algorithm, with the following keys: - ‘alignment’: List of tuples representing the optimal alignment found. - ‘cost’: The cost of the optimal alignment. - ‘visited’: The number of states visited during the alignment algorithm. - ‘closed’: The number of closed states during the alignment algorithm. - ‘global_min’: The global minimum cost found during the alignment algorithm.
Example#
result = alignment_obj.apply_trace() optimal_alignment = result[‘alignment’] alignment_cost = result[‘cost’]
- perform_moves(curr_cost, current, moves)[source]#
Defines available moves based on the trace and model state.
This method determines which moves are possible (synchronous, model, or log moves) so that they can be processed accordingly. Each move type is defined as: - Synchronous (sync): The activity is both in the trace and the model, and is currently enabled. - Model move: The activity is enabled in the model but not in the trace. - Log move: The activity is in the trace but not enabled in the model.
Parameters#
- curr_costfloat
The cost associated with the current state before performing any moves.
- currenttuple
The current state represented as a tuple containing the following: - current[0]: The current cumulative cost associated with the trace. - current[1]: The current state of the graph representing the model. - current[2]: The current position in the trace. - current[3]: A placeholder for additional information (if any). - current[4]: The list of moves performed to reach this state.
- moveslist
The list of moves performed so far to reach the current state. This will be updated with new moves as they are performed.
- construct_results(visited, closed, final_cost)[source]#
Constructs a dictionary of results from the alignment process containing various metrics and outcomes, such as the final alignment, its cost, and statistics about the search process.
Parameters#
- visitedint
The number of states visited during the alignment process.
- closedint
The number of states that were closed (i.e., fully processed and will not be revisited).
- final_costfloat
The cost associated with the final alignment obtained.
Returns#
- dict
A dictionary with keys corresponding to various outputs of the alignment process: - ‘alignment’: The final alignment between the process model and the trace. - ‘cost’: The cost of the final alignment . - ‘visited’: The total number of visited states. - ‘closed’: The total number of closed states. - ‘model move fitness’: the fitness provided that model moves are used - ‘log move fitness’: the fitness provided by the log moves
- pm4py.algo.conformance.alignments.dcr.variants.optimal_multithreaded.apply(trace_or_log: DataFrame | EventLog | Trace, graph: DcrGraph, parameters=None)[source]#
Applies the alignment algorithm to either a single trace or an entire event log.
This function serves as the main entry point for the alignment process. It determines whether to use the single-trace alignment or the multi-threaded log alignment based on the input type and size.
- Parameters:
trace_or_log (Union[pd.DataFrame, EventLog, Trace]): The input trace or log to be aligned. graph (DcrGraph): The DCR graph against which the alignment will be performed. parameters (dict, optional): Additional parameters for the alignment process.
- Returns:
Union[List[Dict[str, Any]], Dict[str, Any]]: The alignment results. For a single trace, it returns a dictionary. For a log, it returns a list of dictionaries.
- pm4py.algo.conformance.alignments.dcr.variants.optimal_multithreaded.apply_original(log: EventLog, graph: DcrGraph, parameters=None)[source]#
Applies the alignment algorithm to an event log without using multithreading. This function is used for smaller logs (less than 100 traces).
Parameters:#
- logEventLog
The event log to be aligned.
- graphDcrGraph
The DCR graph against which the alignment will be performed.
- parametersdict, optional
Additional parameters for the alignment process.
Returns:#
- List[Dict[str, Any]]
A list of dictionaries, each containing the alignment results for a single trace.
- pm4py.algo.conformance.alignments.dcr.variants.optimal_multithreaded.apply_multithreaded(trace_or_log: DataFrame | EventLog | Trace, graph: DcrGraph, parameters=None)[source]#
Applies the multithreaded alignment algorithm to either a single trace or an entire event log.
This function is similar to ‘apply’, but it always uses the multithreaded approach for log alignment, regardless of the log size. It’s useful when processing large logs or when maximum performance is required.
- Parameters:
trace_or_log (Union[pd.DataFrame, EventLog, Trace]): The input trace or log to be aligned. graph (DcrGraph): The DCR graph against which the alignment will be performed. parameters (dict, optional): Additional parameters for the alignment process.
- Returns:
Union[List[Dict[str, Any]], Dict[str, Any]]: The alignment results. For a single trace, it returns a dictionary. For a log, it returns a list of dictionaries.
- pm4py.algo.conformance.alignments.dcr.variants.optimal_multithreaded.get_diagnostics_dataframe(log: EventLog, conf_result: List[Dict[str, Any]], parameters=None) DataFrame [source]#
Gets the diagnostics dataframe from a log and the conformance results
Parameters#
- log
Event log
- conf_result
Results of conformance checking
- variant
Variant to be used: - Variants.CLASSIC
- parameters
Variant-specific parameters
Returns#
- diagn_dataframe
Diagnostics dataframe