spot/tests/python/_mealy.ipynb
Alexandre Duret-Lutz 75818fde13 synthesis: fix suboptimal colorization after LAR
* spot/twaalgos/synthesis.cc (ltl_to_game): In LAR and LAR_OLD mode,
for max odd and colorize the game after the split, not before.  The
previous code used to colorize twice, and could waste up to 4 colors
in the process.
* tests/core/ltlsynt.test, tests/python/_mealy.ipynb,
tests/python/games.ipynb, tests/python/synthesis.ipynb,
tests/python/synthesis.py: Adjust all test cases to reflect the fact
that the game uses fewer colors.
2022-03-17 16:44:48 +01:00

327 lines
15 KiB
Text

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "8bca10b8",
"metadata": {},
"outputs": [],
"source": [
"import spot\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": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.43.0 (0)\n",
" -->\n",
"<!-- Pages: 1 -->\n",
"<svg width=\"212pt\" height=\"212pt\"\n",
" viewBox=\"0.00 0.00 212.00 212.07\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1.0 1.0) rotate(0) translate(4 208.07)\">\n",
"<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-208.07 208,-208.07 208,4 -4,4\"/>\n",
"<text text-anchor=\"start\" x=\"54.5\" y=\"-189.87\" font-family=\"Lato\" font-size=\"14.00\">Inf(</text>\n",
"<text text-anchor=\"start\" x=\"75.5\" y=\"-189.87\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#ff4da0\">❶</text>\n",
"<text text-anchor=\"start\" x=\"91.5\" y=\"-189.87\" font-family=\"Lato\" font-size=\"14.00\">) | Fin(</text>\n",
"<text text-anchor=\"start\" x=\"129.5\" y=\"-189.87\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#1f78b4\">⓿</text>\n",
"<text text-anchor=\"start\" x=\"145.5\" y=\"-189.87\" font-family=\"Lato\" font-size=\"14.00\">)</text>\n",
"<text text-anchor=\"start\" x=\"70.5\" y=\"-175.87\" font-family=\"Lato\" font-size=\"14.00\">[Streett 1]</text>\n",
"<!-- I -->\n",
"<!-- 0 -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>0</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"#33a02c\" stroke-width=\"2\" cx=\"56\" cy=\"-75.07\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"56\" y=\"-71.37\" font-family=\"Lato\" font-size=\"14.00\">0</text>\n",
"</g>\n",
"<!-- I&#45;&gt;0 -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>I&#45;&gt;0</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M1.15,-75.07C2.79,-75.07 17.15,-75.07 30.63,-75.07\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"37.94,-75.07 30.94,-78.22 34.44,-75.07 30.94,-75.07 30.94,-75.07 30.94,-75.07 34.44,-75.07 30.94,-71.92 37.94,-75.07 37.94,-75.07\"/>\n",
"</g>\n",
"<!-- 1 -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>1</title>\n",
"<polygon fill=\"#ffffaa\" stroke=\"#33a02c\" stroke-width=\"2\" points=\"177,-133.07 150,-115.07 177,-97.07 204,-115.07 177,-133.07\"/>\n",
"<text text-anchor=\"middle\" x=\"177\" y=\"-111.37\" font-family=\"Lato\" font-size=\"14.00\">1</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;1 -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
"<title>0&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M62.13,-92.21C67.26,-105.97 76.64,-124.4 92,-133.07 111.84,-144.27 137.9,-135.7 155.7,-126.96\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"162.32,-123.52 157.56,-129.54 159.22,-125.13 156.11,-126.75 156.11,-126.75 156.11,-126.75 159.22,-125.13 154.66,-123.95 162.32,-123.52 162.32,-123.52\"/>\n",
"<text text-anchor=\"start\" x=\"92.5\" y=\"-156.87\" font-family=\"Lato\" font-size=\"14.00\">!a &amp; !c</text>\n",
"<text text-anchor=\"start\" x=\"104\" y=\"-141.87\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#ff4da0\">❶</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g id=\"node4\" class=\"node\">\n",
"<title>2</title>\n",
"<polygon fill=\"#ffffaa\" stroke=\"#33a02c\" stroke-width=\"2\" points=\"177,-53.07 150,-35.07 177,-17.07 204,-35.07 177,-53.07\"/>\n",
"<text text-anchor=\"middle\" x=\"177\" y=\"-31.37\" font-family=\"Lato\" font-size=\"14.00\">2</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;2 -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>0&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M70.12,-63.58C76.36,-58.69 84.15,-53.37 92,-50.07 108.69,-43.04 128.6,-39.3 144.85,-37.32\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"152.03,-36.52 145.42,-40.42 148.55,-36.91 145.07,-37.29 145.07,-37.29 145.07,-37.29 148.55,-36.91 144.73,-34.16 152.03,-36.52 152.03,-36.52\"/>\n",
"<text text-anchor=\"start\" x=\"99.5\" y=\"-68.87\" font-family=\"Lato\" font-size=\"14.00\">a | c</text>\n",
"<text text-anchor=\"start\" x=\"104\" y=\"-53.87\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#ff4da0\">❶</text>\n",
"</g>\n",
"<!-- 1&#45;&gt;0 -->\n",
"<g id=\"edge4\" class=\"edge\">\n",
"<title>1&#45;&gt;0</title>\n",
"<path fill=\"none\" stroke=\"#33a02c\" stroke-width=\"2\" d=\"M159.34,-108.84C151.13,-105.81 141.08,-102.17 132,-99.07 114.77,-93.18 95.16,-86.92 80.32,-82.27\"/>\n",
"<polygon fill=\"#33a02c\" stroke=\"#33a02c\" stroke-width=\"2\" points=\"73.45,-80.13 81.07,-79.21 76.94,-80.69 80.28,-81.74 80.13,-82.21 79.98,-82.69 76.64,-81.65 79.19,-85.22 73.45,-80.13 73.45,-80.13\"/>\n",
"<text text-anchor=\"start\" x=\"92\" y=\"-117.87\" font-family=\"Lato\" font-size=\"14.00\">!b &amp; !d</text>\n",
"<text text-anchor=\"start\" x=\"104\" y=\"-102.87\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#ff4da0\">❶</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;0 -->\n",
"<g id=\"edge5\" class=\"edge\">\n",
"<title>2&#45;&gt;0</title>\n",
"<path fill=\"none\" stroke=\"#33a02c\" stroke-width=\"2\" d=\"M164.73,-25.06C147.96,-11.43 115.84,9.67 92,-5.07 76.06,-14.92 67.14,-34.46 62.3,-50.4\"/>\n",
"<polygon fill=\"#33a02c\" stroke=\"#33a02c\" stroke-width=\"2\" points=\"60.35,-57.43 59.19,-49.84 60.81,-53.92 61.74,-50.55 62.22,-50.68 62.7,-50.82 61.77,-54.19 65.26,-51.52 60.35,-57.43 60.35,-57.43\"/>\n",
"<text text-anchor=\"start\" x=\"98.5\" y=\"-23.87\" font-family=\"Lato\" font-size=\"14.00\">b | d</text>\n",
"<text text-anchor=\"start\" x=\"104\" y=\"-8.87\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#ff4da0\">❶</text>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7f32ec50ce40> >"
]
},
"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": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.43.0 (0)\n",
" -->\n",
"<!-- Pages: 1 -->\n",
"<svg width=\"117pt\" height=\"126pt\"\n",
" viewBox=\"0.00 0.00 117.00 126.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1.0 1.0) rotate(0) translate(4 122)\">\n",
"<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-122 113,-122 113,4 -4,4\"/>\n",
"<!-- I -->\n",
"<!-- 0 -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>0</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"56\" cy=\"-18\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"56\" y=\"-14.3\" font-family=\"Lato\" font-size=\"14.00\">0</text>\n",
"</g>\n",
"<!-- I&#45;&gt;0 -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>I&#45;&gt;0</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M1.15,-18C2.79,-18 17.15,-18 30.63,-18\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"37.94,-18 30.94,-21.15 34.44,-18 30.94,-18 30.94,-18 30.94,-18 34.44,-18 30.94,-14.85 37.94,-18 37.94,-18\"/>\n",
"</g>\n",
"<!-- 0&#45;&gt;0 -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
"<title>0&#45;&gt;0</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M52.76,-35.78C52.21,-45.31 53.29,-54 56,-54 57.99,-54 59.1,-49.32 59.33,-43.05\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"59.24,-35.78 62.48,-42.74 59.28,-39.28 59.33,-42.78 59.33,-42.78 59.33,-42.78 59.28,-39.28 56.18,-42.82 59.24,-35.78 59.24,-35.78\"/>\n",
"<polygon fill=\"#e9f4fb\" stroke=\"transparent\" points=\"5,-55.5 5,-74.5 48,-74.5 48,-55.5 5,-55.5\"/>\n",
"<text text-anchor=\"start\" x=\"7\" y=\"-61.3\" font-family=\"Lato\" font-size=\"14.00\">!a &amp; !c</text>\n",
"<text text-anchor=\"start\" x=\"52\" y=\"-61.3\" font-family=\"Lato\" font-size=\"14.00\">/</text>\n",
"<polygon fill=\"#ffe5f1\" stroke=\"transparent\" points=\"63,-55.5 63,-74.5 107,-74.5 107,-55.5 63,-55.5\"/>\n",
"<text text-anchor=\"start\" x=\"65\" y=\"-61.3\" font-family=\"Lato\" font-size=\"14.00\">!b &amp; !d</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;0 -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>0&#45;&gt;0</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M50.83,-35.41C47.6,-54.42 49.32,-77 56,-77 61.84,-77 63.89,-59.71 62.15,-42.65\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"61.17,-35.41 65.23,-41.93 61.64,-38.88 62.11,-42.35 62.11,-42.35 62.11,-42.35 61.64,-38.88 58.98,-42.77 61.17,-35.41 61.17,-35.41\"/>\n",
"<polygon fill=\"#e9f4fb\" stroke=\"transparent\" points=\"19,-78.5 19,-97.5 48,-97.5 48,-78.5 19,-78.5\"/>\n",
"<text text-anchor=\"start\" x=\"21\" y=\"-84.3\" font-family=\"Lato\" font-size=\"14.00\">a | c</text>\n",
"<text text-anchor=\"start\" x=\"52\" y=\"-84.3\" font-family=\"Lato\" font-size=\"14.00\">/</text>\n",
"<polygon fill=\"#ffe5f1\" stroke=\"transparent\" points=\"63,-78.5 63,-97.5 94,-97.5 94,-78.5 63,-78.5\"/>\n",
"<text text-anchor=\"start\" x=\"65\" y=\"-84.3\" font-family=\"Lato\" font-size=\"14.00\">b | d</text>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7f32ec571c30> >"
]
},
"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": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.43.0 (0)\n",
" -->\n",
"<!-- Pages: 1 -->\n",
"<svg width=\"121pt\" height=\"106pt\"\n",
" viewBox=\"0.00 0.00 121.00 106.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1.0 1.0) rotate(0) translate(4 102)\">\n",
"<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-102 117,-102 117,4 -4,4\"/>\n",
"<!-- I -->\n",
"<!-- 0 -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>0</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"60\" cy=\"-18\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"60\" y=\"-14.3\" font-family=\"Lato\" font-size=\"14.00\">0</text>\n",
"</g>\n",
"<!-- I&#45;&gt;0 -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>I&#45;&gt;0</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M1.17,-18C3.01,-18 19.75,-18 34.75,-18\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"41.9,-18 34.9,-21.15 38.4,-18 34.9,-18 34.9,-18 34.9,-18 38.4,-18 34.9,-14.85 41.9,-18 41.9,-18\"/>\n",
"</g>\n",
"<!-- 0&#45;&gt;0 -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
"<title>0&#45;&gt;0</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M52.97,-34.66C51.41,-44.62 53.75,-54 60,-54 64.69,-54 67.18,-48.73 67.47,-41.89\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"67.03,-34.66 70.6,-41.46 67.24,-38.16 67.46,-41.65 67.46,-41.65 67.46,-41.65 67.24,-38.16 64.31,-41.84 67.03,-34.66 67.03,-34.66\"/>\n",
"<polygon fill=\"#e9f4fb\" stroke=\"transparent\" points=\"9,-77 9,-96 52,-96 52,-77 9,-77\"/>\n",
"<text text-anchor=\"start\" x=\"11\" y=\"-82.8\" font-family=\"Lato\" font-size=\"14.00\">!a &amp; !c</text>\n",
"<text text-anchor=\"start\" x=\"56\" y=\"-82.8\" font-family=\"Lato\" font-size=\"14.00\">/</text>\n",
"<polygon fill=\"#ffe5f1\" stroke=\"transparent\" points=\"67,-77 67,-96 111,-96 111,-77 67,-77\"/>\n",
"<text text-anchor=\"start\" x=\"69\" y=\"-82.8\" font-family=\"Lato\" font-size=\"14.00\">!b &amp; !d</text>\n",
"<polygon fill=\"#e9f4fb\" stroke=\"transparent\" points=\"9,-56 9,-75 52,-75 52,-56 9,-56\"/>\n",
"<text text-anchor=\"start\" x=\"25\" y=\"-61.8\" font-family=\"Lato\" font-size=\"14.00\">a | c</text>\n",
"<text text-anchor=\"start\" x=\"56\" y=\"-61.8\" font-family=\"Lato\" font-size=\"14.00\">/</text>\n",
"<polygon fill=\"#ffe5f1\" stroke=\"transparent\" points=\"67,-56 67,-75 111,-75 111,-56 67,-56\"/>\n",
"<text text-anchor=\"start\" x=\"69\" y=\"-61.8\" font-family=\"Lato\" font-size=\"14.00\">b | d</text>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7f32ec571c30> >"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x"
]
}
],
"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.9.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}