Commit 510a18b1 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz

acc: introduce top_conjuncts() and top_disjuncts()

* spot/twa/acc.cc, spot/twa/acc.hh: Add the new functions.
* python/spot/impl.i: Add bindings.
* tests/python/acc_cond.ipynb: Add tests.
* NEWS: Mention it.
parent 55c50c65
Pipeline #7580 passed with stage
in 63 minutes and 22 seconds
......@@ -20,6 +20,10 @@ New in spot 2.7.2.dev (not yet released)
'ltldo ltl2dstar -f 'GFa -> GFb' | autfilt --small' produces 1
state instead of 4.)
- acc_cond::acc_code::top_disjuncts() and
acc_cond::acc_code::top_conjuncts() can be used to split an
acceptance condition on the top-level & or |.
Bugs fixed:
- When processing CSV files with MSDOS-style \r\n line endings,
......
......@@ -473,6 +473,7 @@ namespace std {
%template(vectorformula) vector<spot::formula>;
%template(vectorunsigned) vector<unsigned>;
%template(vectorpairunsigned) vector<pair<unsigned, unsigned>>;
%template(vectoracccode) vector<spot::acc_cond::acc_code>;
%template(vectorbool) vector<bool>;
%template(vectorbdd) vector<bdd>;
%template(vectorstring) vector<string>;
......
// -*- coding: utf-8 -*-
// Copyright (C) 2015-2018 Laboratoire de Recherche et Développement
// Copyright (C) 2015-2019 Laboratoire de Recherche et Développement
// de l'Epita.
//
// This file is part of Spot, a model checking library.
......@@ -1232,6 +1232,74 @@ namespace spot
return rescode;
}
namespace
{
static std::vector<acc_cond::acc_code>
top_clauses(const acc_cond::acc_code& code,
acc_cond::acc_op connect, acc_cond::acc_op inf_fin)
{
std::vector<acc_cond::acc_code> res;
if (!code.empty())
{
auto pos = &code.back();
auto start = &code.front();
assert(pos - pos->sub.size == start);
if (pos->sub.op == connect)
{
do
{
--pos;
if (pos->sub.op == inf_fin)
{
for (unsigned d: pos[-1].mark.sets())
{
acc_cond::acc_code tmp;
tmp.resize(2);
tmp[0].mark = {d};
tmp[1].sub.op = inf_fin;
tmp[1].sub.size = 1;
res.emplace_back(tmp);
}
}
else
{
res.emplace_back(pos);
}
pos -= pos->sub.size;
}
while (pos > start);
return res;
}
if (pos->sub.op == inf_fin)
{
for (unsigned d: pos[-1].mark.sets())
{
acc_cond::acc_code tmp;
tmp.resize(2);
tmp[0].mark = {d};
tmp[1].sub.op = inf_fin;
tmp[1].sub.size = 1;
res.emplace_back(tmp);
}
return res;
}
}
res.emplace_back(code);
return res;
}
}
std::vector<acc_cond::acc_code> acc_cond::acc_code::top_disjuncts() const
{
return top_clauses(*this, acc_cond::acc_op::Or, acc_cond::acc_op::Fin);
}
std::vector<acc_cond::acc_code> acc_cond::acc_code::top_conjuncts() const
{
return top_clauses(*this, acc_cond::acc_op::And, acc_cond::acc_op::Inf);
}
std::pair<bool, acc_cond::mark_t>
acc_cond::sat_unsat_mark(bool sat) const
{
......
// -*- coding: utf-8 -*-
// Copyright (C) 2014-2018 Laboratoire de Recherche et Développement
// Copyright (C) 2014-2019 Laboratoire de Recherche et Développement
// de l'Epita.
//
// This file is part of Spot, a model checking library.
......@@ -1120,6 +1120,27 @@ namespace spot
/// This implementation is the dual of `to_dnf()`.
acc_code to_cnf() const;
/// \brief Return the top-level disjuncts.
///
/// For instance, if the formula is
/// Fin(0)|Fin(1)|(Fin(2)&(Inf(3)|Fin(4))), this returns
/// [Fin(0), Fin(1), Fin(2)&(Inf(3)|Fin(4))].
///
/// If the formula is not a disjunction, this returns
/// a vector with the formula as only element.
std::vector<acc_code> top_disjuncts() const;
/// \brief Return the top-level conjuncts.
///
/// For instance, if the formula is
/// Fin(0)|Fin(1)|(Fin(2)&(Inf(3)|Fin(4))), this returns
/// [Fin(0), Fin(1), Fin(2)&(Inf(3)|Fin(4))].
///
/// If the formula is not a conjunction, this returns
/// a vector with the formula as only element.
std::vector<acc_code> top_conjuncts() const;
/// \brief Complement an acceptance formula.
///
/// Also known as "dualizing the acceptance condition" since
......
......@@ -817,6 +817,41 @@
"acc.used_inf_fin_sets()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If the top-level operators is a conjunct or disjunct, the following methods returns lists of clauses."
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"spot.acc_code(\"(Fin(0)|Fin(3)) | (Inf(1) & Fin(2))\")\n",
"(spot.acc_code(\"Fin(0)\"), spot.acc_code(\"Fin(3)\"), spot.acc_code(\"Inf(1) & Fin(2)\"))\n",
"spot.acc_code(\"(Inf(0)&Inf(1)) & (Fin(2)|Fin(3))\")\n",
"(spot.acc_code(\"Inf(0)\"), spot.acc_code(\"Inf(1)\"), spot.acc_code(\"Fin(2)|Fin(3)\"))\n",
"(spot.acc_code(\"(Inf(0)&Inf(1)) & (Fin(2)|Fin(3))\"),)\n"
]
}
],
"source": [
"c = spot.acc_code('Fin(0)|(Inf(1)&Fin(2))|Fin(3)')\n",
"print(repr(c))\n",
"print(c.top_disjuncts())\n",
"c = spot.acc_code('Inf(0)&Inf(1)&(Fin(2)|Fin(3))')\n",
"print(repr(c))\n",
"print(c.top_conjuncts())\n",
"# Nothing to split here as the top operator is not a disjunction\n",
"print(c.top_disjuncts())"
]
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -833,7 +868,7 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 34,
"metadata": {},
"outputs": [
{
......@@ -842,7 +877,7 @@
"spot.acc_cond(4, \"(Fin(0) & Inf(1)) | (Fin(2) & Inf(3))\")"
]
},
"execution_count": 33,
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
......@@ -861,7 +896,7 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 35,
"metadata": {},
"outputs": [
{
......@@ -870,7 +905,7 @@
"spot.acc_cond(4, \"(Fin(0) & Inf(1)) | (Fin(2) & Inf(3))\")"
]
},
"execution_count": 34,
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
......@@ -882,7 +917,7 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": 36,
"metadata": {},
"outputs": [
{
......@@ -891,7 +926,7 @@
"4"
]
},
"execution_count": 35,
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
......@@ -902,7 +937,7 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 37,
"metadata": {},
"outputs": [
{
......@@ -911,7 +946,7 @@
"spot.acc_code(\"(Fin(0) & Inf(1)) | (Fin(2) & Inf(3))\")"
]
},
"execution_count": 36,
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
......@@ -929,7 +964,7 @@
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 38,
"metadata": {},
"outputs": [
{
......@@ -938,7 +973,7 @@
"spot.acc_cond(4, \"t\")"
]
},
"execution_count": 37,
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
......@@ -950,7 +985,7 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": 39,
"metadata": {},
"outputs": [
{
......@@ -959,7 +994,7 @@
"spot.acc_cond(6, \"t\")"
]
},
"execution_count": 38,
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
......@@ -971,7 +1006,7 @@
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 40,
"metadata": {},
"outputs": [
{
......@@ -980,7 +1015,7 @@
"spot.acc_cond(6, \"(Fin(0) | Inf(1)) & (Fin(2) | Inf(3))\")"
]
},
"execution_count": 39,
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
......@@ -999,7 +1034,7 @@
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": 41,
"metadata": {},
"outputs": [
{
......@@ -1008,7 +1043,7 @@
"spot.acc_cond(4, \"(Fin(0) | Inf(1)) & (Fin(2) | Inf(3))\")"
]
},
"execution_count": 40,
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1027,7 +1062,7 @@
},
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 42,
"metadata": {},
"outputs": [
{
......@@ -1036,7 +1071,7 @@
"spot.acc_cond(4, \"(Fin(0) | Inf(1)) & (Fin(2) | Inf(3))\")"
]
},
"execution_count": 41,
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1056,7 +1091,7 @@
},
{
"cell_type": "code",
"execution_count": 42,
"execution_count": 43,
"metadata": {},
"outputs": [
{
......@@ -1065,7 +1100,7 @@
"spot.acc_cond(4, \"Inf(0)&Inf(1)&Inf(2)&Inf(3)\")"
]
},
"execution_count": 42,
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1085,7 +1120,7 @@
},
{
"cell_type": "code",
"execution_count": 43,
"execution_count": 44,
"metadata": {},
"outputs": [
{
......@@ -1118,7 +1153,7 @@
},
{
"cell_type": "code",
"execution_count": 44,
"execution_count": 45,
"metadata": {},
"outputs": [
{
......@@ -1147,7 +1182,7 @@
},
{
"cell_type": "code",
"execution_count": 45,
"execution_count": 46,
"metadata": {},
"outputs": [
{
......@@ -1179,7 +1214,7 @@
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": 47,
"metadata": {},
"outputs": [
{
......@@ -1209,7 +1244,7 @@
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": 48,
"metadata": {},
"outputs": [
{
......@@ -1234,7 +1269,7 @@
},
{
"cell_type": "code",
"execution_count": 48,
"execution_count": 49,
"metadata": {},
"outputs": [
{
......@@ -1243,7 +1278,7 @@
"spot.mark_t([0, 1, 2, 3])"
]
},
"execution_count": 48,
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1262,7 +1297,7 @@
},
{
"cell_type": "code",
"execution_count": 49,
"execution_count": 50,
"metadata": {},
"outputs": [
{
......@@ -1292,7 +1327,7 @@
},
{
"cell_type": "code",
"execution_count": 50,
"execution_count": 51,
"metadata": {},
"outputs": [
{
......@@ -1311,7 +1346,7 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": 52,
"metadata": {},
"outputs": [
{
......@@ -1331,7 +1366,7 @@
},
{
"cell_type": "code",
"execution_count": 52,
"execution_count": 53,
"metadata": {},
"outputs": [
{
......@@ -1366,7 +1401,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.7.3rc1"
}
},
"nbformat": 4,
......
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