convert: BDD to cube conversions
* README, configure.ac, spot/Makefile.am, spot/twacube_algos/Makefile.am, spot/twacube_algos/convert.cc spot/twacube_algos/convert.hh, tests/core/cube.cc, tests/core/cube.test: here.
This commit is contained in:
parent
7c3fdd6b97
commit
8d57700d6a
8 changed files with 257 additions and 1 deletions
|
|
@ -17,9 +17,120 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <bddx.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <spot/twacube/cube.hh>
|
||||
#include <spot/misc/hash.hh>
|
||||
#include <spot/twacube/cube.hh>
|
||||
#include <spot/twacube_algos/convert.hh>
|
||||
#include <spot/twa/bdddict.hh>
|
||||
#include <spot/tl/environment.hh>
|
||||
#include <spot/tl/defaultenv.hh>
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
static bool test_translation(bdd& input, spot::cubeset& cubeset,
|
||||
std::unordered_map<int, int>& binder,
|
||||
std::unordered_map<int, int>& reverse_binder,
|
||||
std::vector<std::string>& aps)
|
||||
{
|
||||
// The BDD used to detect if the convertion works
|
||||
bdd res = bddfalse;
|
||||
bdd initial = input;
|
||||
|
||||
std::cout << "bdd : " << input << '\n';
|
||||
while (initial != bddfalse)
|
||||
{
|
||||
bdd one = bdd_satone(initial);
|
||||
initial -= one;
|
||||
auto cube = spot::satone_to_cube(one, cubeset, binder);
|
||||
res |= spot::cube_to_bdd(cube, cubeset, reverse_binder);
|
||||
std::cout << "cube : " << cubeset.dump(cube, aps) << '\n';
|
||||
delete[] cube;
|
||||
}
|
||||
|
||||
// Translating BDD to cubes and cubes to BDD should provide same BDD.
|
||||
return input == res;
|
||||
}
|
||||
|
||||
static void test_bdd_to_cube()
|
||||
{
|
||||
auto d = spot::make_bdd_dict();
|
||||
spot::environment& e = spot::default_environment::instance();
|
||||
|
||||
// Some of these variables are not desired into the final cube
|
||||
auto ap_0 = e.require("0");
|
||||
int idx_0 = d->register_proposition(ap_0, d);
|
||||
auto ap_a = e.require("a");
|
||||
int idx_a = d->register_proposition(ap_a, d);
|
||||
auto ap_b = e.require("b");
|
||||
int idx_b = d->register_proposition(ap_b, d);
|
||||
auto ap_1 = e.require("1");
|
||||
int idx_1 = d->register_proposition(ap_1, d);
|
||||
auto ap_c = e.require("c");
|
||||
int idx_c = d->register_proposition(ap_c, d);
|
||||
auto ap_d = e.require("d");
|
||||
int idx_d = d->register_proposition(ap_d, d);
|
||||
auto ap_e = e.require("e");
|
||||
int idx_e = d->register_proposition(ap_e, d);
|
||||
|
||||
// Prepare cube
|
||||
std::vector<std::string> aps = {"a", "b", "c", "d", "e"};
|
||||
spot::cubeset cubeset(aps.size());
|
||||
|
||||
// Map Bdd indexes to cube indexes
|
||||
std::unordered_map<int, int> binder = {
|
||||
{idx_a, 0},
|
||||
{idx_b, 1},
|
||||
{idx_c, 2},
|
||||
{idx_d, 3},
|
||||
{idx_e, 4}
|
||||
};
|
||||
|
||||
// Map cube indexes to Bdd indexes
|
||||
std::unordered_map<int, int> reverse_binder = {
|
||||
{0, idx_a},
|
||||
{1, idx_b},
|
||||
{2, idx_c},
|
||||
{3, idx_d},
|
||||
{4, idx_e}
|
||||
};
|
||||
|
||||
// The BDD to convert
|
||||
bdd x;
|
||||
bool result;
|
||||
|
||||
// Test bddtrue
|
||||
x = bddtrue;
|
||||
result = test_translation(x, cubeset, binder, reverse_binder, aps);
|
||||
assert(result);
|
||||
|
||||
// Test bddfalse
|
||||
x = bddfalse;
|
||||
result = test_translation(x, cubeset, binder, reverse_binder, aps);
|
||||
assert(result);
|
||||
|
||||
// Test bdddeterministic bdd
|
||||
x = bdd_ithvar(idx_a) & !bdd_ithvar(idx_b) & bdd_ithvar(idx_c) &
|
||||
!bdd_ithvar(idx_d) & bdd_ithvar(idx_e);
|
||||
result = test_translation(x, cubeset, binder, reverse_binder, aps);
|
||||
assert(result);
|
||||
|
||||
// // Test some free var bdd
|
||||
x = (bdd_ithvar(idx_a) | bdd_ithvar(idx_b)) & bdd_ithvar(idx_d);
|
||||
result = test_translation(x, cubeset, binder, reverse_binder, aps);
|
||||
assert(result);
|
||||
|
||||
// Free all variables
|
||||
d->unregister_variable(idx_e, d);
|
||||
d->unregister_variable(idx_d, d);
|
||||
d->unregister_variable(idx_c, d);
|
||||
d->unregister_variable(idx_1, d);
|
||||
d->unregister_variable(idx_b, d);
|
||||
d->unregister_variable(idx_a, d);
|
||||
d->unregister_variable(idx_0, d);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
|
@ -55,4 +166,5 @@ int main()
|
|||
cs.release(mc2);
|
||||
cs.release(mc1);
|
||||
cs.release(mc);
|
||||
test_bdd_to_cube();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,14 @@ cube : b&d
|
|||
valid : 1
|
||||
intersect(c2,c1) : 1
|
||||
intersect(c2,c) : 0
|
||||
bdd : T
|
||||
cube : 1
|
||||
bdd : F
|
||||
bdd : <1:1, 2:0, 4:1, 5:0, 6:1>
|
||||
cube : a&!b&c&!d&e
|
||||
bdd : <1:0, 2:1, 5:1><1:1, 5:1>
|
||||
cube : !a&b&d
|
||||
cube : a&d
|
||||
EOF
|
||||
|
||||
diff stdout expected
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue