{ "metadata": { "kernelspec": { "display_name": "Python 3", "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.4.3+" }, "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "import spot\n", "spot.setup()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "a = spot.translate('a U b U c')" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `#` option of `print_dot()` can be used to display the internal number of each transition " ] }, { "cell_type": "code", "collapsed": false, "input": [ "a.show('.#')" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 3, "svg": [ "\n", "\n", "G\n", "\n", "\n", "\n", "2\n", "\n", "2\n", "\n", "\n", "I->2\n", "\n", "\n", "\n", "\n", "2->2\n", "\n", "\n", "a & !c\n", "#6\n", "\n", "\n", "0\n", "\n", "\n", "0\n", "\n", "\n", "2->0\n", "\n", "\n", "c\n", "#4\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "2->1\n", "\n", "\n", "!a & b & !c\n", "#5\n", "\n", "\n", "0->0\n", "\n", "\n", "1\n", "#1\n", "\n", "\n", "1->0\n", "\n", "\n", "c\n", "#2\n", "\n", "\n", "1->1\n", "\n", "\n", "b & !c\n", "#3\n", "\n", "\n", "" ], "text": [ "" ] } ], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using these numbers you can selectively hightlight some transitions. The second argument is a color number (from a list of predefined colors)." ] }, { "cell_type": "code", "collapsed": false, "input": [ "a.highlight_edges([2, 4, 5], 1)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 4, "svg": [ "\n", "\n", "\n", "\n", "\n", "\n", "G\n", "\n", "\n", "\n", "2\n", "\n", "2\n", "\n", "\n", "I->2\n", "\n", "\n", "\n", "\n", "2->2\n", "\n", "\n", "a & !c\n", "\n", "\n", "0\n", "\n", "\n", "0\n", "\n", "\n", "2->0\n", "\n", "\n", "c\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "2->1\n", "\n", "\n", "!a & b & !c\n", "\n", "\n", "0->0\n", "\n", "\n", "1\n", "\n", "\n", "1->0\n", "\n", "\n", "c\n", "\n", "\n", "1->1\n", "\n", "\n", "b & !c\n", "\n", "\n", "\n" ], "text": [ " *' at 0x7fd034659540> >" ] } ], "prompt_number": 4 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that these `highlight_` functions work for edges and states, and come with both singular (changing the color of single state or edge) and plural versions.\n", "\n", "They modify the automaton in place." ] }, { "cell_type": "code", "collapsed": false, "input": [ "a.highlight_edge(6, 2).highlight_states((0, 1), 0)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 5, "svg": [ "\n", "\n", "\n", "\n", "\n", "\n", "G\n", "\n", "\n", "\n", "2\n", "\n", "2\n", "\n", "\n", "I->2\n", "\n", "\n", "\n", "\n", "2->2\n", "\n", "\n", "a & !c\n", "\n", "\n", "0\n", "\n", "\n", "0\n", "\n", "\n", "2->0\n", "\n", "\n", "c\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "2->1\n", "\n", "\n", "!a & b & !c\n", "\n", "\n", "0->0\n", "\n", "\n", "1\n", "\n", "\n", "1->0\n", "\n", "\n", "c\n", "\n", "\n", "1->1\n", "\n", "\n", "b & !c\n", "\n", "\n", "\n" ], "text": [ " *' at 0x7fd034190180> >" ] } ], "prompt_number": 5 }, { "cell_type": "markdown", "metadata": {}, "source": [ "One use of this highlighting is to highlight a run in an automaton.\n", "\n", "The following few command generate an automaton, then an accepting run on this automaton, and highlight that accepting run on the automaton. Note that a run knows the automaton from which it was generated, so calling `highlight()` will directly decorate that automaton." ] }, { "cell_type": "code", "collapsed": false, "input": [ "b = spot.translate('X (F(Ga <-> b) & GF!b)'); b" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 6, "svg": [ "\n", "\n", "\n", "\n", "\n", "\n", "G\n", "\n", "\n", "\n", "0\n", "\n", "0\n", "\n", "\n", "I->0\n", "\n", "\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "0->1\n", "\n", "\n", "1\n", "\n", "\n", "1->1\n", "\n", "\n", "a | b\n", "\n", "\n", "2\n", "\n", "2\n", "\n", "\n", "1->2\n", "\n", "\n", "!a & !b\n", "\n", "\n", "3\n", "\n", "3\n", "\n", "\n", "1->3\n", "\n", "\n", "a & b\n", "\n", "\n", "4\n", "\n", "4\n", "\n", "\n", "1->4\n", "\n", "\n", "a & !b\n", "\n", "\n", "2->2\n", "\n", "\n", "b\n", "\n", "\n", "2->2\n", "\n", "\n", "!b\n", "\u24ff\n", "\n", "\n", "3->3\n", "\n", "\n", "a & b\n", "\n", "\n", "3->3\n", "\n", "\n", "a & !b\n", "\u24ff\n", "\n", "\n", "4->2\n", "\n", "\n", "!a & b\n", "\n", "\n", "4->4\n", "\n", "\n", "a & b\n", "\n", "\n", "\n" ], "text": [ " *' at 0x7fd034190240> >" ] } ], "prompt_number": 6 }, { "cell_type": "code", "collapsed": false, "input": [ "r = spot.couvreur99(b).check().accepting_run(); r" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 7, "text": [ "Prefix:\n", " 0\n", " | 1\n", " 1\n", " | !a & !b\n", "Cycle:\n", " 2\n", " | !b\t{0}" ] } ], "prompt_number": 7 }, { "cell_type": "code", "collapsed": false, "input": [ "r.highlight(5) # the parameter is a color number" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 8 }, { "cell_type": "code", "collapsed": false, "input": [ "b" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 9, "svg": [ "\n", "\n", "\n", "\n", "\n", "\n", "G\n", "\n", "\n", "\n", "0\n", "\n", "0\n", "\n", "\n", "I->0\n", "\n", "\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "0->1\n", "\n", "\n", "1\n", "\n", "\n", "1->1\n", "\n", "\n", "a | b\n", "\n", "\n", "2\n", "\n", "2\n", "\n", "\n", "1->2\n", "\n", "\n", "!a & !b\n", "\n", "\n", "3\n", "\n", "3\n", "\n", "\n", "1->3\n", "\n", "\n", "a & b\n", "\n", "\n", "4\n", "\n", "4\n", "\n", "\n", "1->4\n", "\n", "\n", "a & !b\n", "\n", "\n", "2->2\n", "\n", "\n", "b\n", "\n", "\n", "2->2\n", "\n", "\n", "!b\n", "\u24ff\n", "\n", "\n", "3->3\n", "\n", "\n", "a & b\n", "\n", "\n", "3->3\n", "\n", "\n", "a & !b\n", "\u24ff\n", "\n", "\n", "4->2\n", "\n", "\n", "!a & b\n", "\n", "\n", "4->4\n", "\n", "\n", "a & b\n", "\n", "\n", "\n" ], "text": [ " *' at 0x7fd034190240> >" ] } ], "prompt_number": 9 } ], "metadata": {} } ] }