python: rewrite translate() to deal with unambiguous and sbacc

and make it easier to extend and use.

* src/twaalgos/postproc.hh, src/twaalgos/translate.cc,
src/twaalgos/translate.hh: Incorporate the Unambiguous option
with the other preferences.  It's cleaner this way, and the
previous setup did not work well with Python.
* src/bin/ltl2tgba.cc: Adjust to this change.
* wrap/python/spot.py (translate): Rewrite.
* wrap/python/tests/automata.ipynb: Adjust existing cases, and
add more as well as some comments.
This commit is contained in:
Alexandre Duret-Lutz 2015-05-15 23:50:19 +02:00
parent 1ef3e5f3ff
commit 19a273929c
6 changed files with 666 additions and 190 deletions

View file

@ -83,7 +83,7 @@ const struct argp_child children[] =
};
static spot::option_map extra_options;
bool unambiguous = false;
static spot::postprocessor::output_pref unambig = 0;
static int
parse_opt(int key, char* arg, struct argp_state*)
@ -98,7 +98,7 @@ parse_opt(int key, char* arg, struct argp_state*)
type = spot::postprocessor::Monitor;
break;
case 'U':
unambiguous = true;
unambig = spot::postprocessor::Unambiguous;
break;
case 'x':
{
@ -186,11 +186,9 @@ main(int argc, char** argv)
program_name);
spot::translator trans(&extra_options);
trans.set_pref(pref | comp | sbacc);
trans.set_pref(pref | comp | sbacc | unambig);
trans.set_type(type);
trans.set_level(level);
if (unambiguous)
trans.set_pref(spot::translator::Unambiguous);
try
{

View file

@ -74,13 +74,11 @@ namespace spot
enum
{
Any = 0,
Small = 1,
Deterministic = 2,
// 3 reserved for unambiguous
// Combine Complete as 'Small | Complete' or 'Deterministic | Complete'
Small = 1, // Small and Deterministic
Deterministic = 2, // are exclusive choices.
Complete = 4,
// Likewise. State-based acceptance.
SBAcc = 8,
SBAcc = 8, // State-based acceptance.
Unambiguous = 16,
};
typedef int output_pref;

View file

@ -28,7 +28,6 @@ namespace spot
void translator::setup_opt(const option_map* opt)
{
comp_susp_ = early_susp_ = skel_wdba_ = skel_simul_ = 0;
unambiguous_ = false;
if (!opt)
return;
@ -64,12 +63,13 @@ namespace spot
twa_graph_ptr translator::run(const ltl::formula** f)
{
if (unambiguous_ && type_ == postprocessor::Monitor)
bool unambiguous = (pref_ & postprocessor::Unambiguous);
if (unambiguous && type_ == postprocessor::Monitor)
{
// Deterministic monitor are unambiguous, so the unambiguous
// option is not really relevant for monitors.
unambiguous_ = false;
set_pref(postprocessor::Deterministic);
unambiguous = false;
set_pref(pref_ | postprocessor::Deterministic);
}
const ltl::formula* r = simpl_->simplify(*f);
@ -94,9 +94,9 @@ namespace spot
}
else
{
bool exprop = unambiguous_ || level_ == postprocessor::High;
bool exprop = unambiguous || level_ == postprocessor::High;
aut = ltl_to_tgba_fm(r, simpl_->get_dict(), exprop,
true, false, false, 0, 0, unambiguous_);
true, false, false, 0, 0, unambiguous);
}
aut = this->postprocessor::run(aut, r);
return aut;

View file

@ -1,6 +1,6 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2013, 2014 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
// Copyright (C) 2013, 2014, 2015 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
@ -82,22 +82,12 @@ namespace spot
this->postprocessor::set_type(type);
}
typedef postprocessor::output_pref output_pref;
enum output_pref_extra { Unambiguous };
void
set_pref(output_pref pref)
{
this->postprocessor::set_pref(pref);
}
void
set_pref(output_pref_extra)
{
unambiguous_ = true;
}
typedef postprocessor::optimization_level optimization_level;
void
@ -130,7 +120,6 @@ namespace spot
int early_susp_;
int skel_wdba_;
int skel_simul_;
bool unambiguous_;
};
/// @}
}