python: add get_highlight_state and get_highlight_edge

* python/spot/impl.i: Here.
* tests/python/highlighting.ipynb: Test it.
* NEWS: Mention it.
This commit is contained in:
Alexandre Duret-Lutz 2023-12-06 16:38:56 +01:00
parent ba86dc6b18
commit 3c638f2a88
3 changed files with 119 additions and 47 deletions

3
NEWS
View file

@ -131,6 +131,9 @@ New in spot 2.11.6.dev (not yet released)
given state or edge. Use aut.remove_highlight_states() or given state or edge. Use aut.remove_highlight_states() or
aut.remove_highlight_edges() to remove all colors. (Issue #554.) aut.remove_highlight_edges() to remove all colors. (Issue #554.)
- Calling aut.get_hight_state(s) or get.highlight_edge(e) will
return the highlight color of that state/edge or None.
Bugs fixed: Bugs fixed:
- tgba_determinize()'s use_simulation option would cause it to - tgba_determinize()'s use_simulation option would cause it to

View file

@ -594,6 +594,14 @@ namespace std {
%} %}
// Must occur before the twa declaration // Must occur before the twa declaration
%typemap(out) unsigned* spot::twa::get_highlight_state,
unsigned* spot::twa::get_highlight_edge %{
if (!$1)
$result = SWIG_Py_Void();
else
$result = swig::from(*$1);
%}
%typemap(out) SWIGTYPE* spot::twa::get_product_states %{ %typemap(out) SWIGTYPE* spot::twa::get_product_states %{
if (!$1) if (!$1)
$result = SWIG_Py_Void(); $result = SWIG_Py_Void();
@ -1056,6 +1064,18 @@ static void* ptr_for_bdddict(PyObject* obj)
return self; return self;
} }
unsigned* get_highlight_state(unsigned state)
{
std::map<unsigned, unsigned>* hs =
self->get_named_prop<std::map<unsigned, unsigned>>("highlight-states");
if (!hs)
return nullptr;
auto it = hs->find(state);
if (it == hs->end())
return nullptr;
return &it->second;
}
twa* remove_highlight_states() twa* remove_highlight_states()
{ {
self->set_named_prop("highlight-states", nullptr); self->set_named_prop("highlight-states", nullptr);
@ -1084,6 +1104,18 @@ static void* ptr_for_bdddict(PyObject* obj)
return self; return self;
} }
unsigned* get_highlight_edge(unsigned edge)
{
std::map<unsigned, unsigned>* he =
self->get_named_prop<std::map<unsigned, unsigned>>("highlight-edges");
if (!he)
return nullptr;
auto it = he->find(edge);
if (it == he->end())
return nullptr;
return &it->second;
}
twa* remove_highlight_edges() twa* remove_highlight_edges()
{ {
self->set_named_prop("highlight-edges", nullptr); self->set_named_prop("highlight-edges", nullptr);

View file

@ -247,7 +247,7 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe86e410bd0> >" "<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe2982e4de0> >"
] ]
}, },
"execution_count": 4, "execution_count": 4,
@ -359,7 +359,7 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa; proxy of <Swig Object of type 'std::shared_ptr< spot::twa > *' at 0x7fe86e4110e0> >" "<spot.twa; proxy of <Swig Object of type 'std::shared_ptr< spot::twa > *' at 0x7fe2982e57d0> >"
] ]
}, },
"execution_count": 5, "execution_count": 5,
@ -469,7 +469,7 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe86e410bd0> >" "<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe2982e4de0> >"
] ]
}, },
"execution_count": 6, "execution_count": 6,
@ -549,6 +549,43 @@
"print(a.to_str('HOA', '1.1'))" "print(a.to_str('HOA', '1.1'))"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Querying highlights\n",
"\n",
"Use `get_highlight_state(s)` or `get_highlight_edge(e)` to retrieve the highlighting color of some state/edge. If no highlighting is present for this state/edge, `None` is returned."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"state 0: 0\n",
"state 1: 5\n",
"state 2: 5\n",
"edge 1: None\n",
"edge 2: 1\n",
"edge 3: None\n",
"edge 4: 1\n",
"edge 5: 1\n",
"edge 6: 2\n"
]
}
],
"source": [
"for i in range(0, a.num_states()):\n",
" print(\"state {}: {}\".format(i, a.get_highlight_state(i)))\n",
"for i in range(1, a.num_edges() + 1):\n",
" print(\"edge {}: {}\".format(i, a.get_highlight_edge(i)))"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
@ -565,7 +602,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -654,10 +691,10 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa; proxy of <Swig Object of type 'std::shared_ptr< spot::twa > *' at 0x7fe86e411e30> >" "<spot.twa; proxy of <Swig Object of type 'std::shared_ptr< spot::twa > *' at 0x7fe2982e6a30> >"
] ]
}, },
"execution_count": 8, "execution_count": 9,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -675,7 +712,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 10,
"metadata": { "metadata": {
"scrolled": true "scrolled": true
}, },
@ -766,10 +803,10 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa; proxy of <Swig Object of type 'std::shared_ptr< spot::twa > *' at 0x7fe86e411c50> >" "<spot.twa; proxy of <Swig Object of type 'std::shared_ptr< spot::twa > *' at 0x7fe2982e71e0> >"
] ]
}, },
"execution_count": 9, "execution_count": 10,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -791,7 +828,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -931,10 +968,10 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe86e4123a0> >" "<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe2982e6f10> >"
] ]
}, },
"execution_count": 10, "execution_count": 11,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -945,7 +982,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -970,7 +1007,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -986,7 +1023,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 14,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -1126,10 +1163,10 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe86e4123a0> >" "<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe2982e6f10> >"
] ]
}, },
"execution_count": 13, "execution_count": 14,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -1149,7 +1186,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 15,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -1464,7 +1501,7 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe86e4121f0> >" "<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe2982e6be0> >"
] ]
}, },
"metadata": {}, "metadata": {},
@ -1725,7 +1762,7 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe86e410f90> >" "<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe2982e67c0> >"
] ]
}, },
"metadata": {}, "metadata": {},
@ -1908,7 +1945,7 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe86e410ff0> >" "<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe2982e6610> >"
] ]
}, },
"metadata": {}, "metadata": {},
@ -1963,7 +2000,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": 16,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -2025,7 +2062,7 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe86e413030> >" "<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe2982e63a0> >"
] ]
}, },
"metadata": {}, "metadata": {},
@ -2080,7 +2117,7 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe86e412280> >" "<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe2982e52c0> >"
] ]
}, },
"metadata": {}, "metadata": {},
@ -2095,7 +2132,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16, "execution_count": 17,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -2174,10 +2211,10 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe86e412310> >" "<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe2982e66d0> >"
] ]
}, },
"execution_count": 16, "execution_count": 17,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -2188,7 +2225,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 18,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -2211,7 +2248,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": 19,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -2224,7 +2261,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": 20,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -2303,7 +2340,7 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe86e412310> >" "<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe2982e66d0> >"
] ]
}, },
"metadata": {}, "metadata": {},
@ -2368,7 +2405,7 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe86e413030> >" "<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe2982e63a0> >"
] ]
}, },
"metadata": {}, "metadata": {},
@ -2423,7 +2460,7 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe86e412280> >" "<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe2982e52c0> >"
] ]
}, },
"metadata": {}, "metadata": {},
@ -2443,7 +2480,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20, "execution_count": 21,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -2649,7 +2686,7 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.impl.twa_product; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_product > *' at 0x7fe86e413c00> >" "<spot.impl.twa_product; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_product > *' at 0x7fe2982e61c0> >"
] ]
}, },
"metadata": {}, "metadata": {},
@ -2734,7 +2771,7 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe86e4109c0> >" "<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe2982e5fe0> >"
] ]
}, },
"metadata": {}, "metadata": {},
@ -2831,7 +2868,7 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe86e413bd0> >" "<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe2982e78a0> >"
] ]
}, },
"metadata": {}, "metadata": {},
@ -2860,7 +2897,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 21, "execution_count": 22,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -3000,10 +3037,10 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe86e412b50> >" "<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe2982e7030> >"
] ]
}, },
"execution_count": 21, "execution_count": 22,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -3028,7 +3065,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": 23,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -3168,10 +3205,10 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe86e412b50> >" "<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe2982e7030> >"
] ]
}, },
"execution_count": 22, "execution_count": 23,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -3191,7 +3228,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": 24,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -3331,7 +3368,7 @@
"</svg>\n" "</svg>\n"
], ],
"text/plain": [ "text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe86e412b50> >" "<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe2982e7030> >"
] ]
}, },
"metadata": {}, "metadata": {},
@ -3565,7 +3602,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 24, "execution_count": 25,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -3811,7 +3848,7 @@
"<spot.jupyter.SVG object>" "<spot.jupyter.SVG object>"
] ]
}, },
"execution_count": 24, "execution_count": 25,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }