acc_cond: rename is_tt/is_ff as is_t/is_f and add printer

* spot/twa/acc.cc, spot/twa/acc.hh: Here.
* spot/parseaut/parseaut.yy, spot/twa/acc.hh,
spot/twaalgos/gtec/gtec.cc, spot/twaalgos/hoa.cc,
spot/twaalgos/neverclaim.cc, spot/twaalgos/product.cc,
spot/twaalgos/remfin.cc, spot/twaalgos/strength.cc: Adjust.
* NEWS: Mention the changes.
* wrap/python/spot_impl.i: Bind acc_cond the printer.
* wrap/python/tests/acc_cond.ipynb: Add more examples.
This commit is contained in:
Alexandre Duret-Lutz 2015-12-17 08:42:34 +01:00
parent 2927cf38ac
commit 94cca9de3d
12 changed files with 259 additions and 44 deletions

View file

@ -1,7 +1,23 @@
{
"metadata": {
"name": "",
"signature": "sha256:f11212c3a17ce302ae81974af32b21c1ebda4aa54d8930f03787ce7ed1c9e5f5"
"kernelspec": {
"display_name": "Python 3",
"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.4.3+"
},
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
@ -920,7 +936,7 @@
"output_type": "pyout",
"prompt_number": 34,
"text": [
"<spot_impl.acc_cond; proxy of <Swig Object of type 'spot::acc_cond *' at 0x7f19407487e0> >"
"(4, (Fin(0) & Inf(1)) | (Fin(2) & Inf(3)))"
]
}
],
@ -970,17 +986,176 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"To be continued..."
"The `acc_cond` object can also be constructed using only a number of sets. In that case, the acceptance condition defaults to `t`, and it can be changed to something else later (using `set_acceptance()`). The number of acceptance sets can also be augmented with `add_sets()`."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"acc = spot.acc_cond(4)\n",
"acc"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 37,
"text": [
"(4, t)"
]
}
],
"prompt_number": 37
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"acc.add_sets(2)\n",
"acc"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 38,
"text": [
"(6, t)"
]
}
],
"prompt_number": 38
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"acc.set_acceptance(spot.parse_acc_code('Streett 2'))\n",
"acc"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 39,
"text": [
"(6, (Fin(0) | Inf(1)) & (Fin(2) | Inf(3)))"
]
}
],
"prompt_number": 39
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The common scenario of setting generalized B\u00fcchi acceptance can be achieved more efficiently as follows:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"acc = spot.acc_cond(4)\n",
"acc.set_generalized_buchi()\n",
"acc"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 40,
"text": [
"(4, Inf(0)&Inf(1)&Inf(2)&Inf(3))"
]
}
],
"prompt_number": 40
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `acc_cond` class has several methods for detecting acceptance conditions that match the named acceptance conditions of the HOA format. Note that in the HOA format, `Inf(0)&Inf(1)&Inf(2)&Inf(3)` is only called generalized B\u00fcchi if exactly for acceptance sets are used. So the following behavior should not be a surprise:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(acc)\n",
"print(acc.is_generalized_buchi())\n",
"acc.add_sets(1)\n",
"print(acc)\n",
"print(acc.is_generalized_buchi())"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"(4, Inf(0)&Inf(1)&Inf(2)&Inf(3))\n",
"True\n",
"(5, Inf(0)&Inf(1)&Inf(2)&Inf(3))\n",
"False\n"
]
}
],
"prompt_number": 41
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Similar methods like `is_t()`, `is_f()`, `is_buchi()`, `is_co_buchi()`, `is_generalized_co_buchi()` all return a Boolean.\n",
"\n",
"The `is_rabin()` and `is_streett()` methods, however, return a number of pairs. The number of pairs is always `num_sets()/2` on success, or -1 on failure."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"code = spot.parse_acc_code('Rabin 2')\n",
"acc = spot.acc_cond(code.used_sets().max_set(), code)\n",
"print(acc)\n",
"print(acc.is_rabin())\n",
"print(acc.is_streett())"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"(4, (Fin(0) & Inf(1)) | (Fin(2) & Inf(3)))\n",
"2\n",
"-1\n"
]
}
],
"prompt_number": 42
},
{
"cell_type": "code",
"collapsed": true,
"input": [],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 36
"prompt_number": null
}
],
"metadata": {}