{ "cells": [ { "cell_type": "markdown", "id": "c200034d-b5f7-4af8-89fe-589d508d65d5", "metadata": { "tags": [] }, "source": [ "# PRINTER_SELL" ] }, { "cell_type": "code", "execution_count": 1, "id": "60301507-1d96-4e3c-97cd-390dc512bcb5", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "finite_state_machine\n", "\n", "\n", "\n", "_a\n", "\n", "\n", "\n", "\n", "0\n", "\n", "\n", "0\n", "\n", "\n", "\n", "_a->0\n", "\n", "\n", "\n", "\n", "\n", "1\n", "\n", "\n", "1\n", "\n", "\n", "\n", "0->1\n", "\n", "\n", "start\n", "\n", "\n", "\n", "1->0\n", "\n", "\n", "auto_finish\n", "\n", "\n", "\n", "1->0\n", "\n", "\n", "manual_stop\n", "\n", "\n", "\n", "2\n", "\n", "2\n", "\n", "\n", "\n", "1->2\n", "\n", "\n", "breakdown\n", "\n", "\n", "\n", "2->0\n", "\n", "\n", "fix\n", "\n", "\n", "\n", "3\n", "\n", "\n", "3\n", "\n", "\n", "\n", "2->3\n", "\n", "\n", "sell\n", "\n", "\n", "\n" ], "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pytct\n", "pytct.init(\"Chp4\", overwrite=True)\n", "\n", "statenum=4 #number of states\n", "#states are sequentially labeled 0,1,...,statenum\n", "#initial state is labeled 0\n", "\n", "trans=[(0,'start',1,'c'),\n", " (1,'auto_finish',0,'u'),\n", " (1,'manual_stop',0,'c'),\n", " (1,'breakdown',2,'u'),\n", " (2,'fix',0,'c'),\n", " (2,'sell',3,'c')] #set of transitions\n", "#each triple is (exit state, event label, entering state)\n", "#each event is either 'c' (controllable) or 'u' (uncontrollable)\n", "\n", "marker = [0,1,3] #set of marker states\n", "\n", "pytct.create('PRINTER_SELL', statenum, trans, marker)\n", "#create automaton PRINTER_SELL\n", "\n", "pytct.display_automaton('PRINTER_SELL',color=True)\n", "#plot PRINTER_SELL.DES with color coding" ] }, { "cell_type": "code", "execution_count": 2, "id": "0bcac9b6-4758-460a-bdbb-3cc4ab739c8a", "metadata": {}, "outputs": [], "source": [ "#statenum=4 #number of states\n", "#states are sequentially labeled 0,1,...,statenum\n", "#initial state is labeled 0\n", "\n", "#trans=[(0,11,1),\n", "# (1,10,0),\n", "# (1,13,0),\n", "# (1,12,2),\n", "# (2,15,0),\n", "# (2,17,3)] #set of transitions\n", "#each triple is (exit state, event label, entering state)\n", "#odd numbers for controllable events; even numbers for uncontrollable events\n", "\n", "#marker = [0,1,3] #set of marker states\n", "\n", "#pytct.create('PRINTER_SELL', statenum, trans, marker)\n", "#create automaton PRINTER_SELL\n", "\n", "#pytct.display_automaton('PRINTER_SELL',color=True)\n", "#plot PRINTER_SELL.DES with color coding" ] }, { "cell_type": "code", "execution_count": 3, "id": "8f7c9a7e-a099-4250-83ef-5decc782f2f3", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/opt/conda/lib/python3.11/site-packages/pytct/des_check.py:65: UserWarning: Too many number of state. It is recommend to set 3\n", " warnings.warn(f\"Too many number of state. It is recommend to set {max_state}\")\n" ] }, { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "finite_state_machine\n", "\n", "\n", "\n", "_a\n", "\n", "\n", "\n", "\n", "0\n", "\n", "\n", "0\n", "\n", "\n", "\n", "_a->0\n", "\n", "\n", "\n", "\n", "\n", "1\n", "\n", "\n", "1\n", "\n", "\n", "\n", "0->1\n", "\n", "\n", "start\n", "\n", "\n", "\n", "1->0\n", "\n", "\n", "auto_finish\n", "\n", "\n", "\n", "1->0\n", "\n", "\n", "manual_stop\n", "\n", "\n", "\n", "2\n", "\n", "2\n", "\n", "\n", "\n", "1->2\n", "\n", "\n", "breakdown\n", "\n", "\n", "\n", "2->0\n", "\n", "\n", "fix\n", "\n", "\n", "\n", "3\n", "\n", "\n", "3\n", "\n", "\n", "\n" ], "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pytct.subautomaton('S1','PRINTER_SELL',[3],[])\n", "#create subautomaton S1 by removing from PRINTER_SELL \n", "# [state list] and [transition list]\n", "\n", "pytct.display_automaton('S1',color=True)\n", "#plot S1.DES with color coding" ] }, { "cell_type": "code", "execution_count": 4, "id": "0c7d1961-2f38-4414-a740-0a4db2c662a6", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/opt/conda/lib/python3.11/site-packages/pytct/des_check.py:65: UserWarning: Too many number of state. It is recommend to set 3\n", " warnings.warn(f\"Too many number of state. It is recommend to set {max_state}\")\n" ] }, { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "finite_state_machine\n", "\n", "\n", "\n", "_a\n", "\n", "\n", "\n", "\n", "0\n", "\n", "\n", "0\n", "\n", "\n", "\n", "_a->0\n", "\n", "\n", "\n", "\n", "\n", "1\n", "\n", "\n", "1\n", "\n", "\n", "\n", "0->1\n", "\n", "\n", "start\n", "\n", "\n", "\n", "1->0\n", "\n", "\n", "auto_finish\n", "\n", "\n", "\n", "1->0\n", "\n", "\n", "manual_stop\n", "\n", "\n", "\n", "2\n", "\n", "2\n", "\n", "\n", "\n", "1->2\n", "\n", "\n", "breakdown\n", "\n", "\n", "\n", "2->0\n", "\n", "\n", "fix\n", "\n", "\n", "\n", "3\n", "\n", "\n", "3\n", "\n", "\n", "\n" ], "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pytct.subautomaton('S2','PRINTER_SELL',[],[(2,'sell',3)])\n", "#create subautomaton S2 by removing from PRINTER_SELL \n", "# [state list] and [transition list]\n", "\n", "pytct.display_automaton('S2',color=True)\n", "#plot S2.DES with color coding" ] }, { "cell_type": "code", "execution_count": 5, "id": "bc4351ae-7926-4aa0-ba85-3f180a2ff8dd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pytct.is_controllable('PRINTER_SELL','S2')\n", "#check if S is controllable wrt. PRINTER_SELL" ] }, { "cell_type": "code", "execution_count": 6, "id": "80c112c3-5a49-41b5-8fe0-102823a7fc81", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "finite_state_machine\n", "\n", "\n", "\n", "_a\n", "\n", "\n", "\n", "\n", "0\n", "\n", "0\n", "\n", "\n", "\n", "_a->0\n", "\n", "\n", "\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "\n", "0->1\n", "\n", "\n", "move_up\n", "\n", "\n", "\n", "2\n", "\n", "2\n", "\n", "\n", "\n", "0->2\n", "\n", "\n", "move_right_u\n", "\n", "\n", "\n", "3\n", "\n", "3\n", "\n", "\n", "\n", "1->3\n", "\n", "\n", "move_right_u\n", "\n", "\n", "\n", "4\n", "\n", "4\n", "\n", "\n", "\n", "1->4\n", "\n", "\n", "move_right_c\n", "\n", "\n", "\n", "2->3\n", "\n", "\n", "move_up\n", "\n", "\n", "\n", "5\n", "\n", "\n", "5\n", "\n", "\n", "\n", "2->5\n", "\n", "\n", "move_right_c\n", "\n", "\n", "\n", "3->2\n", "\n", "\n", "move_down\n", "\n", "\n", "\n", "6\n", "\n", "6\n", "\n", "\n", "\n", "3->6\n", "\n", "\n", "move_right_c\n", "\n", "\n", "\n", "4->3\n", "\n", "\n", "move_down\n", "\n", "\n", "\n", "4->6\n", "\n", "\n", "move_right_u\n", "\n", "\n", "\n", "6->5\n", "\n", "\n", "move_down\n", "\n", "\n", "\n" ], "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "statenum=7 #number of states\n", "#states are sequentially labeled 0,1,...,statenum\n", "#initial state is labeled 0\n", "\n", "trans=[(0,'move_up',1,'u'),\n", " (0,'move_right_u',2,'u'),\n", " (1,'move_right_u',3,'u'),\n", " (1,'move_right_c',4,'c'),\n", " (2,'move_up',3,'u'),\n", " (2,'move_right_c',5,'c'),\n", " (3,'move_down',2,'u'),\n", " (3,'move_right_c',6,'c'),\n", " (4,'move_down',3,'u'),\n", " (4,'move_right_u',6,'u'),\n", " (6,'move_down',5,'u')] #set of transitions\n", "#each triple is (exit state, event label, entering state)\n", "#each event is either 'c' (controllable) or 'u' (uncontrollable)\n", "\n", "marker = [5] #set of marker states\n", "\n", "pytct.create('ROBOT', statenum, trans, marker)\n", "#create automaton ROBOT\n", "\n", "pytct.display_automaton('ROBOT',color=True)\n", "#plot ROBOT.DES with color coding" ] }, { "cell_type": "code", "execution_count": 7, "id": "fea6d1c8-98a0-4030-bfcb-5b1e41e1a017", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/opt/conda/lib/python3.11/site-packages/pytct/des_check.py:65: UserWarning: Too many number of state. It is recommend to set 6\n", " warnings.warn(f\"Too many number of state. It is recommend to set {max_state}\")\n" ] }, { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "finite_state_machine\n", "\n", "\n", "\n", "_a\n", "\n", "\n", "\n", "\n", "0\n", "\n", "0\n", "\n", "\n", "\n", "_a->0\n", "\n", "\n", "\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "\n", "0->1\n", "\n", "\n", "move_up\n", "\n", "\n", "\n", "2\n", "\n", "2\n", "\n", "\n", "\n", "0->2\n", "\n", "\n", "move_right_u\n", "\n", "\n", "\n", "3\n", "\n", "3\n", "\n", "\n", "\n", "1->3\n", "\n", "\n", "move_right_u\n", "\n", "\n", "\n", "4\n", "\n", "4\n", "\n", "\n", "\n", "1->4\n", "\n", "\n", "move_right_c\n", "\n", "\n", "\n", "2->3\n", "\n", "\n", "move_up\n", "\n", "\n", "\n", "5\n", "\n", "\n", "5\n", "\n", "\n", "\n", "2->5\n", "\n", "\n", "move_right_c\n", "\n", "\n", "\n", "3->2\n", "\n", "\n", "move_down\n", "\n", "\n", "\n", "4->3\n", "\n", "\n", "move_down\n", "\n", "\n", "\n", "6\n", "\n", "6\n", "\n", "\n", "\n" ], "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pytct.subautomaton('S','ROBOT',[6],[])\n", "#create subautomaton S by removing from ROBOT\n", "# [state list] and [transition list]\n", "\n", "pytct.display_automaton('S',color=True)\n", "#plot S.DES with color coding" ] }, { "cell_type": "code", "execution_count": 8, "id": "c6dcb4b5-e027-427f-9a42-d8911758f802", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pytct.is_controllable('ROBOT','S')\n", "#check if S is controllable wrt. ROBOT" ] }, { "cell_type": "code", "execution_count": 9, "id": "f6961ac0-04e0-40e9-8a21-25dd3ab81de4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[4, 4, 4]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pytct.uncontrollable_states('ROBOT','S')\n", "#compute the set of uncontrollable states" ] }, { "cell_type": "code", "execution_count": null, "id": "ff86e9e2-d460-4e67-ad1a-53511c3fc0cf", "metadata": {}, "outputs": [], "source": [] } ], "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.11.6" } }, "nbformat": 4, "nbformat_minor": 5 }