{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Édition, visualisation d'automates\n", " http://vaucanson-project.org/Awali/1.0/index.html ." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "scrolled": true }, "outputs": [ { "data": { "application/javascript": [ "IPython.notebook.set_autosave_interval(0)" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Autosave disabled\n" ] } ], "source": [ "# We disable autosave for technical reasons.\n", "# Replace 0 by 120 in next line to restore default.\n", "%autosave 0" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[Warning] The python module awalipy relies on compilation executed \"on-the-fly\" depending on the context (type of weights, of labels, etc.). As a result, the very first call to a given function in a given context may take up to 10 seconds. \n" ] } ], "source": [ "import awalipy # If import fails, check that \n", " # Python version used as Jupyter\n", " # kernel matches the one\n", " # Awalipy was compiled with." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "(The above warning is displayed every time awalipy is imported.)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Créer un automate" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Les alphabets sont des `str` Python\n", "- chaque `char` de `str` est une lettre de l'alpahbet\n", "- l'ordre n'a pas d'importance (`\"abc\"` et `\"bac\"` représentent le même alphabet)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "alph1 = \"abc\" # represents {a,b,c}\n", "alph2 = \"01\" # represents {0,1}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Un **automate** peut être construit à partir d'un alphabet" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "A = awalipy.Automaton(alph1)\n", "# ou directment `awalipy.Automaton(\"abc\")`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`A` est un automate sans états ni transitions sur l'alphabet {a,b,c}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Ajout d'états\n", "\n", "par défaut le nom affiché de l'état est donné par son indice : le premier état est nommé `\"s0\"`, le second `\"s1\"`, etc." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "stt_0 = A.add_state()\n", "stt_1 = A.add_state()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Ajout de transitions" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "tr_0 = A.set_transition(stt_0,stt_1,'a')\n", "tr_1 = A.set_transition(stt_1,stt_0,'b')\n", "tr_2 = A.set_transition(stt_0,stt_0,'b')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "