From 6b516df34a28c1c4aa5e84eeec882ac954889beb Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Fri, 13 Nov 2015 23:16:39 +0100 Subject: [PATCH] dot: display pairs of states for products * src/twaalgos/dot.cc: Here. * wrap/python/tests/automata.ipynb: Test it. * NEWS: Document this. --- NEWS | 5 + src/twaalgos/dot.cc | 22 +- wrap/python/tests/automata.ipynb | 397 +++++++++++++++++++++++++++++-- 3 files changed, 401 insertions(+), 23 deletions(-) diff --git a/NEWS b/NEWS index e2a376583..9f4f3c85d 100644 --- a/NEWS +++ b/NEWS @@ -48,6 +48,11 @@ New in spot 1.99.5a (not yet released) automata already tagged as "deterministic", and "inherently-weak" or "weak" even for automata tagged "weak" or "terminal". + * The dot output will display pair of states when displaying an + automaton built as an explicit product. This works in IPython + with spot.product() or spot.product_or() and in the shell with + autfilt's --product or --product-or options. + * Renamings: is_guarantee_automaton() -> is_terminal_automaton() tgba_run -> twa_run diff --git a/src/twaalgos/dot.cc b/src/twaalgos/dot.cc index 3b7476c02..e9de09c3f 100644 --- a/src/twaalgos/dot.cc +++ b/src/twaalgos/dot.cc @@ -56,6 +56,7 @@ namespace spot bool opt_html_labels_ = false; const_twa_graph_ptr aut_; std::vector* sn_ = nullptr; + std::vector>* sprod_ = nullptr; std::string* name_ = nullptr; acc_cond::mark_t inf_sets_ = 0U; acc_cond::mark_t fin_sets_ = 0U; @@ -385,6 +386,8 @@ namespace spot os_ << '"'; if (has_name) escape_str(os_, (*sn_)[s]); + else if (sprod_) + os_ << (*sprod_)[s].first << ',' << (*sprod_)[s].second; else os_ << s; if (acc) @@ -399,6 +402,8 @@ namespace spot os_ << '<'; if (has_name) escape_html(os_, (*sn_)[s]); + else if (sprod_) + os_ << (*sprod_)[s].first << ',' << (*sprod_)[s].second; else os_ << s; if (acc) @@ -416,6 +421,8 @@ namespace spot os_ << " " << s << " [label=\""; if (sn_ && s < sn_->size() && !(*sn_)[s].empty()) escape_str(os_, (*sn_)[s]); + else if (sprod_) + os_ << (*sprod_)[s].first << ',' << (*sprod_)[s].second; else os_ << s; os_ << '"'; @@ -466,13 +473,24 @@ namespace spot { aut_ = aut; if (opt_want_state_names_) - sn_ = aut->get_named_prop>("state-names"); + { + sn_ = aut->get_named_prop>("state-names"); + // We have no names. Do we have product sources? + if (!sn_) + { + sprod_ = aut->get_named_prop + >> + ("product-states"); + if (sprod_ && aut->num_states() != sprod_->size()) + sprod_ = nullptr; + } + } if (opt_name_) name_ = aut_->get_named_prop("automaton-name"); mark_states_ = !opt_force_acc_trans_ && aut_->prop_state_acc(); if (opt_shape_ == ShapeAuto) { - if (sn_ || aut->num_states() > 100) + if (sn_ || sprod_ || aut->num_states() > 100) opt_shape_ = ShapeEllipse; else opt_shape_ = ShapeCircle; diff --git a/wrap/python/tests/automata.ipynb b/wrap/python/tests/automata.ipynb index 80d4f1167..c576294be 100644 --- a/wrap/python/tests/automata.ipynb +++ b/wrap/python/tests/automata.ipynb @@ -17,8 +17,7 @@ "pygments_lexer": "ipython3", "version": "3.4.3+" }, - "name": "", - "signature": "sha256:d67ef646828999fe2beb805f3bb74087bbb30e12354c11fdfbe0f28c23bd7e5f" + "name": "" }, "nbformat": 3, "nbformat_minor": 0, @@ -178,7 +177,7 @@ "\n" ], "text": [ - " *' at 0x7f48d053f5d0> >" + " *' at 0x7faee805b4b0> >" ] } ], @@ -317,7 +316,7 @@ "" ], "text": [ - "" + "" ] } ], @@ -470,7 +469,7 @@ "" ], "text": [ - "" + "" ] } ], @@ -570,7 +569,7 @@ "\n" ], "text": [ - " *' at 0x7f48d05238d0> >" + " *' at 0x7faee8042780> >" ] } ], @@ -640,7 +639,7 @@ "\n" ], "text": [ - " *' at 0x7f48d05237e0> >" + " *' at 0x7faee8042600> >" ] } ], @@ -716,7 +715,7 @@ "\n" ], "text": [ - " *' at 0x7f48d0523750> >" + " *' at 0x7faee8042660> >" ] } ], @@ -839,7 +838,7 @@ "" ], "text": [ - "" + "" ] } ], @@ -1029,7 +1028,7 @@ "" ], "text": [ - "" + "" ] } ], @@ -1176,7 +1175,7 @@ "\n" ], "text": [ - " *' at 0x7f48d0523ab0> >" + " *' at 0x7faee8042d80> >" ] } ], @@ -1277,7 +1276,7 @@ "\n" ], "text": [ - " *' at 0x7f48d0523870> >" + " *' at 0x7faee8042e40> >" ] } ], @@ -1395,7 +1394,7 @@ "\n" ], "text": [ - " *' at 0x7f48d05237b0> >" + " *' at 0x7faee80425a0> >" ] } ], @@ -1494,7 +1493,7 @@ "\n" ], "text": [ - " *' at 0x7f48d04c2120> >" + " *' at 0x7faee8042630> >" ] } ], @@ -1964,7 +1963,7 @@ "\n" ], "text": [ - " *' at 0x7f48d0523f30> >" + " *' at 0x7faee80423c0> >" ] } ], @@ -2161,7 +2160,7 @@ "" ], "text": [ - "" + "" ] }, { @@ -2286,7 +2285,7 @@ "" ], "text": [ - "" + "" ] }, { @@ -2428,7 +2427,7 @@ "" ], "text": [ - "" + "" ] }, { @@ -2579,7 +2578,7 @@ "\n" ], "text": [ - " *' at 0x7f48d0523780> >" + " *' at 0x7faee8042ed0> >" ] } ], @@ -2735,7 +2734,7 @@ "\n" ], "text": [ - " *' at 0x7f48d05236f0> >" + " *' at 0x7faee80426c0> >" ] } ], @@ -2805,11 +2804,367 @@ "\n" ], "text": [ - " *' at 0x7f48d0523510> >" + " *' at 0x7faedb3750f0> >" ] } ], "prompt_number": 22 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "a1 = spot.translate('a W c'); display(a1.show('.bat'))\n", + "a2 = spot.translate('a U b'); display(a2.show('.bat'))\n", + "# the product should display pairs of states, unless asked not to\n", + "p = spot.product(a1, a2); display(p.show('.bat')); display(p.show('.bat1'))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "display_data", + "svg": [ + "\n", + "\n", + "G\n", + "\n", + "Inf(\n", + "\u24ff\n", + ")\n", + "\n", + "\n", + "1\n", + "\n", + "1\n", + "\n", + "\n", + "I->1\n", + "\n", + "\n", + "\n", + "\n", + "1->1\n", + "\n", + "\n", + "a & !c\n", + "\u24ff\n", + "\n", + "\n", + "0\n", + "\n", + "0\n", + "\n", + "\n", + "1->0\n", + "\n", + "\n", + "c\n", + "\u24ff\n", + "\n", + "\n", + "0->0\n", + "\n", + "\n", + "1\n", + "\u24ff\n", + "\n", + "\n", + "" + ], + "text": [ + "" + ] + }, + { + "metadata": {}, + "output_type": "display_data", + "svg": [ + "\n", + "\n", + "G\n", + "\n", + "Inf(\n", + "\u24ff\n", + ")\n", + "\n", + "\n", + "1\n", + "\n", + "1\n", + "\n", + "\n", + "I->1\n", + "\n", + "\n", + "\n", + "\n", + "1->1\n", + "\n", + "\n", + "a & !b\n", + "\n", + "\n", + "0\n", + "\n", + "0\n", + "\n", + "\n", + "1->0\n", + "\n", + "\n", + "b\n", + "\n", + "\n", + "0->0\n", + "\n", + "\n", + "1\n", + "\u24ff\n", + "\n", + "\n", + "" + ], + "text": [ + "" + ] + }, + { + "metadata": {}, + "output_type": "display_data", + "svg": [ + "\n", + "\n", + "G\n", + "\n", + "Inf(\n", + "\u24ff\n", + ")&Inf(\n", + "\u2776\n", + ")\n", + "\n", + "\n", + "0\n", + "\n", + "1,1\n", + "\n", + "\n", + "I->0\n", + "\n", + "\n", + "\n", + "\n", + "0->0\n", + "\n", + "\n", + "a & !b & !c\n", + "\u24ff\n", + "\n", + "\n", + "1\n", + "\n", + "0,0\n", + "\n", + "\n", + "0->1\n", + "\n", + "\n", + "b & c\n", + "\u24ff\n", + "\n", + "\n", + "2\n", + "\n", + "0,1\n", + "\n", + "\n", + "0->2\n", + "\n", + "\n", + "a & !b & c\n", + "\u24ff\n", + "\n", + "\n", + "3\n", + "\n", + "1,0\n", + "\n", + "\n", + "0->3\n", + "\n", + "\n", + "a & b & !c\n", + "\u24ff\n", + "\n", + "\n", + "1->1\n", + "\n", + "\n", + "1\n", + "\u24ff\n", + "\u2776\n", + "\n", + "\n", + "2->1\n", + "\n", + "\n", + "b\n", + "\u24ff\n", + "\n", + "\n", + "2->2\n", + "\n", + "\n", + "a & !b\n", + "\u24ff\n", + "\n", + "\n", + "3->1\n", + "\n", + "\n", + "c\n", + "\u24ff\n", + "\u2776\n", + "\n", + "\n", + "3->3\n", + "\n", + "\n", + "a & !c\n", + "\u24ff\n", + "\u2776\n", + "\n", + "\n", + "" + ], + "text": [ + "" + ] + }, + { + "metadata": {}, + "output_type": "display_data", + "svg": [ + "\n", + "\n", + "G\n", + "\n", + "Inf(\n", + "\u24ff\n", + ")&Inf(\n", + "\u2776\n", + ")\n", + "\n", + "\n", + "0\n", + "\n", + "0\n", + "\n", + "\n", + "I->0\n", + "\n", + "\n", + "\n", + "\n", + "0->0\n", + "\n", + "\n", + "a & !b & !c\n", + "\u24ff\n", + "\n", + "\n", + "1\n", + "\n", + "1\n", + "\n", + "\n", + "0->1\n", + "\n", + "\n", + "b & c\n", + "\u24ff\n", + "\n", + "\n", + "2\n", + "\n", + "2\n", + "\n", + "\n", + "0->2\n", + "\n", + "\n", + "a & !b & c\n", + "\u24ff\n", + "\n", + "\n", + "3\n", + "\n", + "3\n", + "\n", + "\n", + "0->3\n", + "\n", + "\n", + "a & b & !c\n", + "\u24ff\n", + "\n", + "\n", + "1->1\n", + "\n", + "\n", + "1\n", + "\u24ff\n", + "\u2776\n", + "\n", + "\n", + "2->1\n", + "\n", + "\n", + "b\n", + "\u24ff\n", + "\n", + "\n", + "2->2\n", + "\n", + "\n", + "a & !b\n", + "\u24ff\n", + "\n", + "\n", + "3->1\n", + "\n", + "\n", + "c\n", + "\u24ff\n", + "\u2776\n", + "\n", + "\n", + "3->3\n", + "\n", + "\n", + "a & !c\n", + "\u24ff\n", + "\u2776\n", + "\n", + "\n", + "" + ], + "text": [ + "" + ] + } + ], + "prompt_number": 23 + }, + { + "cell_type": "code", + "collapsed": true, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": null } ], "metadata": {}