{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "8bca10b8", "metadata": {}, "outputs": [], "source": [ "import spot, buddy\n", "import pandas as pd\n", "spot.setup()" ] }, { "cell_type": "markdown", "id": "c73e997a", "metadata": {}, "source": [ "Test the Mealy printer." ] }, { "cell_type": "code", "execution_count": 2, "id": "f8eff7ed", "metadata": {}, "outputs": [], "source": [ "g = spot.ltl_to_game('G((a|c) <-> (b|d))', [\"b\", \"d\"])" ] }, { "cell_type": "code", "execution_count": 3, "id": "ad3c80bc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "spot.solve_game(g)" ] }, { "cell_type": "code", "execution_count": 4, "id": "50130d85", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "t\n", "[all]\n", "\n", "\n", "\n", "0\n", "\n", "0\n", "\n", "\n", "\n", "I->0\n", "\n", "\n", "\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "\n", "0->1\n", "\n", "\n", "!a & !c\n", "\n", "\n", "\n", "2\n", "\n", "2\n", "\n", "\n", "\n", "0->2\n", "\n", "\n", "a | c\n", "\n", "\n", "\n", "1->0\n", "\n", "\n", "!b & !d\n", "\n", "\n", "\n", "2->0\n", "\n", "\n", "b | d\n", "\n", "\n", "\n" ], "text/plain": [ " *' at 0x7f8877796550> >" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "spot.highlight_strategy(g)" ] }, { "cell_type": "code", "execution_count": 5, "id": "3d56cda6", "metadata": {}, "outputs": [], "source": [ "x = spot.solved_game_to_separated_mealy(g)" ] }, { "cell_type": "code", "execution_count": 6, "id": "c24548a1", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "0\n", "\n", "0\n", "\n", "\n", "\n", "I->0\n", "\n", "\n", "\n", "\n", "\n", "0->0\n", "\n", "\n", "\n", "!a & !c\n", "/\n", "\n", "!b & !d\n", "\n", "\n", "\n", "0->0\n", "\n", "\n", "\n", "a | c\n", "/\n", "\n", "b | d\n", "\n", "\n", "\n" ], "text/plain": [ " *' at 0x7f8877796820> >" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x" ] }, { "cell_type": "code", "execution_count": 7, "id": "88f2c0e0", "metadata": {}, "outputs": [], "source": [ "x.merge_edges()" ] }, { "cell_type": "code", "execution_count": 8, "id": "e626997e", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "0\n", "\n", "0\n", "\n", "\n", "\n", "I->0\n", "\n", "\n", "\n", "\n", "\n", "0->0\n", "\n", "\n", "\n", "!a & !c\n", "/\n", "\n", "!b & !d\n", "\n", "a | c\n", "/\n", "\n", "b | d\n", "\n", "\n", "\n" ], "text/plain": [ " *' at 0x7f8877796820> >" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x" ] }, { "cell_type": "code", "execution_count": 9, "id": "923a59d6", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "0\n", "\n", "0\n", "\n", "\n", "\n", "I->0\n", "\n", "\n", "\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "\n", "0->1\n", "\n", "\n", "\n", "!i\n", "/\n", "\n", "!o\n", "\n", "\n", "\n", "2\n", "\n", "2\n", "\n", "\n", "\n", "0->2\n", "\n", "\n", "\n", "i\n", "/\n", "\n", "o\n", "\n", "\n", "\n", "1->1\n", "\n", "\n", "\n", "1\n", "/\n", "\n", "!o\n", "\n", "\n", "\n", "2->2\n", "\n", "\n", "\n", "1\n", "/\n", "\n", "1\n", "\n", "\n", "\n" ], "text/plain": [ " *' at 0x7f8877797b40> >" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aut = spot.make_twa_graph()\n", "i = buddy.bdd_ithvar(aut.register_ap(\"i\"))\n", "o = buddy.bdd_ithvar(aut.register_ap(\"o\"))\n", "spot.set_synthesis_outputs(aut, o)\n", "aut.new_states(3)\n", "aut.new_edge(0,1,buddy.bdd_not(i)&buddy.bdd_not(o))\n", "aut.new_edge(0,2,i&o)\n", "aut.new_edge(1,1,buddy.bdd_not(o))\n", "aut.new_edge(2,2,buddy.bddtrue)\n", "aut" ] }, { "cell_type": "code", "execution_count": 10, "id": "f06d6df4", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "('o',)\n" ] }, { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "t\n", "[all]\n", "\n", "\n", "\n", "0\n", "\n", "0\n", "\n", "\n", "\n", "I->0\n", "\n", "\n", "\n", "\n", "\n", "3\n", "\n", "3\n", "\n", "\n", "\n", "0->3\n", "\n", "\n", "!i\n", "\n", "\n", "\n", "4\n", "\n", "4\n", "\n", "\n", "\n", "0->4\n", "\n", "\n", "i\n", "\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "\n", "3->1\n", "\n", "\n", "!o\n", "\n", "\n", "\n", "2\n", "\n", "2\n", "\n", "\n", "\n", "4->2\n", "\n", "\n", "o\n", "\n", "\n", "\n", "1->3\n", "\n", "\n", "1\n", "\n", "\n", "\n", "5\n", "\n", "5\n", "\n", "\n", "\n", "2->5\n", "\n", "\n", "1\n", "\n", "\n", "\n", "5->2\n", "\n", "\n", "1\n", "\n", "\n", "\n" ], "text/plain": [ " *' at 0x7f88777970f0> >" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aut_s = spot.split_2step(aut)\n", "print(spot.get_synthesis_output_aps(aut_s))\n", "aut_s" ] }, { "cell_type": "code", "execution_count": 11, "id": "3cc4d320", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
taskpremin_timereorg_timepartsol_timeplayer_incomp_timeincomp_timesplit_all_let_timesplit_min_let_timesplit_cstr_timeprob_init_build_time...total_timen_classesn_refinementn_litn_clausesn_iterationn_letters_partn_bisim_letn_min_statesdone
0presat7.7176e-052.863e-061.6553e-050.0001860617.753e-061.0616e-051.1804e-058.101e-066.7328e-05...NaNNaNNaNNaNNaNNaN32NaNNaN
1satNaNNaNNaNNaNNaNNaNNaNNaNNaN...0.000496302207120NaNNaN41
\n", "

2 rows × 23 columns

\n", "
" ], "text/plain": [ " task premin_time reorg_time partsol_time player_incomp_time incomp_time \\\n", "0 presat 7.7176e-05 2.863e-06 1.6553e-05 0.000186061 7.753e-06 \n", "1 sat NaN NaN NaN NaN NaN \n", "\n", " split_all_let_time split_min_let_time split_cstr_time prob_init_build_time \\\n", "0 1.0616e-05 1.1804e-05 8.101e-06 6.7328e-05 \n", "1 NaN NaN NaN NaN \n", "\n", " ... total_time n_classes n_refinement n_lit n_clauses n_iteration \\\n", "0 ... NaN NaN NaN NaN NaN NaN \n", "1 ... 0.000496302 2 0 7 12 0 \n", "\n", " n_letters_part n_bisim_let n_min_states done \n", "0 3 2 NaN NaN \n", "1 NaN NaN 4 1 \n", "\n", "[2 rows x 23 columns]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "t\n", "[all]\n", "\n", "\n", "\n", "0\n", "\n", "0\n", "\n", "\n", "\n", "I->0\n", "\n", "\n", "\n", "\n", "\n", "2\n", "\n", "2\n", "\n", "\n", "\n", "0->2\n", "\n", "\n", "i\n", "\n", "\n", "\n", "3\n", "\n", "3\n", "\n", "\n", "\n", "0->3\n", "\n", "\n", "!i\n", "\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "\n", "2->1\n", "\n", "\n", "o\n", "\n", "\n", "\n", "3->1\n", "\n", "\n", "!o\n", "\n", "\n", "\n", "1->3\n", "\n", "\n", "1\n", "\n", "\n", "\n" ], "text/plain": [ " *' at 0x7f8877796eb0> >" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "min_lvl = 0\n", "aut_ms, table = spot.minimize_mealy(aut_s, min_lvl, display_log=True, return_log=True)\n", "aut_ms" ] }, { "cell_type": "markdown", "id": "bc844797", "metadata": {}, "source": [ "## A more involved example" ] }, { "cell_type": "code", "execution_count": 12, "id": "893bc90e", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "0\n", "\n", "0\n", "\n", "\n", "\n", "I->0\n", "\n", "\n", "\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "\n", "0->1\n", "\n", "\n", "\n", "1\n", "/\n", "\n", "o1\n", "\n", "\n", "\n", "2\n", "\n", "2\n", "\n", "\n", "\n", "1->2\n", "\n", "\n", "\n", "1\n", "/\n", "\n", "o0\n", "\n", "\n", "\n", "2->2\n", "\n", "\n", "\n", "1\n", "/\n", "\n", "(o0 & !o1) | (!o0 & o1)\n", "\n", "\n", "\n" ], "text/plain": [ " *' at 0x7f8877797120> >" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aut = spot.make_twa_graph()\n", "i = buddy.bdd_ithvar(aut.register_ap(\"i\"))\n", "o0 = buddy.bdd_ithvar(aut.register_ap(\"o0\"))\n", "no0 = buddy.bdd_not(o0)\n", "o1 = buddy.bdd_ithvar(aut.register_ap(\"o1\"))\n", "no1 = buddy.bdd_not(o1)\n", "spot.set_synthesis_outputs(aut, o0&o1)\n", "\n", "vo1 = o0&o1\n", "vo2 = no0&o1\n", "vo3 = o0&no1\n", "\n", "aut.new_states(3)\n", "\n", "aut.new_edge(0,1,vo1|vo2)\n", "aut.new_edge(1,2,vo1|vo3)\n", "aut.new_edge(2,2,vo2|vo3)\n", "aut" ] }, { "cell_type": "code", "execution_count": 13, "id": "23edb107", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "t\n", "[all]\n", "\n", "\n", "\n", "0\n", "\n", "0\n", "\n", "\n", "\n", "I->0\n", "\n", "\n", "\n", "\n", "\n", "3\n", "\n", "3\n", "\n", "\n", "\n", "0->3\n", "\n", "\n", "1\n", "\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "\n", "3->1\n", "\n", "\n", "o1\n", "\n", "\n", "\n", "4\n", "\n", "4\n", "\n", "\n", "\n", "1->4\n", "\n", "\n", "1\n", "\n", "\n", "\n", "2\n", "\n", "2\n", "\n", "\n", "\n", "4->2\n", "\n", "\n", "o0\n", "\n", "\n", "\n", "5\n", "\n", "5\n", "\n", "\n", "\n", "2->5\n", "\n", "\n", "1\n", "\n", "\n", "\n", "5->2\n", "\n", "\n", "(o0 & !o1) | (!o0 & o1)\n", "\n", "\n", "\n" ], "text/plain": [ " *' at 0x7f8877797990> >" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aut_s = spot.split_2step(aut)\n", "aut_s" ] }, { "cell_type": "code", "execution_count": 14, "id": "837aab84", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
taskpremin_timereorg_timepartsol_timeplayer_incomp_timeincomp_timesplit_all_let_timesplit_min_let_timesplit_cstr_timeprob_init_build_time...total_timen_classesn_refinementn_litn_clausesn_iterationn_letters_partn_bisim_letn_min_statesdone
0presat3.282e-063.702e-061.4248e-050.0001090946.705e-069.219e-068.52e-061.0407e-053.2896e-05...NaNNaNNaNNaNNaNNaN11NaNNaN
1satNaNNaNNaNNaNNaNNaNNaNNaNNaN...NaN10360NaNNaNNaNNaN
2refinementNaNNaNNaNNaNNaNNaNNaNNaNNaN...NaN111016NaNNaNNaNNaNNaN
3satNaNNaNNaNNaNNaNNaNNaNNaNNaN...0.000412422017291NaNNaN41
\n", "

4 rows × 23 columns

\n", "
" ], "text/plain": [ " task premin_time reorg_time partsol_time player_incomp_time \\\n", "0 presat 3.282e-06 3.702e-06 1.4248e-05 0.000109094 \n", "1 sat NaN NaN NaN NaN \n", "2 refinement NaN NaN NaN NaN \n", "3 sat NaN NaN NaN NaN \n", "\n", " incomp_time split_all_let_time split_min_let_time split_cstr_time \\\n", "0 6.705e-06 9.219e-06 8.52e-06 1.0407e-05 \n", "1 NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN \n", "\n", " prob_init_build_time ... total_time n_classes n_refinement n_lit \\\n", "0 3.2896e-05 ... NaN NaN NaN NaN \n", "1 NaN ... NaN 1 0 3 \n", "2 NaN ... NaN 1 1 10 \n", "3 NaN ... 0.00041242 2 0 17 \n", "\n", " n_clauses n_iteration n_letters_part n_bisim_let n_min_states done \n", "0 NaN NaN 1 1 NaN NaN \n", "1 6 0 NaN NaN NaN NaN \n", "2 16 NaN NaN NaN NaN NaN \n", "3 29 1 NaN NaN 4 1 \n", "\n", "[4 rows x 23 columns]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Number of variables\n", "0 NaN\n", "1 3\n", "2 10\n", "3 17\n", "Name: n_lit, dtype: object\n" ] }, { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "t\n", "[all]\n", "\n", "\n", "\n", "0\n", "\n", "0\n", "\n", "\n", "\n", "I->0\n", "\n", "\n", "\n", "\n", "\n", "2\n", "\n", "2\n", "\n", "\n", "\n", "0->2\n", "\n", "\n", "1\n", "\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "\n", "2->1\n", "\n", "\n", "o0 & o1\n", "\n", "\n", "\n", "3\n", "\n", "3\n", "\n", "\n", "\n", "1->3\n", "\n", "\n", "1\n", "\n", "\n", "\n", "3->1\n", "\n", "\n", "o0 & !o1\n", "\n", "\n", "\n" ], "text/plain": [ " *' at 0x7f8877797cc0> >" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "si = spot.synthesis_info()\n", "si.minimize_lvl = 3\n", "aut_ms, table = spot.minimize_mealy(aut_s, si, display_log=True, return_log=True)\n", "print(\"Number of variables\")\n", "print(table[\"n_lit\"])\n", "aut_ms" ] }, { "cell_type": "markdown", "id": "0fea0269", "metadata": {}, "source": [ "## Testing dimacs output" ] }, { "cell_type": "code", "execution_count": 15, "id": "d14324e8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
taskpremin_timereorg_timepartsol_timeplayer_incomp_timeincomp_timesplit_all_let_timesplit_min_let_timesplit_cstr_timeprob_init_build_time...total_timen_classesn_refinementn_litn_clausesn_iterationn_letters_partn_bisim_letn_min_statesdone
0presat1.956e-062.445e-068.171e-065.0007e-054.819e-066.077e-065.797e-064.33e-062.242e-05...NaNNaNNaNNaNNaNNaN11NaNNaN
1satNaNNaNNaNNaNNaNNaNNaNNaNNaN...NaN10360NaNNaNNaNNaN
2refinementNaNNaNNaNNaNNaNNaNNaNNaNNaN...NaN111016NaNNaNNaNNaNNaN
3satNaNNaNNaNNaNNaNNaNNaNNaNNaN...0.0002521322017291NaNNaN41
\n", "

4 rows × 23 columns

\n", "
" ], "text/plain": [ " task premin_time reorg_time partsol_time player_incomp_time \\\n", "0 presat 1.956e-06 2.445e-06 8.171e-06 5.0007e-05 \n", "1 sat NaN NaN NaN NaN \n", "2 refinement NaN NaN NaN NaN \n", "3 sat NaN NaN NaN NaN \n", "\n", " incomp_time split_all_let_time split_min_let_time split_cstr_time \\\n", "0 4.819e-06 6.077e-06 5.797e-06 4.33e-06 \n", "1 NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN \n", "\n", " prob_init_build_time ... total_time n_classes n_refinement n_lit \\\n", "0 2.242e-05 ... NaN NaN NaN NaN \n", "1 NaN ... NaN 1 0 3 \n", "2 NaN ... NaN 1 1 10 \n", "3 NaN ... 0.000252132 2 0 17 \n", "\n", " n_clauses n_iteration n_letters_part n_bisim_let n_min_states done \n", "0 NaN NaN 1 1 NaN NaN \n", "1 6 0 NaN NaN NaN NaN \n", "2 16 NaN NaN NaN NaN NaN \n", "3 29 1 NaN NaN 4 1 \n", "\n", "[4 rows x 23 columns]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "c ### Next Instance 1 0 ###\n", "p cnf 5 5\n", "-1 2 -3 0\n", "1 -3 0\n", "1 -5 0\n", "2 -5 0\n", "3 -5 0\n", "c ### Next Instance 1 1 ###\n", "p cnf 12 15\n", "-1 2 -3 0\n", "4 0\n", "6 0\n", "-9 0\n", "-1 -2 10 0\n", "-10 0\n", "1 -3 0\n", "1 -5 0\n", "1 -12 0\n", "2 -5 0\n", "2 -12 0\n", "-2 9 0\n", "3 -5 0\n", "3 -12 0\n", "7 8 0\n", "c ### Next Instance 2 0 ###\n", "p cnf 19 29\n", "-3 -1 2 0\n", "4 0\n", "6 0\n", "-9 0\n", "-1 -2 10 0\n", "-10 0\n", "11 -16 -17 0\n", "1 -15 -17 0\n", "-1 13 -14 0\n", "-11 13 -16 0\n", "-11 -15 2 0\n", "-13 -15 2 0\n", "1 11 -19 0\n", "13 -19 2 0\n", "15 16 -19 0\n", "3 14 -19 0\n", "-2 0\n", "-12 0\n", "-5 0\n", "1 -3 0\n", "1 -5 0\n", "1 -12 0\n", "2 -5 0\n", "2 -12 0\n", "-2 9 0\n", "3 -5 0\n", "3 -12 0\n", "7 8 0\n", "11 -14 0\n", "\n" ] } ], "source": [ "import tempfile\n", "\n", "si = spot.synthesis_info()\n", "si.minimize_lvl = 3\n", "\n", "with tempfile.NamedTemporaryFile(dir='.', suffix='.dimacslog') as t:\n", " si.opt.set_str(\"satlogdimacs\", t.name)\n", " aut_ms, table = spot.minimize_mealy(aut_s, si, display_log=True, return_log=True)\n", " with open(t.name, \"r\") as f:\n", " print(\"\".join(f.readlines()))\n", " \n", " " ] }, { "cell_type": "markdown", "id": "b10213b8", "metadata": {}, "source": [ "# Testing partitioned relabeling" ] }, { "cell_type": "code", "execution_count": 16, "id": "fd5ca506", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Conditions in orig machine: 8\n", "Conditions in relabeled machine: 13\n" ] } ], "source": [ "def get_mealy():\n", " return spot.split_2step(spot.automaton(\"\"\"HOA: v1\n", "States: 2\n", "Start: 0\n", "AP: 11 \"u0accel0accel\" \"u0accel0f1dcon23p81b\" \"u0accel0f1dcon231b\" \"u0gear0f1dmin0f1dcon61b0f1dadd0gear0f1dcon241b1b1b\" \"u0gear0gear\" \"u0gear0f1dmax0f1dcon241b0f1dsub0gear0f1dcon241b1b1b\" \"u0steer0f1dsteering0angle0trackpos1b\" \"u0steer0steer\" \"p0p0gt0rpm0f1dcon5523231b\" \"p0p0lt0rpm0f1dcon32323231b\" \"p0p0lt0speed0f1dsub0target2speed0f1dmultp0f1dabs0steer1b0f1dcon248881b1b1b\"\n", "acc-name: all\n", "Acceptance: 0 t\n", "properties: trans-labels explicit-labels state-acc deterministic\n", "controllable-AP: 0 1 2 3 4 5 6 7\n", "--BODY--\n", "State: 0\n", "[!0&!1&2&!3&4&!5&6&!7&!8&!9&!10] 0\n", "[!0&1&!2&!3&4&!5&6&!7&!8&!9&10] 0\n", "[!0&!1&2&!3&!4&5&6&!7&!8&9&!10] 0\n", "[!0&1&!2&!3&!4&5&6&!7&!8&9&10] 0\n", "[!0&!1&2&3&!4&!5&6&!7&8&!9&!10] 0\n", "[!0&1&!2&3&!4&!5&6&!7&8&!9&10] 0\n", "[!0&!1&2&!3&!4&5&!6&7&8&9 | !0&!1&2&!3&!4&5&6&!7&8&9 | !0&!1&2&!3&4&!5&!6&7&8&9 | !0&!1&2&!3&4&!5&6&!7&8&9 | !0&!1&2&3&!4&!5&!6&7&8&9 | !0&!1&2&3&!4&!5&6&!7&8&9 | !0&1&!2&!3&!4&5&!6&7&8&9 | !0&1&!2&!3&!4&5&6&!7&8&9 | !0&1&!2&!3&4&!5&!6&7&8&9 | !0&1&!2&!3&4&!5&6&!7&8&9 | !0&1&!2&3&!4&!5&!6&7&8&9 | !0&1&!2&3&!4&!5&6&!7&8&9 | 0&!1&!2&!3&!4&5&!6&7&8&9 | 0&!1&!2&!3&!4&5&6&!7&8&9 | 0&!1&!2&!3&4&!5&!6&7&8&9 | 0&!1&!2&!3&4&!5&6&!7&8&9 | 0&!1&!2&3&!4&!5&!6&7&8&9 | 0&!1&!2&3&!4&!5&6&!7&8&9] 1\n", "State: 1\n", "[!0&!1&2&!3&!4&5&!6&7 | !0&!1&2&!3&!4&5&6&!7 | !0&!1&2&!3&4&!5&!6&7 | !0&!1&2&!3&4&!5&6&!7 | !0&!1&2&3&!4&!5&!6&7 | !0&!1&2&3&!4&!5&6&!7 | !0&1&!2&!3&!4&5&!6&7 | !0&1&!2&!3&!4&5&6&!7 | !0&1&!2&!3&4&!5&!6&7 | !0&1&!2&!3&4&!5&6&!7 | !0&1&!2&3&!4&!5&!6&7 | !0&1&!2&3&!4&!5&6&!7 | 0&!1&!2&!3&!4&5&!6&7 | 0&!1&!2&!3&!4&5&6&!7 | 0&!1&!2&!3&4&!5&!6&7 | 0&!1&!2&!3&4&!5&6&!7 | 0&!1&!2&3&!4&!5&!6&7 | 0&!1&!2&3&!4&!5&6&!7] 1\n", "--END--\"\"\"))\n", "\n", "def env_conditions(m):\n", " sp = spot.get_state_players(m)\n", " conds = []\n", " for e in m.edges():\n", " if sp[e.src]:\n", " continue\n", " if not e.cond in conds:\n", " conds.append(e.cond)\n", " return conds\n", "print(\"Conditions in orig machine: \", len(env_conditions(get_mealy())))\n", "ms = get_mealy()\n", "# Relabel only env\n", "spot.partitioned_game_relabel_here(ms, True, False, True, False)\n", "print(\"Conditions in relabeled machine: \", len(env_conditions(ms)))" ] }, { "cell_type": "code", "execution_count": 17, "id": "ee29da67", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Partitioned env letters: 13\n" ] } ], "source": [ "si = spot.synthesis_info()\n", "si.minimize_lvl = 3\n", "# Turn on relabeling\n", "si.opt.set(\"max_letter_mult\", 100000)\n", "\n", "mm, log = spot.minimize_mealy(get_mealy(), si, return_log=True)\n", "print(\"Partitioned env letters:\", log[\"n_letters_part\"][0])" ] }, { "cell_type": "code", "execution_count": 18, "id": "0aec8019", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Partitioned env letters: 0\n" ] } ], "source": [ "# Turn off relabeling\n", "si.opt.set(\"max_letter_mult\", 0)\n", "\n", "mm, log = spot.minimize_mealy(get_mealy(), si, return_log=True)\n", "print(\"Partitioned env letters:\", log[\"n_letters_part\"][0])" ] }, { "cell_type": "code", "execution_count": null, "id": "a92f4f43", "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.5" }, "vscode": { "interpreter": { "hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1" } } }, "nbformat": 4, "nbformat_minor": 5 }