{ "cells": [ { "cell_type": "markdown", "id": "c200034d-b5f7-4af8-89fe-589d508d65d5", "metadata": { "tags": [] }, "source": [ "# PRINTER_SELL" ] }, { "cell_type": "code", "execution_count": 2, "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": 2, "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": 3, "id": "a0060523-4eb5-40df-b6d0-b09f75940e37", "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", "0->0\n", "\n", "\n", "auto_finish\n", "\n", "\n", "\n", "0->0\n", "\n", "\n", "start\n", "\n", "\n", "\n", "0->0\n", "\n", "\n", "manual_stop\n", "\n", "\n", "\n", "1\n", "\n", "\n", "1\n", "\n", "\n", "\n", "0->1\n", "\n", "\n", "breakdown\n", "\n", "\n", "\n", "1->1\n", "\n", "\n", "auto_finish\n", "\n", "\n", "\n", "1->1\n", "\n", "\n", "start\n", "\n", "\n", "\n", "1->1\n", "\n", "\n", "manual_stop\n", "\n", "\n", "\n", "1->1\n", "\n", "\n", "fix\n", "\n", "\n", "\n", "1->1\n", "\n", "\n", "sell\n", "\n", "\n", "\n" ], "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# creat automaton E\n", "\n", "statenum=2 #number of states\n", "#states are sequentially labeled 0,1,...,statenum\n", "#initial state is labeled 0\n", "\n", "trans=[(0,'start',0,'c'),\n", " (0,'auto_finish',0,'u'),\n", " (0,'manual_stop',0,'c'),\n", " (0,'breakdown',1,'u'),\n", " (1,'start',1,'c'),\n", " (1,'auto_finish',1,'u'),\n", " (1,'manual_stop',1,'c'),\n", " (1,'fix',1,'c'),\n", " (1,'sell',1,'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] #set of marker states\n", "\n", "pytct.create('E', statenum, trans, marker)\n", "#create automaton E\n", "\n", "pytct.display_automaton('E',color=True)\n", "#plot E.DES with color coding" ] }, { "cell_type": "code", "execution_count": 4, "id": "32a50cc2-4042-4f2b-90e1-66626d3d6f10", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pytct.is_controllable('PRINTER_SELL','E')\n", "#check if E is controllable wrt. PRINTER_SELL" ] }, { "cell_type": "code", "execution_count": 5, "id": "fb1d4451-3dbf-4183-8c7a-c73a8c7550a1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pytct.uncontrollable_states('PRINTER_SELL','E')\n", "#compute the set of uncontrollable states" ] }, { "cell_type": "code", "execution_count": 6, "id": "e2b54ebf-3551-4ae4-a7dc-ef6b1a8255aa", "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", "3\n", "\n", "\n", "3\n", "\n", "\n", "\n", "2->3\n", "\n", "\n", "fix\n", "\n", "\n", "\n", "4\n", "\n", "\n", "4\n", "\n", "\n", "\n", "2->4\n", "\n", "\n", "sell\n", "\n", "\n", "\n", "5\n", "\n", "\n", "5\n", "\n", "\n", "\n", "3->5\n", "\n", "\n", "start\n", "\n", "\n", "\n", "5->3\n", "\n", "\n", "auto_finish\n", "\n", "\n", "\n", "5->3\n", "\n", "\n", "manual_stop\n", "\n", "\n", "\n" ], "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pytct.sync('S','PRINTER_SELL','E')\n", "#synchronous product\n", "\n", "pytct.display_automaton('S',color=True)\n", "#plot DES with color coding" ] }, { "cell_type": "code", "execution_count": 7, "id": "828e479c-4020-4e76-be55-80e103bb9a49", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pytct.is_controllable('PRINTER_SELL','S')\n", "#check if S is controllable wrt. PRINTER_SELL" ] }, { "cell_type": "code", "execution_count": 8, "id": "bd0e2ad3-31b6-47db-90c5-cd31a8e56bd0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[5]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pytct.uncontrollable_states('PRINTER_SELL','S')\n", "#compute the set of uncontrollable states" ] }, { "cell_type": "code", "execution_count": 9, "id": "771361ea-bcd7-4c9d-bd24-a45c4a6ba7a7", "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", "3\n", "\n", "\n", "3\n", "\n", "\n", "\n", "2->3\n", "\n", "\n", "fix\n", "\n", "\n", "\n", "4\n", "\n", "\n", "4\n", "\n", "\n", "\n", "2->4\n", "\n", "\n", "sell\n", "\n", "\n", "\n" ], "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pytct.supcon('C','PRINTER_SELL','E') \n", "#compute optimal supervisor\n", "\n", "pytct.display_automaton('C', color=True) # display automaton\n", "# red transition: controllable; green transition: uncontrollable" ] }, { "cell_type": "code", "execution_count": 10, "id": "e67a9fe0-455b-4516-9b88-a6b6520b6f08", "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", "3\n", "\n", "\n", "3\n", "\n", "\n", "\n", "2->3\n", "\n", "\n", "fix\n", "\n", "\n", "\n", "4\n", "\n", "\n", "4\n", "\n", "\n", "\n", "2->4\n", "\n", "\n", "sell\n", "\n", "\n", "\n" ], "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pytct.supcon('CC','PRINTER_SELL','S') \n", "#compute optimal supervisor\n", "\n", "pytct.display_automaton('CC', color=True) # display automaton\n", "# red transition: controllable; green transition: uncontrollable" ] }, { "cell_type": "code", "execution_count": 14, "id": "c2919984-2ec7-4fb1-8b8c-f660c27394f5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3: start\n" ] } ], "source": [ "table = pytct.conact('PRINTER_SELL','C')\n", "#compute supervisor's control actions\n", "\n", "print(table)\n", "#print control actions" ] }, { "cell_type": "code", "execution_count": 17, "id": "fa614e21-0c9a-4ab3-bf52-8bcc3e60a711", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3: start\n" ] } ], "source": [ "table = pytct.conact('PRINTER_SELL','CC')\n", "#compute supervisor's control actions\n", "\n", "print(table)\n", "#print control actions\n" ] }, { "cell_type": "code", "execution_count": null, "id": "a8027191-c2b9-4355-aad6-0c903c459849", "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 }