Commit 8579bedf authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz

python: highlighting with vector of bools

* python/spot/__init__.py: Deal with vectors of bools.
* tests/python/highlighting.ipynb: Test this.
parent 95fd7594
......@@ -122,13 +122,25 @@ class twa:
return SVG(self._repr_svg_(opt))
def highlight_states(self, states, color):
for state in states:
self.highlight_state(state, color)
"""Highlight a list of states. This can be a list of
state numbers, or a list of Booleans."""
for idx, val in enumerate(states):
if type(val) is bool:
if val:
self.highlight_state(idx, color)
else:
self.highlight_state(val, color)
return self
def highlight_edges(self, edges, color):
for edge in edges:
self.highlight_edge(edge, color)
"""Highlight a list of edges. This can be a list of
edge numbers, or a list of Booleans."""
for idx, val in enumerate(edges):
if type(val) is bool:
if val:
self.highlight_edge(idx, color)
else:
self.highlight_edge(val, color)
return self
@_extend(twa)
......
......@@ -15,7 +15,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.3"
"version": "3.6.4"
},
"name": ""
},
......@@ -254,7 +254,7 @@
"</svg>\n"
],
"text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7efde042fbd0> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe1205e8990> >"
]
}
],
......@@ -356,12 +356,112 @@
"</svg>\n"
],
"text": [
"<spot.twa; proxy of <Swig Object of type 'std::shared_ptr< spot::twa > *' at 0x7efde03c0a50> >"
"<spot.twa; proxy of <Swig Object of type 'std::shared_ptr< spot::twa > *' at 0x7fe1205e8a80> >"
]
}
],
"prompt_number": 5
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The plural version can take a list or tuple of state numbers (as above) or of Booleans (as below). In the latter case the indices of the True values give the states to highlight."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"a.highlight_states([False, True, True], 5)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 6,
"svg": [
"<?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.38.0 (20140413.2041)\n",
" -->\n",
"<!-- Title: G Pages: 1 -->\n",
"<svg width=\"307pt\" height=\"139pt\"\n",
" viewBox=\"0.00 0.00 307.00 139.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 1) rotate(0) translate(4 135)\">\n",
"<title>G</title>\n",
"<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-135 303,-135 303,4 -4,4\"/>\n",
"<!-- I -->\n",
"<!-- 2 -->\n",
"<g id=\"node2\" class=\"node\"><title>2</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"#e31a1c\" stroke-width=\"2\" cx=\"56\" cy=\"-76\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"56\" y=\"-72.3\" font-family=\"Lato\" font-size=\"14.00\">2</text>\n",
"</g>\n",
"<!-- I&#45;&gt;2 -->\n",
"<g id=\"edge1\" class=\"edge\"><title>I&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M1.15491,-76C2.79388,-76 17.1543,-76 30.6317,-76\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"37.9419,-76 30.9419,-79.1501 34.4419,-76 30.9419,-76.0001 30.9419,-76.0001 30.9419,-76.0001 34.4419,-76 30.9418,-72.8501 37.9419,-76 37.9419,-76\"/>\n",
"</g>\n",
"<!-- 2&#45;&gt;2 -->\n",
"<g id=\"edge7\" class=\"edge\"><title>2&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"#ff7f00\" stroke-width=\"2\" d=\"M49.6208,-93.0373C48.3189,-102.858 50.4453,-112 56,-112 60.166,-112 62.4036,-106.858 62.7128,-100.143\"/>\n",
"<polygon fill=\"#ff7f00\" stroke=\"#ff7f00\" stroke-width=\"2\" points=\"62.3792,-93.0373 65.8541,-99.8818 63.0428,-96.51 63.207,-100.006 62.7076,-100.03 62.2081,-100.053 62.0439,-96.5569 59.561,-100.177 62.3792,-93.0373 62.3792,-93.0373\"/>\n",
"<text text-anchor=\"start\" x=\"38\" y=\"-115.8\" font-family=\"Lato\" font-size=\"14.00\">a &amp; !c</text>\n",
"</g>\n",
"<!-- 0 -->\n",
"<g id=\"node3\" class=\"node\"><title>0</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"#1f78b4\" stroke-width=\"2\" cx=\"277\" cy=\"-76\" rx=\"18\" ry=\"18\"/>\n",
"<ellipse fill=\"none\" stroke=\"#1f78b4\" stroke-width=\"2\" cx=\"277\" cy=\"-76\" rx=\"22\" ry=\"22\"/>\n",
"<text text-anchor=\"middle\" x=\"277\" y=\"-72.3\" font-family=\"Lato\" font-size=\"14.00\">0</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;0 -->\n",
"<g id=\"edge5\" class=\"edge\"><title>2&#45;&gt;0</title>\n",
"<path fill=\"none\" stroke=\"#ff4da0\" stroke-width=\"2\" d=\"M74.071,-77.7575C79.7664,-78.2653 86.1506,-78.7498 92,-79 147.13,-81.3584 211.623,-79.169 247.752,-77.4948\"/>\n",
"<polygon fill=\"#ff4da0\" stroke=\"#ff4da0\" stroke-width=\"2\" points=\"255.018,-77.1472 248.176,-80.6282 251.545,-77.8139 248.049,-77.9813 248.026,-77.4818 248.002,-76.9824 251.498,-76.8151 247.875,-74.3354 255.018,-77.1472 255.018,-77.1472\"/>\n",
"<text text-anchor=\"start\" x=\"190.5\" y=\"-82.8\" font-family=\"Lato\" font-size=\"14.00\">c</text>\n",
"</g>\n",
"<!-- 1 -->\n",
"<g id=\"node4\" class=\"node\"><title>1</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"#e31a1c\" stroke-width=\"2\" cx=\"194\" cy=\"-18\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"start\" x=\"189.5\" y=\"-14.3\" font-family=\"Lato\" font-size=\"14.00\">1</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;1 -->\n",
"<g id=\"edge6\" class=\"edge\"><title>2&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"#ff4da0\" stroke-width=\"2\" d=\"M72.8671,-69.2332C97.0256,-58.9303 143.124,-39.2707 170.658,-27.5281\"/>\n",
"<polygon fill=\"#ff4da0\" stroke=\"#ff4da0\" stroke-width=\"2\" points=\"177.234,-24.7237 172.031,-30.3673 174.211,-26.5567 170.991,-27.9297 170.795,-27.4698 170.599,-27.0099 173.818,-25.6369 169.559,-24.5723 177.234,-24.7237 177.234,-24.7237\"/>\n",
"<text text-anchor=\"start\" x=\"92\" y=\"-63.8\" font-family=\"Lato\" font-size=\"14.00\">!a &amp; b &amp; !c</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;0 -->\n",
"<g id=\"edge2\" class=\"edge\"><title>0&#45;&gt;0</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M269.317,-96.9908C268.369,-107.087 270.93,-116 277,-116 281.553,-116 284.131,-110.987 284.736,-104.22\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"284.683,-96.9908 287.884,-103.967 284.709,-100.491 284.734,-103.991 284.734,-103.991 284.734,-103.991 284.709,-100.491 281.585,-104.014 284.683,-96.9908 284.683,-96.9908\"/>\n",
"<text text-anchor=\"start\" x=\"272.5\" y=\"-119.8\" font-family=\"Lato\" font-size=\"14.00\">1</text>\n",
"</g>\n",
"<!-- 1&#45;&gt;0 -->\n",
"<g id=\"edge3\" class=\"edge\"><title>1&#45;&gt;0</title>\n",
"<path fill=\"none\" stroke=\"#ff4da0\" stroke-width=\"2\" d=\"M209.109,-28.1028C221.166,-36.7361 238.75,-49.3269 252.863,-59.4329\"/>\n",
"<polygon fill=\"#ff4da0\" stroke=\"#ff4da0\" stroke-width=\"2\" points=\"258.673,-63.5931 251.148,-62.0789 255.536,-61.962 252.691,-59.9243 252.982,-59.5178 253.273,-59.1113 256.119,-61.1489 254.816,-56.9566 258.673,-63.5931 258.673,-63.5931\"/>\n",
"<text text-anchor=\"start\" x=\"230\" y=\"-50.8\" font-family=\"Lato\" font-size=\"14.00\">c</text>\n",
"</g>\n",
"<!-- 1&#45;&gt;1 -->\n",
"<g id=\"edge4\" class=\"edge\"><title>1&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M187.266,-35.0373C185.892,-44.8579 188.137,-54 194,-54 198.397,-54 200.759,-48.8576 201.086,-42.1433\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"200.734,-35.0373 204.226,-41.8728 200.907,-38.533 201.08,-42.0287 201.08,-42.0287 201.08,-42.0287 200.907,-38.533 197.934,-42.1847 200.734,-35.0373 200.734,-35.0373\"/>\n",
"<text text-anchor=\"start\" x=\"175.5\" y=\"-57.8\" font-family=\"Lato\" font-size=\"14.00\">b &amp; !c</text>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe1205e8990> >"
]
}
],
"prompt_number": 6
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -414,7 +514,7 @@
"Acceptance: 1 Inf(0)\n",
"properties: trans-labels explicit-labels state-acc !complete\n",
"properties: deterministic stutter-invariant terminal\n",
"spot.highlight.states: 0 0 1 0\n",
"spot.highlight.states: 0 0 1 5 2 5\n",
"spot.highlight.edges: 2 1 4 1 5 1 6 2\n",
"--BODY--\n",
"State: 0 {0}\n",
......@@ -430,7 +530,7 @@
]
}
],
"prompt_number": 6
"prompt_number": 7
},
{
"cell_type": "markdown",
......@@ -455,7 +555,7 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 7,
"prompt_number": 8,
"svg": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
......@@ -571,11 +671,11 @@
"</svg>\n"
],
"text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7efde03c0930> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe12058d1b0> >"
]
}
],
"prompt_number": 7
"prompt_number": 8
},
{
"cell_type": "code",
......@@ -589,7 +689,7 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 8,
"prompt_number": 9,
"text": [
"Prefix:\n",
" 0\n",
......@@ -602,7 +702,7 @@
]
}
],
"prompt_number": 8
"prompt_number": 9
},
{
"cell_type": "code",
......@@ -613,7 +713,7 @@
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 9
"prompt_number": 10
},
{
"cell_type": "markdown",
......@@ -634,7 +734,7 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 10,
"prompt_number": 11,
"svg": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
......@@ -750,11 +850,11 @@
"</svg>\n"
],
"text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7efde03c0930> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe12058d1b0> >"
]
}
],
"prompt_number": 10
"prompt_number": 11
},
{
"cell_type": "markdown",
......@@ -830,7 +930,7 @@
"</svg>\n"
],
"text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7efde035c270> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe12058d2d0> >"
]
},
{
......@@ -876,11 +976,11 @@
"</svg>\n"
],
"text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7efde035c2d0> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe12058d150> >"
]
}
],
"prompt_number": 11
"prompt_number": 12
},
{
"cell_type": "code",
......@@ -894,7 +994,7 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 12,
"prompt_number": 13,
"svg": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
......@@ -962,11 +1062,11 @@
"</svg>\n"
],
"text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7efde03c09c0> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe12058d2a0> >"
]
}
],
"prompt_number": 12
"prompt_number": 13
},
{
"cell_type": "code",
......@@ -980,7 +1080,7 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 13,
"prompt_number": 14,
"text": [
"Prefix:\n",
" 1,0\n",
......@@ -993,7 +1093,7 @@
]
}
],
"prompt_number": 13
"prompt_number": 14
},
{
"cell_type": "code",
......@@ -1008,7 +1108,7 @@
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 14
"prompt_number": 15
},
{
"cell_type": "code",
......@@ -1089,7 +1189,7 @@
"</svg>\n"
],
"text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7efde03c09c0> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe12058d2a0> >"
]
},
{
......@@ -1146,7 +1246,7 @@
"</svg>\n"
],
"text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7efde035c270> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe12058d2d0> >"
]
},
{
......@@ -1192,11 +1292,11 @@
"</svg>\n"
],
"text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7efde035c2d0> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe12058d150> >"
]
}
],
"prompt_number": 15
"prompt_number": 16
},
{
"cell_type": "markdown",
......@@ -1399,7 +1499,7 @@
"</svg>\n"
],
"text": [
"<spot.impl.twa_product; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_product > *' at 0x7efde042fc00> >"
"<spot.impl.twa_product; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_product > *' at 0x7fe12058d210> >"
]
},
{
......@@ -1473,7 +1573,7 @@
"</svg>\n"
],
"text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7efde035c180> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe12058d1e0> >"
]
},
{
......@@ -1557,11 +1657,11 @@
"</svg>\n"
],
"text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7efde03c0990> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe12058d270> >"
]
}
],
"prompt_number": 16
"prompt_number": 17
},
{
"cell_type": "markdown",
......@@ -1587,7 +1687,7 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 17,
"prompt_number": 18,
"svg": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
......@@ -1703,11 +1803,11 @@
"</svg>\n"
],
"text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7efde035c750> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe12058d330> >"
]
}
],
"prompt_number": 17
"prompt_number": 18
},
{
"cell_type": "markdown",
......@@ -1732,7 +1832,7 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 18,
"prompt_number": 19,
"svg": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
......@@ -1848,11 +1948,11 @@
"</svg>\n"
],
"text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7efde035c750> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe12058d330> >"
]
}
],
"prompt_number": 18
"prompt_number": 19
},
{
"cell_type": "markdown",
......@@ -1991,7 +2091,7 @@
"</svg>\n"
],
"text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7efde035c750> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fe12058d330> >"
]
},
{
......@@ -2152,7 +2252,7 @@
]
}
],
"prompt_number": 19
"prompt_number": 20
},
{
"cell_type": "markdown",
......@@ -2177,7 +2277,7 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 20,
"prompt_number": 21,
"svg": [
"<svg height=\"360pt\" viewBox=\"0.00 0.00 652.06 360.00\" width=\"652pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g class=\"graph\" id=\"graph0\" transform=\"scale(0.882353 0.882353) rotate(0) translate(4 404)\">\n",
......@@ -2382,7 +2482,7 @@
]
}
],
"prompt_number": 20
"prompt_number": 21
}
],
"metadata": {}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment