Commit c5b7e8e1 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

Introduce a translator class.

This perform pre- and post-processings in addition to
the LTL-to-TGBA translation.

* src/tgbaalgos/translate.cc, src/tgbaalgos/translate.hh: New files.
* src/tgbaalgos/Makefile.am: Add them.
* src/tgbaalgos/postproc.hh: Make the private part protected, so
that we can inherit from that in the translator class.
* src/bin/ltl2tgba.cc: Use the translator class to hide LTL
simplification, translation, and postprocessings.
* NEWS: Mention it.
parent 0edb2b7a
......@@ -2,11 +2,17 @@ New in spot 1.0.2a (not released):
* New features in the library
- Postprocessor now takes an optional option_map argument that can
be used to specify fine-tuning options, making it easier to
benchmark different scenarios while developing new
- The postprocessor class now takes an optional option_map
argument that can be used to specify fine-tuning options, making
it easier to benchmark different scenarios while developing new
postprocessings.
- A new translator class implements a complete translation chain,
from LTL/PSL to TGBA/BA/Monitor. It performs pre- and
post-processings in addition to the core translation, and offers
an interface similar to that used in the postprocessor class, to
specify the intent of the translation.
- The degeneralization algorithm has learned three new tricks:
level reset, level caching, and SCC-based ordering. The former
two are enabled by default. Benchmarking has shown that the
......@@ -26,7 +32,7 @@ New in spot 1.0.2a (not released):
* Command-line tools
- ltl2tgba and ltl2tgta now honor a new --extra-options (or -x)
flag to fine-tune the algorithm used. The available options
flag to fine-tune the algorithms used. The available options
are documented in the spot-x (7) manpage.
New in spot 1.0.2 (2013-03-06):
......
......@@ -31,13 +31,14 @@
#include "common_finput.hh"
#include "common_post.hh"
#include "ltlvisit/simplify.hh"
#include "ltlast/formula.hh"
#include "tgba/tgbaexplicit.hh"
#include "tgbaalgos/dotty.hh"
#include "tgbaalgos/lbtt.hh"
#include "tgbaalgos/ltl2tgba_fm.hh"
#include "tgbaalgos/neverclaim.hh"
#include "tgbaalgos/save.hh"
#include "tgbaalgos/stats.hh"
#include "tgbaalgos/translate.hh"
#include "tgba/bddprint.hh"
#include "misc/optionmap.hh"
......@@ -174,13 +175,11 @@ namespace
class trans_processor: public job_processor
{
public:
spot::ltl::ltl_simplifier& simpl;
spot::postprocessor& post;
spot::translator& trans;
spot::stat_printer statistics;
trans_processor(spot::ltl::ltl_simplifier& simpl,
spot::postprocessor& post)
: simpl(simpl), post(post), statistics(std::cout, stats)
trans_processor(spot::translator& trans)
: trans(trans), statistics(std::cout, stats)
{
}
......@@ -188,12 +187,7 @@ namespace
process_formula(const spot::ltl::formula* f,
const char* filename = 0, int linenum = 0)
{
const spot::ltl::formula* res = simpl.simplify(f);
f->destroy();
f = res;
// This helps ltl_to_tgba_fm() to order BDD variables in a more
// natural way (improving the degeneralization).
simpl.clear_as_bdd_cache();
const spot::tgba* aut = trans.run(&f);
// This should not happen, because the parser we use can only
// read PSL/LTL formula, but since our ltl::formula* type can
......@@ -207,10 +201,6 @@ namespace
s.c_str());
}
bool exprop = level == spot::postprocessor::High;
const spot::tgba* aut = ltl_to_tgba_fm(f, simpl.get_dict(), exprop);
aut = post.run(aut, f);
if (utf8)
{
spot::tgba* a = const_cast<spot::tgba*>(aut);
......@@ -267,14 +257,12 @@ main(int argc, char** argv)
error(2, 0, "No formula to translate? Run '%s --help' for usage.",
program_name);
spot::ltl::ltl_simplifier simpl(simplifier_options());
spot::postprocessor postproc(&extra_options);
postproc.set_pref(pref);
postproc.set_type(type);
postproc.set_level(level);
spot::translator trans(&extra_options);
trans.set_pref(pref);
trans.set_type(type);
trans.set_level(level);
trans_processor processor(simpl, postproc);
trans_processor processor(trans);
if (processor.run())
return 2;
return 0;
......
## -*- coding: utf-8 -*-
## Copyright (C) 2008, 2009, 2010, 2011, 2012 Laboratoire de Recherche
## Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013 Laboratoire de Recherche
## et Développement de l'Epita (LRDE).
## Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de Paris
## 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
......@@ -66,6 +66,7 @@ tgbaalgos_HEADERS = \
stripacc.hh \
tau03.hh \
tau03opt.hh \
translate.hh \
reductgba_sim.hh \
weight.hh
......@@ -109,6 +110,7 @@ libtgbaalgos_la_SOURCES = \
stripacc.cc \
tau03.cc \
tau03opt.cc \
translate.cc \
reductgba_sim.cc \
weight.cc
......
......@@ -89,7 +89,7 @@ namespace spot
/// Return the optimized automaton and delete \a input_disown.
const tgba* run(const tgba* input_disown, const ltl::formula* f);
private:
protected:
const tgba* do_simul(const tgba* input);
const tgba* do_degen(const tgba* input);
......
// -*- coding: utf-8 -*-
// Copyright (C) 2013 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// 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 "translate.hh"
#include "ltl2tgba_fm.hh"
namespace spot
{
void translator::build_simplifier(bdd_dict* dict)
{
ltl::ltl_simplifier_options options(false, false, false);
switch (level_)
{
case High:
options.containment_checks = true;
options.containment_checks_stronger = true;
// fall through
case Medium:
options.synt_impl = true;
// fall through
case Low:
options.reduce_basics = true;
options.event_univ = true;
// fall through
}
simpl_owned_ = simpl_ = new ltl::ltl_simplifier(options, dict);
}
const tgba* translator::run(const ltl::formula** f)
{
const ltl::formula* r = simpl_->simplify(*f);
(*f)->destroy();
*f = r;
// This helps ltl_to_tgba_fm() to order BDD variables in a more
// natural way (improving the degeneralization).
simpl_->clear_as_bdd_cache();
bool exprop = level_ == spot::postprocessor::High;
const tgba* aut = ltl_to_tgba_fm(r, simpl_->get_dict(), exprop);
aut = this->postprocessor::run(aut, r);
return aut;
}
const tgba* translator::run(const ltl::formula* f)
{
f->clone();
const tgba* aut = run(&f);
f->destroy();
return aut;
}
}
// -*- coding: utf-8 -*-
// Copyright (C) 2013 Laboratoire de Recherche et Développement de
// l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef SPOT_TGBAALGOS_TRANSLATE_HH
# define SPOT_TGBAALGOS_TRANSLATE_HH
#include "postproc.hh"
#include "ltlvisit/simplify.hh"
namespace spot
{
/// \brief Translate an LTL formula into an optimized spot::tgba.
/// \ingroup tgba_ltl
///
/// This class implements a three-step translation:
/// - syntactic simplification of the formula
/// - translation of the formula into TGBA
/// - postprocessing of the resulting TGBA to minimize it, or
/// turn it into the required form.
///
/// Method set_type() may be used to specify the type of
/// automaton produced (TGBA, BA, Monitor). The default is TGBA.
///
/// Method set_pref() may be used to specify whether small automata
/// should be prefered over deterministic automata.
///
/// Method set_level() may be used to specify the optimization level.
///
/// The semantic of these three methods is inherited from the
/// spot::postprocessor class, but the optimization level is
/// additionally used to select which LTL simplifications to enable.
class translator: protected postprocessor
{
public:
translator(ltl::ltl_simplifier* simpl, const option_map* opt = 0)
: postprocessor(opt), simpl_(simpl), simpl_owned_(0)
{
assert(simpl);
}
translator(bdd_dict* dict, const option_map* opt = 0)
: postprocessor(opt)
{
build_simplifier(dict);
}
translator(const option_map* opt = 0)
: postprocessor(opt)
{
build_simplifier(0);
}
~translator()
{
// simpl_owned_ is 0 if simpl_ was supplied to the constructor.
delete simpl_owned_;
}
void build_simplifier(bdd_dict* dict);
typedef postprocessor::output_type output_type;
void
set_type(output_type type)
{
this->postprocessor::set_type(type);
}
typedef postprocessor::output_pref output_pref;
void
set_pref(output_pref pref)
{
this->postprocessor::set_pref(pref);
}
typedef postprocessor::optimization_level optimization_level;
void
set_level(optimization_level level)
{
level_ = level;
}
/// \brief Convert \a f into an automaton.
///
/// The formula \a f is simplified internally, but it is not
/// not destroyed (this is the responsibility of the caller).
const tgba* run(const ltl::formula* f);
/// \brief Convert \a f into an automaton, and update f.
///
/// The formula <code>*f</code> is destroyed, and replaced
/// by the simplified version, which should be destroyed by
/// the caller.
const tgba* run(const ltl::formula** f);
private:
ltl::ltl_simplifier* simpl_;
ltl::ltl_simplifier* simpl_owned_;
};
/// @}
}
#endif // SPOT_TGBAALGOS_TRANSLATE_HH
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