{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "c54c43ba",
"metadata": {},
"outputs": [],
"source": [
"import spot, buddy\n",
"spot.setup()\n",
"from spot.jupyter import display_inline"
]
},
{
"cell_type": "markdown",
"id": "0576f64a",
"metadata": {},
"source": [
"Additional testing for synthesis"
]
},
{
"cell_type": "markdown",
"id": "e25b7989",
"metadata": {},
"source": [
"Testing the different methods to solve"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "007107a6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"si = spot.synthesis_info()\n",
"si.s = spot.synthesis_info.algo_LAR # Use LAR algorithm\n",
"game = spot.ltl_to_game(\"G((F(i0) && F(i1))->(G(i1<->(X(o0)))))\", [\"o0\"], si)\n",
"spot.solve_game(game)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "a7859f19",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"HOA: v1\n",
"States: 21\n",
"Start: 0\n",
"AP: 3 \"i1\" \"i0\" \"o0\"\n",
"acc-name: all\n",
"Acceptance: 0 t\n",
"properties: trans-labels explicit-labels state-acc deterministic\n",
"spot-state-player: 0 0 1 0 1 0 1 0 1 0 1 1 1 1 0 1 1 1 1 1 1\n",
"controllable-AP: 2\n",
"--BODY--\n",
"State: 0\n",
"[!0&!1] 2\n",
"[!0&1] 4\n",
"[0&!1] 6\n",
"[0&1] 8\n",
"State: 1\n",
"[0&1] 13\n",
"[0&!1] 18\n",
"[!0&1] 19\n",
"[!0&!1] 20\n",
"State: 2\n",
"[t] 1\n",
"State: 3\n",
"[0] 13\n",
"[!0] 19\n",
"State: 4\n",
"[t] 3\n",
"State: 5\n",
"[!0&1] 10\n",
"[0&1] 11\n",
"[!0&!1] 15\n",
"[0&!1] 16\n",
"State: 6\n",
"[t] 5\n",
"State: 7\n",
"[!0] 10\n",
"[0] 11\n",
"State: 8\n",
"[t] 7\n",
"State: 9\n",
"[!0] 12\n",
"[0] 13\n",
"State: 10\n",
"[2] 9\n",
"State: 11\n",
"[2] 7\n",
"State: 12\n",
"[!2] 9\n",
"State: 13\n",
"[!2] 7\n",
"State: 14\n",
"[!0&1] 12\n",
"[0&1] 13\n",
"[!0&!1] 17\n",
"[0&!1] 18\n",
"State: 15\n",
"[2] 14\n",
"State: 16\n",
"[2] 5\n",
"State: 17\n",
"[!2] 14\n",
"State: 18\n",
"[!2] 5\n",
"State: 19\n",
"[!2] 3\n",
"State: 20\n",
"[!2] 1\n",
"--END--\n",
"HOA: v1\n",
"States: 7\n",
"Start: 0\n",
"AP: 3 \"i1\" \"i0\" \"o0\"\n",
"acc-name: all\n",
"Acceptance: 0 t\n",
"properties: trans-labels explicit-labels state-acc deterministic\n",
"controllable-AP: 2\n",
"--BODY--\n",
"State: 0\n",
"[!0&!1] 1\n",
"[!0&1] 2\n",
"[0&!1] 3\n",
"[0&1] 4\n",
"State: 1\n",
"[0&1&!2] 4\n",
"[0&!1&!2] 3\n",
"[!0&1&!2] 2\n",
"[!0&!1&!2] 1\n",
"State: 2\n",
"[0&!2] 4\n",
"[!0&!2] 2\n",
"State: 3\n",
"[!0&1&2] 5\n",
"[0&1&2] 4\n",
"[!0&!1&2] 6\n",
"[0&!1&2] 3\n",
"State: 4\n",
"[!0&2] 5\n",
"[0&2] 4\n",
"State: 5\n",
"[!0&!2] 5\n",
"[0&!2] 4\n",
"State: 6\n",
"[!0&1&!2] 5\n",
"[0&1&!2] 4\n",
"[!0&!1&!2] 6\n",
"[0&!1&!2] 3\n",
"--END--\n",
"HOA: v1\n",
"States: 21\n",
"Start: 0\n",
"AP: 3 \"i1\" \"i0\" \"o0\"\n",
"acc-name: all\n",
"Acceptance: 0 t\n",
"properties: trans-labels explicit-labels state-acc deterministic\n",
"spot-state-player: 0 0 1 0 1 0 1 0 1 0 1 1 1 1 0 1 1 1 1 1 1\n",
"controllable-AP: 2\n",
"--BODY--\n",
"State: 0\n",
"[!0&!1] 2\n",
"[!0&1] 4\n",
"[0&!1] 6\n",
"[0&1] 8\n",
"State: 1\n",
"[0&1] 13\n",
"[0&!1] 18\n",
"[!0&1] 19\n",
"[!0&!1] 20\n",
"State: 2\n",
"[t] 1\n",
"State: 3\n",
"[0] 13\n",
"[!0] 19\n",
"State: 4\n",
"[t] 3\n",
"State: 5\n",
"[!0&1] 10\n",
"[0&1] 11\n",
"[!0&!1] 15\n",
"[0&!1] 16\n",
"State: 6\n",
"[t] 5\n",
"State: 7\n",
"[!0] 10\n",
"[0] 11\n",
"State: 8\n",
"[t] 7\n",
"State: 9\n",
"[!0] 12\n",
"[0] 13\n",
"State: 10\n",
"[2] 9\n",
"State: 11\n",
"[2] 7\n",
"State: 12\n",
"[!2] 9\n",
"State: 13\n",
"[!2] 7\n",
"State: 14\n",
"[!0&1] 12\n",
"[0&1] 13\n",
"[!0&!1] 17\n",
"[0&!1] 18\n",
"State: 15\n",
"[2] 14\n",
"State: 16\n",
"[2] 5\n",
"State: 17\n",
"[!2] 14\n",
"State: 18\n",
"[!2] 5\n",
"State: 19\n",
"[!2] 3\n",
"State: 20\n",
"[!2] 1\n",
"--END--\n",
"HOA: v1\n",
"States: 21\n",
"Start: 0\n",
"AP: 3 \"i1\" \"i0\" \"o0\"\n",
"acc-name: all\n",
"Acceptance: 0 t\n",
"properties: trans-labels explicit-labels state-acc deterministic\n",
"spot-state-player: 0 0 1 0 1 0 1 0 1 0 1 1 1 1 0 1 1 1 1 1 1\n",
"controllable-AP: 2\n",
"--BODY--\n",
"State: 0\n",
"[!0&!1] 2\n",
"[!0&1] 4\n",
"[0&!1] 6\n",
"[0&1] 8\n",
"State: 1\n",
"[0&1] 13\n",
"[0&!1] 18\n",
"[!0&1] 19\n",
"[!0&!1] 20\n",
"State: 2\n",
"[t] 1\n",
"State: 3\n",
"[0] 13\n",
"[!0] 19\n",
"State: 4\n",
"[t] 3\n",
"State: 5\n",
"[!0&1] 10\n",
"[0&1] 11\n",
"[!0&!1] 15\n",
"[0&!1] 16\n",
"State: 6\n",
"[t] 5\n",
"State: 7\n",
"[!0] 10\n",
"[0] 11\n",
"State: 8\n",
"[t] 7\n",
"State: 9\n",
"[!0] 12\n",
"[0] 13\n",
"State: 10\n",
"[2] 9\n",
"State: 11\n",
"[2] 7\n",
"State: 12\n",
"[!2] 9\n",
"State: 13\n",
"[!2] 7\n",
"State: 14\n",
"[!0&1] 12\n",
"[0&1] 13\n",
"[!0&!1] 17\n",
"[0&!1] 18\n",
"State: 15\n",
"[2] 14\n",
"State: 16\n",
"[2] 5\n",
"State: 17\n",
"[!2] 14\n",
"State: 18\n",
"[!2] 5\n",
"State: 19\n",
"[!2] 3\n",
"State: 20\n",
"[!2] 1\n",
"--END--\n",
"HOA: v1\n",
"States: 7\n",
"Start: 0\n",
"AP: 3 \"i1\" \"i0\" \"o0\"\n",
"acc-name: all\n",
"Acceptance: 0 t\n",
"properties: trans-labels explicit-labels state-acc deterministic\n",
"controllable-AP: 2\n",
"--BODY--\n",
"State: 0\n",
"[!0&!1] 1\n",
"[!0&1] 2\n",
"[0&!1] 3\n",
"[0&1] 4\n",
"State: 1\n",
"[0&1&!2] 4\n",
"[0&!1&!2] 3\n",
"[!0&1&!2] 2\n",
"[!0&!1&!2] 1\n",
"State: 2\n",
"[0&!2] 4\n",
"[!0&!2] 2\n",
"State: 3\n",
"[!0&1&2] 5\n",
"[0&1&2] 4\n",
"[!0&!1&2] 6\n",
"[0&!1&2] 3\n",
"State: 4\n",
"[!0&2] 5\n",
"[0&2] 4\n",
"State: 5\n",
"[!0&!2] 5\n",
"[0&!2] 4\n",
"State: 6\n",
"[!0&1&!2] 5\n",
"[0&1&!2] 4\n",
"[!0&!1&!2] 6\n",
"[0&!1&!2] 3\n",
"--END--\n",
"HOA: v1\n",
"States: 21\n",
"Start: 0\n",
"AP: 3 \"i1\" \"i0\" \"o0\"\n",
"acc-name: all\n",
"Acceptance: 0 t\n",
"properties: trans-labels explicit-labels state-acc deterministic\n",
"spot-state-player: 0 0 1 0 1 0 1 0 1 0 1 1 1 1 0 1 1 1 1 1 1\n",
"controllable-AP: 2\n",
"--BODY--\n",
"State: 0\n",
"[!0&!1] 2\n",
"[!0&1] 4\n",
"[0&!1] 6\n",
"[0&1] 8\n",
"State: 1\n",
"[0&1] 13\n",
"[0&!1] 18\n",
"[!0&1] 19\n",
"[!0&!1] 20\n",
"State: 2\n",
"[t] 1\n",
"State: 3\n",
"[0] 13\n",
"[!0] 19\n",
"State: 4\n",
"[t] 3\n",
"State: 5\n",
"[!0&1] 10\n",
"[0&1] 11\n",
"[!0&!1] 15\n",
"[0&!1] 16\n",
"State: 6\n",
"[t] 5\n",
"State: 7\n",
"[!0] 10\n",
"[0] 11\n",
"State: 8\n",
"[t] 7\n",
"State: 9\n",
"[!0] 12\n",
"[0] 13\n",
"State: 10\n",
"[2] 9\n",
"State: 11\n",
"[2] 7\n",
"State: 12\n",
"[!2] 9\n",
"State: 13\n",
"[!2] 7\n",
"State: 14\n",
"[!0&1] 12\n",
"[0&1] 13\n",
"[!0&!1] 17\n",
"[0&!1] 18\n",
"State: 15\n",
"[2] 14\n",
"State: 16\n",
"[2] 5\n",
"State: 17\n",
"[!2] 14\n",
"State: 18\n",
"[!2] 5\n",
"State: 19\n",
"[!2] 3\n",
"State: 20\n",
"[!2] 1\n",
"--END--\n",
"HOA: v1\n",
"States: 21\n",
"Start: 0\n",
"AP: 3 \"i1\" \"i0\" \"o0\"\n",
"acc-name: all\n",
"Acceptance: 0 t\n",
"properties: trans-labels explicit-labels state-acc deterministic\n",
"spot-state-player: 0 0 1 0 1 0 1 0 1 0 1 1 1 1 0 1 1 1 1 1 1\n",
"controllable-AP: 2\n",
"--BODY--\n",
"State: 0\n",
"[!0&!1] 2\n",
"[!0&1] 4\n",
"[0&!1] 6\n",
"[0&1] 8\n",
"State: 1\n",
"[0&1] 13\n",
"[0&!1] 18\n",
"[!0&1] 19\n",
"[!0&!1] 20\n",
"State: 2\n",
"[t] 1\n",
"State: 3\n",
"[0] 13\n",
"[!0] 19\n",
"State: 4\n",
"[t] 3\n",
"State: 5\n",
"[!0&1] 10\n",
"[0&1] 11\n",
"[!0&!1] 15\n",
"[0&!1] 16\n",
"State: 6\n",
"[t] 5\n",
"State: 7\n",
"[!0] 10\n",
"[0] 11\n",
"State: 8\n",
"[t] 7\n",
"State: 9\n",
"[!0] 12\n",
"[0] 13\n",
"State: 10\n",
"[2] 9\n",
"State: 11\n",
"[2] 7\n",
"State: 12\n",
"[!2] 9\n",
"State: 13\n",
"[!2] 7\n",
"State: 14\n",
"[!0&1] 12\n",
"[0&1] 13\n",
"[!0&!1] 17\n",
"[0&!1] 18\n",
"State: 15\n",
"[2] 14\n",
"State: 16\n",
"[2] 5\n",
"State: 17\n",
"[!2] 14\n",
"State: 18\n",
"[!2] 5\n",
"State: 19\n",
"[!2] 3\n",
"State: 20\n",
"[!2] 1\n",
"--END--\n",
"HOA: v1\n",
"States: 7\n",
"Start: 0\n",
"AP: 3 \"i1\" \"i0\" \"o0\"\n",
"acc-name: all\n",
"Acceptance: 0 t\n",
"properties: trans-labels explicit-labels state-acc deterministic\n",
"controllable-AP: 2\n",
"--BODY--\n",
"State: 0\n",
"[!0&!1] 1\n",
"[!0&1] 2\n",
"[0&!1] 3\n",
"[0&1] 4\n",
"State: 1\n",
"[0&1&!2] 4\n",
"[0&!1&!2] 3\n",
"[!0&1&!2] 2\n",
"[!0&!1&!2] 1\n",
"State: 2\n",
"[0&!2] 4\n",
"[!0&!2] 2\n",
"State: 3\n",
"[!0&1&2] 5\n",
"[0&1&2] 4\n",
"[!0&!1&2] 6\n",
"[0&!1&2] 3\n",
"State: 4\n",
"[!0&2] 5\n",
"[0&2] 4\n",
"State: 5\n",
"[!0&!2] 5\n",
"[0&!2] 4\n",
"State: 6\n",
"[!0&1&!2] 5\n",
"[0&1&!2] 4\n",
"[!0&!1&!2] 6\n",
"[0&!1&!2] 3\n",
"--END--\n",
"HOA: v1\n",
"States: 21\n",
"Start: 0\n",
"AP: 3 \"i1\" \"i0\" \"o0\"\n",
"acc-name: all\n",
"Acceptance: 0 t\n",
"properties: trans-labels explicit-labels state-acc deterministic\n",
"spot-state-player: 0 0 1 0 1 0 1 0 1 0 1 1 1 1 0 1 1 1 1 1 1\n",
"controllable-AP: 2\n",
"--BODY--\n",
"State: 0\n",
"[!0&!1] 2\n",
"[!0&1] 4\n",
"[0&!1] 6\n",
"[0&1] 8\n",
"State: 1\n",
"[0&1] 13\n",
"[0&!1] 18\n",
"[!0&1] 19\n",
"[!0&!1] 20\n",
"State: 2\n",
"[t] 1\n",
"State: 3\n",
"[0] 13\n",
"[!0] 19\n",
"State: 4\n",
"[t] 3\n",
"State: 5\n",
"[!0&1] 10\n",
"[0&1] 11\n",
"[!0&!1] 15\n",
"[0&!1] 16\n",
"State: 6\n",
"[t] 5\n",
"State: 7\n",
"[!0] 10\n",
"[0] 11\n",
"State: 8\n",
"[t] 7\n",
"State: 9\n",
"[!0] 12\n",
"[0] 13\n",
"State: 10\n",
"[2] 9\n",
"State: 11\n",
"[2] 7\n",
"State: 12\n",
"[!2] 9\n",
"State: 13\n",
"[!2] 7\n",
"State: 14\n",
"[!0&1] 12\n",
"[0&1] 13\n",
"[!0&!1] 17\n",
"[0&!1] 18\n",
"State: 15\n",
"[2] 14\n",
"State: 16\n",
"[2] 5\n",
"State: 17\n",
"[!2] 14\n",
"State: 18\n",
"[!2] 5\n",
"State: 19\n",
"[!2] 3\n",
"State: 20\n",
"[!2] 1\n",
"--END--\n"
]
}
],
"source": [
"si.minimize_lvl = 0\n",
"mm0 = spot.solved_game_to_mealy(game, si)\n",
"msep0 = spot.solved_game_to_separated_mealy(game, si)\n",
"msplit0 = spot.solved_game_to_split_mealy(game, si)\n",
"assert(spot.is_mealy(mm0))\n",
"assert(spot.is_separated_mealy(msep0))\n",
"assert(spot.is_split_mealy(msplit0))\n",
"print(mm0.to_str(\"hoa\"))\n",
"print(msep0.to_str(\"hoa\"))\n",
"print(msplit0.to_str(\"hoa\"))\n",
"si.minimize_lvl = 2\n",
"mm2 = spot.solved_game_to_mealy(game, si)\n",
"msep2 = spot.solved_game_to_separated_mealy(game, si)\n",
"msplit2 = spot.solved_game_to_split_mealy(game, si)\n",
"assert(spot.is_mealy(mm2))\n",
"assert(spot.is_separated_mealy(msep2))\n",
"assert(spot.is_split_mealy(msplit2))\n",
"print(mm2.to_str(\"hoa\"))\n",
"print(msep2.to_str(\"hoa\"))\n",
"print(msplit2.to_str(\"hoa\"))\n",
"si.minimize_lvl = 3\n",
"mm3 = spot.solved_game_to_mealy(game, si)\n",
"msep3 = spot.solved_game_to_separated_mealy(game, si)\n",
"msplit3 = spot.solved_game_to_split_mealy(game, si)\n",
"assert(spot.is_mealy(mm3))\n",
"assert(spot.is_separated_mealy(msep3))\n",
"assert(spot.is_split_mealy(msplit3))\n",
"print(mm3.to_str(\"hoa\"))\n",
"print(msep3.to_str(\"hoa\"))\n",
"print(msplit3.to_str(\"hoa\"))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "fb57ac53",
"metadata": {},
"outputs": [],
"source": [
"mus0 = spot.unsplit_mealy(msplit0)\n",
"mus2 = spot.unsplit_mealy(msplit2)\n",
"mus3 = spot.unsplit_mealy(msplit3)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "40fc65b5",
"metadata": {},
"outputs": [],
"source": [
"assert(mus0.equivalent_to(msep0))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "f6d8b29c",
"metadata": {},
"outputs": [],
"source": [
"assert(mus2.equivalent_to(msep2))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "db8d47f2",
"metadata": {},
"outputs": [],
"source": [
"assert(mus3.equivalent_to(msep3))"
]
},
{
"cell_type": "markdown",
"id": "c19beeb0",
"metadata": {},
"source": [
"Testing related to #495"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "3736cd1b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(0, t)\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc33a0f0> >"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = spot.translate(\"i<->o\", \"parity\")\n",
"print(a.acc())\n",
"a"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "da6a7802",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc33a0f0> >"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spot.set_synthesis_outputs(a, buddy.bdd_ithvar(a.register_ap(\"o\")))\n",
"a"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "987219a4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(0, t)\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc345660> >"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a_s = spot.split_2step(a, True)\n",
"print(a.acc())\n",
"a_s"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "958d81f2",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc3486c0> >"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = spot.make_twa_graph()\n",
"a.acc().set_acceptance(spot.acc_code.t())\n",
"i0 = buddy.bdd_ithvar(a.register_ap('i0'))\n",
"i1 = buddy.bdd_ithvar(a.register_ap('i1'))\n",
"o = buddy.bdd_ithvar(a.register_ap('o'))\n",
"tt = buddy.bddtrue\n",
"a0 = spot.mark_t([0])\n",
"a.new_states(3)\n",
"a.new_edge(0,1,i0&o,a0)\n",
"a.new_edge(1,0,i1,a0)\n",
"a.new_edge(1,2,i0&(buddy.bdd_not(o)),a0)\n",
"spot.set_synthesis_outputs(a, o)\n",
"a"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "078bb43e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(0, t)\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc345ae0> >"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a_snc = spot.split_2step(a, False)\n",
"print(a_snc.acc())\n",
"a_snc"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "05b4a138",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(1, Fin(0))\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc345e40> >"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a_s = spot.split_2step(a, True)\n",
"print(a_s.acc())\n",
"a_s"
]
},
{
"cell_type": "markdown",
"id": "0ee90b2a",
"metadata": {},
"source": [
"## A problematic case for merge\n",
"\n",
"This is an example graph for which the self-loop optimisation in merge_states does not work"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "06b20a8c",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc364a20> >"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"aut = spot.make_twa_graph()\n",
"aut.set_buchi()\n",
"aut.new_states(5)\n",
"\n",
"a = buddy.bdd_ithvar(aut.register_ap(\"a\"))\n",
"b = buddy.bdd_ithvar(aut.register_ap(\"b\"))\n",
"c = buddy.bdd_ithvar(aut.register_ap(\"c\"))\n",
"x = buddy.bdd_ithvar(aut.register_ap(\"x\"))\n",
"\n",
"\n",
"aut.new_edge(0, 1, buddy.bddtrue)\n",
"aut.new_edge(0, 4, buddy.bddtrue)\n",
"\n",
"# OK, edge conditions ensure \"correct\" ordering\n",
"aut.new_edge(1, 1, a)\n",
"aut.new_edge(1, 2, b)\n",
"aut.new_edge(1, 3, c)\n",
"\n",
"aut.new_edge(4, 4, a)\n",
"aut.new_edge(4, 2, b)\n",
"aut.new_edge(4, 3, c)\n",
"\n",
"aut.new_edge(2, 2, x)\n",
"aut.new_edge(3, 3, buddy.bdd_not(x))\n",
"\n",
"aut"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "8a2f2e4d",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc364a20> >"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"aut.merge_states()\n",
"aut"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "b40f8ce7",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc35a2d0> >"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"aut = spot.make_twa_graph()\n",
"aut.set_buchi()\n",
"aut.new_states(5)\n",
"\n",
"a = buddy.bdd_ithvar(aut.register_ap(\"a\"))\n",
"b = buddy.bdd_ithvar(aut.register_ap(\"b\"))\n",
"c = buddy.bdd_ithvar(aut.register_ap(\"c\"))\n",
"x = buddy.bdd_ithvar(aut.register_ap(\"x\"))\n",
"\n",
"\n",
"aut.new_edge(0, 1, buddy.bddtrue)\n",
"aut.new_edge(0, 4, buddy.bddtrue)\n",
"\n",
"# Not OK, all edge equal -> sorted by destination\n",
"# Fails to merge\n",
"aut.new_edge(1, 1, a)\n",
"aut.new_edge(1, 2, a)\n",
"aut.new_edge(1, 3, a)\n",
"\n",
"aut.new_edge(4, 4, a)\n",
"aut.new_edge(4, 2, a)\n",
"aut.new_edge(4, 3, a)\n",
"\n",
"aut.new_edge(2, 2, x)\n",
"aut.new_edge(3, 3, buddy.bdd_not(x))\n",
"\n",
"aut"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "1f596284",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc35a2d0> >"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"aut.merge_states()\n",
"aut"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "761b4c96",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc35af00> >"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"aut = spot.make_twa_graph()\n",
"aut.set_buchi()\n",
"aut.new_states(8)\n",
"\n",
"a = buddy.bdd_ithvar(aut.register_ap(\"a\"))\n",
"b = buddy.bdd_ithvar(aut.register_ap(\"b\"))\n",
"c = buddy.bdd_ithvar(aut.register_ap(\"c\"))\n",
"x = buddy.bdd_ithvar(aut.register_ap(\"x\"))\n",
"\n",
"\n",
"aut.new_edge(0, 1, buddy.bddtrue)\n",
"aut.new_edge(0, 4, buddy.bddtrue)\n",
"\n",
"aut.new_edge(1, 1, a)\n",
"aut.new_edge(1, 2, b)\n",
"aut.new_edge(1, 3, c)\n",
"\n",
"aut.new_edge(4, 4, a)\n",
"aut.new_edge(4, 2, b)\n",
"aut.new_edge(4, 3, c)\n",
"\n",
"aut.new_edge(2, 2, x)\n",
"aut.new_edge(3, 3, buddy.bdd_not(x))\n",
"\n",
"aut.new_edge(5, 1, a)\n",
"aut.new_edge(5, 2, b)\n",
"aut.new_edge(5, 3, c)\n",
"\n",
"display(aut.show_storage())\n",
"aut"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "d4e09261",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc35af00> >"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"aut.merge_states()\n",
"aut"
]
},
{
"cell_type": "markdown",
"id": "4a8ace82",
"metadata": {},
"source": [
"## Splitting can inhibit merging\n",
"\n",
"In split automata, no self-loops exist.\n",
"Therefore states that can be merged pre-split can not be merged in a split automaton"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "c9e38db9",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc36d240> >"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc3910f0> >"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"aut = spot.make_twa_graph()\n",
"aut.set_buchi()\n",
"aut.new_states(5)\n",
"\n",
"a = buddy.bdd_ithvar(aut.register_ap(\"a\"))\n",
"b = buddy.bdd_ithvar(aut.register_ap(\"b\"))\n",
"c = buddy.bdd_ithvar(aut.register_ap(\"c\"))\n",
"x = buddy.bdd_ithvar(aut.register_ap(\"x\"))\n",
"\n",
"\n",
"aut.new_edge(0, 1, buddy.bddtrue)\n",
"aut.new_edge(0, 4, buddy.bddtrue)\n",
"\n",
"aut.new_edge(1, 1, a)\n",
"aut.new_edge(1, 2, b)\n",
"aut.new_edge(1, 3, c)\n",
"\n",
"aut.new_edge(4, 4, a)\n",
"aut.new_edge(4, 2, b)\n",
"aut.new_edge(4, 3, c)\n",
"\n",
"aut.new_edge(2, 2, x)\n",
"aut.new_edge(3, 3, buddy.bdd_not(x))\n",
"\n",
"display(aut)\n",
"\n",
"aut = spot.split_2step(aut, x, False)\n",
"\n",
"display(aut.show_storage())\n",
"aut"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "2009f279",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc3910f0> >"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print(aut.merge_states())\n",
"aut"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "17c8d6bc",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc364570> >"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc35a9c0> >"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Merging possible even in split case\n",
"aut = spot.make_twa_graph()\n",
"aut.set_buchi()\n",
"aut.new_states(5)\n",
"\n",
"a = buddy.bdd_ithvar(aut.register_ap(\"a\"))\n",
"b = buddy.bdd_ithvar(aut.register_ap(\"b\"))\n",
"c = buddy.bdd_ithvar(aut.register_ap(\"c\"))\n",
"x = buddy.bdd_ithvar(aut.register_ap(\"x\"))\n",
"\n",
"\n",
"aut.new_edge(0, 1, buddy.bddtrue)\n",
"aut.new_edge(0, 4, buddy.bddtrue)\n",
"\n",
"aut.new_edge(1, 2, b)\n",
"aut.new_edge(1, 3, c)\n",
"\n",
"aut.new_edge(4, 2, b)\n",
"aut.new_edge(4, 3, c)\n",
"\n",
"aut.new_edge(2, 2, x)\n",
"aut.new_edge(3, 3, buddy.bdd_not(x))\n",
"\n",
"display(aut)\n",
"\n",
"aut = spot.split_2step(aut, x, False)\n",
"\n",
"display(aut.show_storage())\n",
"aut"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "b3e90235",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc35a9c0> >"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print(aut.merge_states())\n",
"aut"
]
},
{
"cell_type": "markdown",
"id": "05785bb1",
"metadata": {},
"source": [
"Fail case for alternate_players"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "df4aa681",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc3646c0> >"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc3646c0> >"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"aut = spot.make_twa_graph()\n",
"aut.set_buchi()\n",
"i = buddy.bdd_ithvar(aut.register_ap(\"i\"))\n",
"o = buddy.bdd_ithvar(aut.register_ap(\"o\"))\n",
"\n",
"spot.set_synthesis_outputs(aut, o)\n",
"\n",
"aut.new_states(2)\n",
"aut.new_edge(0,1,i)\n",
"aut.new_edge(1,0,o,spot.mark_t([0]))\n",
"display(aut)\n",
"spot.alternate_players(aut)\n",
"display(aut)"
]
},
{
"cell_type": "markdown",
"id": "7efe7450",
"metadata": {},
"source": [
"# Test improved aiger INF encoding"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "31872ccc",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc3911e0> >"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"si = spot.synthesis_info()\n",
"\n",
"aut = spot.ltl_to_game(\"(a|b|c|d)->x\", [\"x\"], si)\n",
"aut"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "9064bc60",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"print(spot.solve_game(aut))"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "303ada1e",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbcd407ca20> >"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ctrl = spot.solved_game_to_split_mealy(aut)\n",
"ctrl"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "9874a530",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
" *' at 0x7fbccc33adb0> >"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"aig = spot.mealy_machine_to_aig(ctrl, \"ite\")\n",
"aig"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "eb81b7d3",
"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.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}