From 049684d5a040dd11443ebc835f1c7201af7bde5c Mon Sep 17 00:00:00 2001 From: vhavlena Date: Wed, 11 Oct 2023 08:45:44 +0200 Subject: [PATCH 1/3] notebook showing basic visualization possibilities --- .../notebooks/example-04-visualization.ipynb | 1376 +++++++++++++++++ 1 file changed, 1376 insertions(+) create mode 100644 examples/notebooks/example-04-visualization.ipynb diff --git a/examples/notebooks/example-04-visualization.ipynb b/examples/notebooks/example-04-visualization.ipynb new file mode 100644 index 000000000..7470ca893 --- /dev/null +++ b/examples/notebooks/example-04-visualization.ipynb @@ -0,0 +1,1376 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 38, + "id": "ec3e8285-352f-49ab-8f27-040e3684dabd", + "metadata": {}, + "outputs": [], + "source": [ + "import libmata as mata\n", + "from libmata.nfa.nfa import *\n", + "import libmata.plotting\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import networkx as nx\n", + "import graphviz\n", + "import IPython\n", + "from matplotlib.colors import LinearSegmentedColormap" + ] + }, + { + "cell_type": "markdown", + "id": "1c61551c-2385-481a-9344-d687f3c893f7", + "metadata": {}, + "source": [ + "## Auxiliary Functions" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "cfae9f5c-a084-4654-a1a5-dfcdd4d2b54c", + "metadata": { + "jupyter": { + "source_hidden": true + } + }, + "outputs": [], + "source": [ + "def distance_from(aut: Nfa) -> dict[int,int]:\n", + " queue = []\n", + " dist = dict()\n", + " for q in aut.initial_states:\n", + " dist[q] = 0\n", + " queue.append(q)\n", + "\n", + " while len(queue) != 0:\n", + " act = queue.pop(0)\n", + " for trans in aut.get_trans_from_state_as_sequence(act):\n", + " if not trans.target in dist:\n", + " dist[trans.target] = dist[act] + 1\n", + " queue.append(trans.target)\n", + " return dist\n", + "\n", + "def hexa_heat(minimum, maximum, value):\n", + " ratio = 2 * (value-float(minimum)) / float((maximum - minimum))\n", + " b = int(max(0, 255 * (1 - ratio)))\n", + " r = int(max(0, 255 * (ratio - 1)))\n", + " g = 255 - b - r\n", + " return \"#{:02x}{:02x}{:02x}\".format(r, g, b)" + ] + }, + { + "cell_type": "markdown", + "id": "3a10d72c-e5ad-443b-b223-d0f517883e10", + "metadata": {}, + "source": [ + "Creation of example automata" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "7954d84f-386d-480c-bad8-b0f9bb2760d8", + "metadata": {}, + "outputs": [], + "source": [ + "libmata.plotting.store()['alphabet'] = mata.alphabets.OnTheFlyAlphabet.from_symbol_map({\"0\":0, \"1\":1})\n", + "lhs = divisible_by(4)\n", + "lhs.label = \"aut1\"\n", + "rhs = divisible_by(3)\n", + "rhs.label = \"aut2\"\n", + "result = concatenate(lhs, rhs)\n", + "result.label = \"aut1.aut2\"" + ] + }, + { + "cell_type": "markdown", + "id": "1594d6c5-27c9-4b29-a460-b615d3dc6ba6", + "metadata": {}, + "source": [ + "## Conditional State/Transition Formatting" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "77230c54-2aed-4e8b-812a-b1f470316e81", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "dot\n", + "\n", + "aut1\n", + "\n", + "\n", + "q0\n", + "\n", + "\n", + "\n", + "0\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "q0->0\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "0->0\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "1\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "0->1\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "1->1\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "2\n", + "\n", + "2\n", + "\n", + "\n", + "\n", + "1->2\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "2->2\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "3\n", + "\n", + "3\n", + "\n", + "\n", + "\n", + "2->3\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "3->3\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "4\n", + "\n", + "\n", + "4\n", + "\n", + "\n", + "\n", + "3->4\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "4->1\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "4->4\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "dot\n", + "\n", + "aut2\n", + "\n", + "\n", + "q0\n", + "\n", + "\n", + "\n", + "0\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "q0->0\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "0->0\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "1\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "0->1\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "1->1\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "2\n", + "\n", + "2\n", + "\n", + "\n", + "\n", + "1->2\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "2->2\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "3\n", + "\n", + "\n", + "3\n", + "\n", + "\n", + "\n", + "2->3\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "3->1\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "3->3\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "dot\n", + "\n", + "aut1.aut2\n", + "\n", + "\n", + "q0\n", + "\n", + "\n", + "\n", + "0\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "q0->0\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "0->0\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "1\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "0->1\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "1->1\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "2\n", + "\n", + "2\n", + "\n", + "\n", + "\n", + "1->2\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "2->2\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "3\n", + "\n", + "3\n", + "\n", + "\n", + "\n", + "2->3\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "3->3\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "4\n", + "\n", + "4\n", + "\n", + "\n", + "\n", + "3->4\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "4->1\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "4->4\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "5\n", + "\n", + "5\n", + "\n", + "\n", + "\n", + "4->5\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "6\n", + "\n", + "6\n", + "\n", + "\n", + "\n", + "4->6\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "5->5\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "5->6\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "6->6\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "7\n", + "\n", + "7\n", + "\n", + "\n", + "\n", + "6->7\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "7->7\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "8\n", + "\n", + "\n", + "8\n", + "\n", + "\n", + "\n", + "7->8\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "8->6\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "8->8\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "e_h = [\n", + " (lambda aut, edge: edge.symbol == 1, {'color': 'grey'}),\n", + " (lambda aut, edge: edge.symbol == 0, {'style': 'dashed', 'color': 'grey'})\n", + "]\n", + "n_h = [\n", + " (lambda aut, state: state in aut.final_states, {'color': 'red', 'fillcolor': 'red'}),\n", + " (lambda aut, state: state in aut.initial_states, {'color': 'green', 'fillcolor': 'green'}),\n", + "]\n", + "libmata.plotting.plot(lhs, rhs, result, node_highlight=n_h, edge_highlight=e_h)" + ] + }, + { + "cell_type": "markdown", + "id": "dcfcf6e9-6ce5-4378-8743-fbe550813b42", + "metadata": {}, + "source": [ + "## SCC Visualization" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "2f615ee8-e334-46d0-baab-4dbb8cc5de0b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "dot\n", + "\n", + "aut1\n", + "\n", + "cluster_0\n", + "\n", + "\n", + "\n", + "cluster_1\n", + "\n", + "\n", + "\n", + "\n", + "1\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "1->1\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "2\n", + "\n", + "2\n", + "\n", + "\n", + "\n", + "1->2\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "2->2\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "3\n", + "\n", + "3\n", + "\n", + "\n", + "\n", + "2->3\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "3->3\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "4\n", + "\n", + "\n", + "4\n", + "\n", + "\n", + "\n", + "3->4\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "4->1\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "4->4\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "q0\n", + "\n", + "\n", + "\n", + "0\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "q0->0\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "0->1\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "0->0\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "dot\n", + "\n", + "aut2\n", + "\n", + "cluster_0\n", + "\n", + "\n", + "\n", + "cluster_1\n", + "\n", + "\n", + "\n", + "\n", + "1\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "1->1\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "2\n", + "\n", + "2\n", + "\n", + "\n", + "\n", + "1->2\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "2->2\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "3\n", + "\n", + "\n", + "3\n", + "\n", + "\n", + "\n", + "2->3\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "3->1\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "3->3\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "q0\n", + "\n", + "\n", + "\n", + "0\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "q0->0\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "0->1\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "0->0\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "dot\n", + "\n", + "aut1.aut2\n", + "\n", + "cluster_0\n", + "\n", + "\n", + "\n", + "cluster_1\n", + "\n", + "\n", + "\n", + "cluster_2\n", + "\n", + "\n", + "\n", + "cluster_3\n", + "\n", + "\n", + "\n", + "\n", + "8\n", + "\n", + "\n", + "8\n", + "\n", + "\n", + "\n", + "8->8\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "6\n", + "\n", + "6\n", + "\n", + "\n", + "\n", + "8->6\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "6->6\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "7\n", + "\n", + "7\n", + "\n", + "\n", + "\n", + "6->7\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "7->8\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "7->7\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "5\n", + "\n", + "5\n", + "\n", + "\n", + "\n", + "5->6\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "5->5\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "1\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "1->1\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "2\n", + "\n", + "2\n", + "\n", + "\n", + "\n", + "1->2\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "2->2\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "3\n", + "\n", + "3\n", + "\n", + "\n", + "\n", + "2->3\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "3->3\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "4\n", + "\n", + "4\n", + "\n", + "\n", + "\n", + "3->4\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "4->6\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "4->5\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "4->1\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "4->4\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "q0\n", + "\n", + "\n", + "\n", + "0\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "q0->0\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "0->1\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "0->0\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "e_h = [\n", + " (lambda aut, edge: edge.symbol == 1, {'color': 'grey'}),\n", + " (lambda aut, edge: edge.symbol == 0, {'style': 'dashed', 'color': 'grey'})\n", + "]\n", + "n_h = [\n", + " (lambda aut, state: state in aut.final_states, {'color': 'red', 'fillcolor': 'red'}),\n", + " (lambda aut, state: state in aut.initial_states, {'color': 'green', 'fillcolor': 'green'}),\n", + "]\n", + "libmata.plotting.plot(lhs, rhs, result, with_scc=True, node_highlight=n_h, edge_highlight=e_h)" + ] + }, + { + "cell_type": "markdown", + "id": "dccb8027-97a8-4e0d-b02b-19238d8648b1", + "metadata": {}, + "source": [ + "## Example of a Heatmap" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "07df7d90-13f4-41c5-8bf9-ea4cea33c333", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "dot\n", + "\n", + "aut1.aut2\n", + "\n", + "\n", + "q0\n", + "\n", + "\n", + "\n", + "0\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "q0->0\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "0->0\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "1\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "0->1\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "1->1\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "2\n", + "\n", + "2\n", + "\n", + "\n", + "\n", + "1->2\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "2->2\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "3\n", + "\n", + "3\n", + "\n", + "\n", + "\n", + "2->3\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "3->3\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "4\n", + "\n", + "4\n", + "\n", + "\n", + "\n", + "3->4\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "4->1\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "4->4\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "5\n", + "\n", + "5\n", + "\n", + "\n", + "\n", + "4->5\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "6\n", + "\n", + "6\n", + "\n", + "\n", + "\n", + "4->6\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "5->5\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "5->6\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "6->6\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "7\n", + "\n", + "7\n", + "\n", + "\n", + "\n", + "6->7\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "7->7\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "8\n", + "\n", + "\n", + "8\n", + "\n", + "\n", + "\n", + "7->8\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "8->6\n", + "\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "8->8\n", + "\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "heat_map = distance_from(result)\n", + "max_heat = max(heat_map.values())\n", + "e_h = [\n", + " (lambda aut, edge: edge.symbol == 1, {'color': 'gray'}),\n", + " (lambda aut, edge: edge.source == edge.target, {'style': 'dashed', 'color': 'red'})\n", + "]\n", + "n_h = [\n", + " (lambda aut, state, j=i: state == j, libmata.plotting.Style.filled(hexa_heat(0, max_heat, heat_map[i]))) for i in range(0,result.num_of_states())\n", + "]\n", + "libmata.plotting.plot(result, node_highlight=n_h, edge_highlight=e_h)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 4eee12095d0a51a32c071f0ca01d8bd0c643c901 Mon Sep 17 00:00:00 2001 From: vhavlena Date: Wed, 11 Oct 2023 15:16:34 +0200 Subject: [PATCH 2/3] visualisation: aut from regex --- .../notebooks/example-04-visualization.ipynb | 215 +++++++++++++++++- 1 file changed, 209 insertions(+), 6 deletions(-) diff --git a/examples/notebooks/example-04-visualization.ipynb b/examples/notebooks/example-04-visualization.ipynb index 7470ca893..fe0a4d77d 100644 --- a/examples/notebooks/example-04-visualization.ipynb +++ b/examples/notebooks/example-04-visualization.ipynb @@ -9,13 +9,13 @@ "source": [ "import libmata as mata\n", "from libmata.nfa.nfa import *\n", + "from libmata.parser import *\n", "import libmata.plotting\n", "\n", - "import matplotlib.pyplot as plt\n", - "import networkx as nx\n", - "import graphviz\n", - "import IPython\n", - "from matplotlib.colors import LinearSegmentedColormap" + "# import matplotlib.pyplot as plt\n", + "#import networkx as nx\n", + "#import graphviz\n", + "#import IPython" ] }, { @@ -1102,7 +1102,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 43, "id": "07df7d90-13f4-41c5-8bf9-ea4cea33c333", "metadata": {}, "outputs": [ @@ -1350,6 +1350,209 @@ "]\n", "libmata.plotting.plot(result, node_highlight=n_h, edge_highlight=e_h)" ] + }, + { + "cell_type": "markdown", + "id": "22a0477d-b02c-4c02-8629-bb415e8e685e", + "metadata": {}, + "source": [ + "## Regex Example" + ] + }, + { + "cell_type": "markdown", + "id": "b1710914-765b-418b-aa8b-27ae3b1f140d", + "metadata": {}, + "source": [ + "Setting a correct alphabet" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "f6d84372-0dd4-4646-b331-00fc80e43f86", + "metadata": {}, + "outputs": [], + "source": [ + "libmata.plotting.store()['alphabet'] = mata.alphabets.OnTheFlyAlphabet.from_symbol_map({\"a\":97, \"b\":98})" + ] + }, + { + "cell_type": "markdown", + "id": "d571e4e3-7685-4ac3-aba0-5b413a88efa4", + "metadata": {}, + "source": [ + "Plot the automaton" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "3a6ababe-3d20-4ebd-8f0d-b9fe44786f7c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "dot\n", + "\n", + "\n", + "cluster_0\n", + "\n", + "\n", + "\n", + "cluster_1\n", + "\n", + "\n", + "\n", + "cluster_2\n", + "\n", + "\n", + "\n", + "\n", + "4\n", + "\n", + "\n", + "4\n", + "\n", + "\n", + "\n", + "4->4\n", + "\n", + "\n", + "b\n", + "\n", + "\n", + "\n", + "3\n", + "\n", + "3\n", + "\n", + "\n", + "\n", + "3->4\n", + "\n", + "\n", + "a\n", + "\n", + "\n", + "\n", + "q0\n", + "\n", + "\n", + "\n", + "0\n", + "\n", + "0\n", + "\n", + "\n", + "\n", + "q0->0\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "0->3\n", + "\n", + "\n", + "a\n", + "\n", + "\n", + "\n", + "0->0\n", + "\n", + "\n", + "a\n", + "\n", + "\n", + "\n", + "1\n", + "\n", + "1\n", + "\n", + "\n", + "\n", + "0->1\n", + "\n", + "\n", + "a\n", + "\n", + "\n", + "\n", + "1->1\n", + "\n", + "\n", + "a\n", + "\n", + "\n", + "\n", + "2\n", + "\n", + "2\n", + "\n", + "\n", + "\n", + "1->2\n", + "\n", + "\n", + "b\n", + "\n", + "\n", + "\n", + "2->0\n", + "\n", + "\n", + "a\n", + "\n", + "\n", + "\n", + "2->1\n", + "\n", + "\n", + "a\n", + "\n", + "\n", + "\n", + "
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "reg_aut = from_regex(\"((a+b)*a)*aab*\")\n", + "e_h = [\n", + " (lambda aut, edge: edge.symbol == 98, {'color': 'black'}),\n", + " (lambda aut, edge: edge.symbol == 97, {'style': 'dashed', 'color': 'black'})\n", + "]\n", + "n_h = [\n", + " (lambda aut, state: state in aut.final_states, {'color': 'red', 'fillcolor': 'red'}),\n", + " (lambda aut, state: state in aut.initial_states, {'color': 'orange', 'fillcolor': 'orange'}),\n", + "]\n", + "libmata.plotting.plot(reg_aut, with_scc=True, node_highlight=n_h, edge_highlight=e_h)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7b9c56d6-578b-4375-b92b-b39077b86b91", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { From c721e11362e86585ca9ba4b197099895521a3273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Chocholat=C3=BD?= Date: Sat, 14 Oct 2023 12:51:22 +0200 Subject: [PATCH 3/3] Remove commented out code --- examples/notebooks/example-04-visualization.ipynb | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/examples/notebooks/example-04-visualization.ipynb b/examples/notebooks/example-04-visualization.ipynb index fe0a4d77d..4b95d14f3 100644 --- a/examples/notebooks/example-04-visualization.ipynb +++ b/examples/notebooks/example-04-visualization.ipynb @@ -10,12 +10,7 @@ "import libmata as mata\n", "from libmata.nfa.nfa import *\n", "from libmata.parser import *\n", - "import libmata.plotting\n", - "\n", - "# import matplotlib.pyplot as plt\n", - "#import networkx as nx\n", - "#import graphviz\n", - "#import IPython" + "import libmata.plotting" ] }, { @@ -1545,14 +1540,6 @@ "]\n", "libmata.plotting.plot(reg_aut, with_scc=True, node_highlight=n_h, edge_highlight=e_h)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7b9c56d6-578b-4375-b92b-b39077b86b91", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": {