Skip to main content

Build the n-gram index of a BPMN/Petri net process model to compute the state of an ongoing case in constant time.

Project description

Efficient State Computation of Process Ongoing Cases

build version

Approach to, given a process model in Petri net or BPMN format, compute the state of ongoing cases in constant time. The approach consists of, in design time, given a maximum size n, create an index that associates each n-gram -- i.e., execution of n consecutive activities -- with the state(s) they lead to in the process model. Then, at runtime, the state of an ongoing process case can be computed in constant time by searching for the last n executed activities in the index. For example, for an ongoing case A-B-F-T-W-S-G-T-D, after building the 5-gram index, the state would be computed by searching in the index with the sequence [W, S, G, T, D].

This approach has been submitted as a publication to IEEE Transactions on Services Computing under the title "Efficient Online Computation of Business Process State From Trace Prefixes via N-Gram Indexing", by David Chapela-Campa and Marlon Dumas.

Installation

Package available in PyPI: https://pypi.org/project/ongoing-process-state/. Install it with:

pip install ongoing-process-state

Requirements

  • Python v3.9.5+
  • PIP v23.0+
  • Python dependencies: all packages listed in pyproject.toml

Basic Usage

Given a process model in BPMN or Petri net format, first compute the reachability graph and build an n-gram index. Then, given an instance of an N-gram index, compute the state given an n-gram prefix.

BPMN model

from pathlib import Path

from ongoing_process_state.n_gram_index import NGramIndex
from ongoing_process_state.utils import read_bpmn_model

# Read BPMN model
bpmn_model_path = Path("./inputs/synthetic/synthetic_and_k5.bpmn")
bpmn_model = read_bpmn_model(bpmn_model_path)
# Compute reachability graph
reachability_graph = bpmn_model.get_reachability_graph()
# Build n-gram index
n_gram_index = NGramIndex(reachability_graph, n_gram_size_limit=5)
n_gram_index.build()

Petri net

from pathlib import Path

from ongoing_process_state.n_gram_index import NGramIndex
from ongoing_process_state.utils import read_petri_net

# Read BPMN model
petri_net_path = Path("./inputs/synthetic/synthetic_and_k5.bpmn")
petri_net = read_petri_net(petri_net_path)
# Compute reachability graph
reachability_graph = petri_net.get_reachability_graph()
# Build n-gram index
n_gram_index = NGramIndex(reachability_graph, n_gram_size_limit=5)
n_gram_index.build()

Compute ongoing state

from ongoing_process_state.n_gram_index import NGramIndex

# Compute the state of an ongoing case
n_gram = ["B", "E", "F", "C", "G"]
ongoing_state = n_gram_index.get_best_marking_state_for(n_gram)
# Compute the state of an ongoing case with less than N recorded events
n_gram = [NGramIndex.TRACE_START, "A", "B", "F"]
ongoing_state = n_gram_index.get_best_marking_state_for(n_gram)

Storing

The following code can be used to store/load the reachability graph in/from a file:

from pathlib import Path

from ongoing_process_state.reachability_graph import ReachabilityGraph

# Store reachability graph for future re-use
reachability_graph_path = Path("./outputs/synthetic_and_k5.tgf")
with open(reachability_graph_path, 'w') as output_file:
    output_file.write(reachability_graph.to_tgf_format())
# Load reachability graph from file
with open(reachability_graph_path, 'r') as reachability_graph_file:
    reachability_graph = ReachabilityGraph.from_tgf_format(reachability_graph_file.read())

We recommend to store the n-gram index in an indexed database, as the size of the map may be too big to comfortably work with it through files. However, we provide a simple functionality to store/load an n-gram index in/from a file.

from pathlib import Path

from ongoing_process_state.n_gram_index import NGramIndex

# Store n-gram index for future re-use
n_gram_index_path = Path("./outputs/synthetic_and_k5.txt")
n_gram_index.to_self_contained_map_file(n_gram_index_path)
# Lead n-gram index from file
n_gram_index = NGramIndex.from_self_contained_map_file(n_gram_index_path, reachability_graph)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ongoing_process_state-2.1.1.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ongoing_process_state-2.1.1-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

Details for the file ongoing_process_state-2.1.1.tar.gz.

File metadata

  • Download URL: ongoing_process_state-2.1.1.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ongoing_process_state-2.1.1.tar.gz
Algorithm Hash digest
SHA256 e84510024690d800cf078f4981736c7928b1e48ecca637829819af3cecd6edd4
MD5 d67a50d454db986f42e774aaae74db05
BLAKE2b-256 ade1c17d22ff0028502b1f3942e311b01662a6c20bc8aa6689b8849a2fcc13f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for ongoing_process_state-2.1.1.tar.gz:

Publisher: build.yaml on AutomatedProcessImprovement/ongoing-process-state

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ongoing_process_state-2.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ongoing_process_state-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 673521e8cd8c68c1da17428e3c17fcc3593b16c6cd88a73d600419d935000a8c
MD5 4cf7eb5c35f8d472e6f7cd72380c3319
BLAKE2b-256 9dd6b0a9c064ae72e9c7d70f091eff18a8dca2329669d321d21ae99de2ff5a3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ongoing_process_state-2.1.1-py3-none-any.whl:

Publisher: build.yaml on AutomatedProcessImprovement/ongoing-process-state

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page