{ "cells": [ { "cell_type": "markdown", "id": "0009d44f-be72-4bb2-9ca6-487a2be24ce1", "metadata": { "tags": [] }, "source": [ "# Generate pm4py log using ASP Generator\n", "\n", "ASP log generator uses the decl model which converts the model into abudction logic programming and pass to the clingo.\n", "Clingo generates the output which is turned into the pm4py log or can be created a .xes file.\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "1eb21bf2-bf41-46b2-96e3-806047cc8cb1", "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Python 3.11.4\r\n" ] } ], "source": [ "!python3 --version" ] }, { "cell_type": "code", "execution_count": 2, "id": "2938753f-7b7c-4095-b918-1a667621e50d", "metadata": { "tags": [] }, "outputs": [], "source": [ "import os\n", "import pathlib\n", "\n", "from Declare4Py.ProcessMiningTasks.ASPLogGeneration.asp_generator import AspGenerator\n", "from Declare4Py.ProcessModels.DeclareModel import DeclareModel" ] }, { "cell_type": "code", "execution_count": 3, "id": "0b9d5123-dc4f-4a75-bdd1-d4235d636772", "metadata": { "tags": [] }, "outputs": [], "source": [ "decl_model_1 = \"decl_files/Response.decl\"\n", "decl_model_2 = \"decl_files/MikeModel.decl\"\n", "decl_model_3 = \"decl_files/reference10.decl\"\n", "decl_model_4 = \"diagonisis.decl\"\n", "decl_folder = \"decl_files\"\n", "\n", "decl_filename = decl_model_4.split(\".\")[0]\n", "output_file = pathlib.Path(\".\", f\"{decl_filename}.xes\")\n", "decl_file = pathlib.Path(\".\", decl_folder, decl_model_4)" ] }, { "cell_type": "code", "execution_count": 4, "id": "4b2d84b6-6a5a-4b3c-a0bb-335981eb6374", "metadata": {}, "outputs": [], "source": [ "# Create Declare model by reading declare model from a file.\n", "\n", "model: DeclareModel = DeclareModel().parse_from_file(decl_file)" ] }, { "cell_type": "code", "execution_count": 5, "id": "f4b87ba4-2740-4006-b40f-b0ae95bab202", "metadata": {}, "outputs": [], "source": [ "#general Setting\n", "\n", "# Number of traces that should be generated\n", "num_of_traces = 20\n", "\n", "# Minimum and maximum number of events a trace can contain\n", "(num_min_events, num_max_events) = (2, 5)\n" ] }, { "cell_type": "code", "execution_count": 6, "id": "b9dc4474-319b-40e0-95a7-c8ac36a18f2b", "metadata": {}, "outputs": [], "source": [ "# Initializing ASP generator with default distributor which is uniform.\n", "\n", "asp = AspGenerator(\n", " model,\n", " num_of_traces,\n", " num_min_events,\n", " num_max_events\n", ")" ] }, { "cell_type": "code", "execution_count": 7, "id": "fd662d2d", "metadata": {}, "outputs": [], "source": [ "asp.set_number_of_repetition_per_trace(8) # same trace but with possible different events" ] }, { "cell_type": "code", "execution_count": 8, "id": "974a92ad-6497-433f-99e4-2f0d79a6e150", "metadata": { "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "PM4PY log generated: 160/160 only.\n" ] } ], "source": [ "# Generate the traces and parse the result produced by clingo\n", "asp.run() # Run accets 1 optional value whether to create file for the ASP generated from given declare model\n" ] }, { "cell_type": "code", "execution_count": 9, "id": "a03b7b40-e718-4783-a8e4-36528bd4d01d", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c71e8fd708924f0cb2fe747fb982ce6e", "version_major": 2, "version_minor": 0 }, "text/plain": [ "exporting log, completed traces :: 0%| | 0/160 [00:00