spot/src/tgbatest/complementation.cc
Alexandre Duret-Lutz bf62d439c9 Use 'const formula*' instead of 'formula*' everywhere.
The distinction makes no sense since Spot 0.5, where we switched from
mutable furmulae to immutable formulae.  The difference between
const_visitor and visitor made no sense either.  They have been merged
into one: visitor.

* iface/dve2/dve2check.cc, iface/gspn/ltlgspn.cc,
src/eltlparse/eltlparse.yy, src/eltlparse/public.hh,
src/evtgbatest/ltl2evtgba.cc, src/kripkeparse/kripkeparse.yy,
src/ltlast/atomic_prop.cc, src/ltlast/atomic_prop.hh,
src/ltlast/automatop.cc, src/ltlast/automatop.hh, src/ltlast/binop.cc,
src/ltlast/binop.hh, src/ltlast/bunop.cc, src/ltlast/bunop.hh,
src/ltlast/constant.cc, src/ltlast/constant.hh, src/ltlast/formula.cc,
src/ltlast/formula.hh, src/ltlast/formula_tree.cc,
src/ltlast/formula_tree.hh, src/ltlast/multop.cc,
src/ltlast/multop.hh, src/ltlast/predecl.hh, src/ltlast/refformula.cc,
src/ltlast/refformula.hh, src/ltlast/unop.cc, src/ltlast/unop.hh,
src/ltlast/visitor.hh, src/ltlenv/declenv.cc, src/ltlenv/declenv.hh,
src/ltlenv/defaultenv.cc, src/ltlenv/defaultenv.hh,
src/ltlenv/environment.hh, src/ltlparse/ltlfile.cc,
src/ltlparse/ltlfile.hh, src/ltlparse/ltlparse.yy,
src/ltlparse/public.hh, src/ltltest/consterm.cc,
src/ltltest/equals.cc, src/ltltest/genltl.cc, src/ltltest/kind.cc,
src/ltltest/length.cc, src/ltltest/randltl.cc, src/ltltest/readltl.cc,
src/ltltest/reduc.cc, src/ltltest/syntimpl.cc,
src/ltltest/tostring.cc, src/ltlvisit/apcollect.cc,
src/ltlvisit/apcollect.hh, src/ltlvisit/clone.cc,
src/ltlvisit/clone.hh, src/ltlvisit/contain.cc,
src/ltlvisit/contain.hh, src/ltlvisit/dotty.cc,
src/ltlvisit/length.cc, src/ltlvisit/lunabbrev.cc,
src/ltlvisit/lunabbrev.hh, src/ltlvisit/mark.cc, src/ltlvisit/mark.hh,
src/ltlvisit/nenoform.cc, src/ltlvisit/nenoform.hh,
src/ltlvisit/postfix.cc, src/ltlvisit/postfix.hh,
src/ltlvisit/randomltl.cc, src/ltlvisit/randomltl.hh,
src/ltlvisit/reduce.cc, src/ltlvisit/reduce.hh,
src/ltlvisit/simpfg.cc, src/ltlvisit/simpfg.hh,
src/ltlvisit/simplify.cc, src/ltlvisit/simplify.hh,
src/ltlvisit/snf.cc, src/ltlvisit/snf.hh, src/ltlvisit/tostring.cc,
src/ltlvisit/tunabbrev.cc, src/ltlvisit/tunabbrev.hh,
src/ltlvisit/wmunabbrev.cc, src/ltlvisit/wmunabbrev.hh,
src/neverparse/neverclaimparse.yy, src/sabatest/sabacomplementtgba.cc,
src/tgba/bdddict.cc, src/tgba/formula2bdd.cc, src/tgba/taatgba.cc,
src/tgba/taatgba.hh, src/tgbaalgos/eltl2tgba_lacim.cc,
src/tgbaalgos/ltl2taa.cc, src/tgbaalgos/ltl2tgba_fm.cc,
src/tgbaalgos/ltl2tgba_lacim.cc, src/tgbaalgos/minimize.cc,
src/tgbaalgos/randomgraph.cc, src/tgbaparse/tgbaparse.yy,
src/tgbatest/complementation.cc, src/tgbatest/ltl2tgba.cc,
src/tgbatest/ltlprod.cc, src/tgbatest/mixprod.cc,
src/tgbatest/randtgba.cc: Massive adjustment!
* src/tgbatest/reductgba.cc: Delete.
2012-05-02 09:28:16 +02:00

327 lines
8.9 KiB
C++

// Copyright (C) 2008, 2009, 2010, 2011, 2012 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 2 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 Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#include <iomanip>
#include <iostream>
#include "tgbaalgos/dotty.hh"
#include "tgbaalgos/save.hh"
#include "tgbaparse/public.hh"
#include "tgba/tgbaproduct.hh"
#include "tgbaalgos/gtec/gtec.hh"
#include "tgbaalgos/ltl2tgba_fm.hh"
#include "ltlparse/public.hh"
#include "tgbaalgos/stats.hh"
#include "tgbaalgos/emptiness.hh"
#include "ltlast/unop.hh"
#include "tgbaalgos/stats.hh"
#include "tgbaalgos/emptiness_stats.hh"
#include "tgba/tgbatba.hh"
#include "tgba/tgbasafracomplement.hh"
#include "tgba/tgbakvcomplement.hh"
void usage(const char* prog)
{
std::cout << "usage: " << prog << " [options]" << std::endl;
std::cout << "with options" << std::endl
<< "-b Output in spot's format" << std::endl
<< "-S Use Safra's complementation "
<< "instead of Kupferman&Vardi's" << std::endl
<< "-s buchi_automaton display the safra automaton"
<< std::endl
<< "-a buchi_automaton display the complemented automaton"
<< std::endl
<< "-astat buchi_automaton statistics for !a" << std::endl
<< "-fstat formula statistics for !A_f" << std::endl
<< "-f formula test !A_f and !A_!f" << std::endl
<< "-p formula print the automaton for f" << std::endl;
}
int main(int argc, char* argv[])
{
char *file = 0;
bool print_safra = false;
bool print_automaton = false;
//bool check = false;
int return_value = 0;
bool stats = false;
bool formula = false;
bool safra = false;
bool print_formula = false;
bool save_spot = false;
if (argc < 3)
{
usage(argv[0]);
return 1;
}
for (int i = 1; i < argc; ++i)
{
if (argv[i][0] == '-')
{
if (strcmp(argv[i] + 1, "b") == 0)
{
save_spot = true;
continue;
}
if (strcmp(argv[i] + 1, "astat") == 0)
{
stats = true;
formula = false;
continue;
}
if (strcmp(argv[i] + 1, "fstat") == 0)
{
stats = true;
formula = true;
continue;
}
switch (argv[i][1])
{
case 'S':
safra = true; break;
case 's':
safra = true; print_safra = true; break;
case 'a':
print_automaton = true; break;
case 'f':
//check = true;
break;
case 'p':
print_formula = true; break;
default:
std::cerr << "unrecognized option `-" << argv[i][1]
<< "'" << std::endl;
return 2;
}
}
else
file = argv[i];
}
if (file == 0)
{
usage(argv[0]);
return 1;
}
spot::bdd_dict* dict = new spot::bdd_dict();
if (print_automaton || print_safra)
{
spot::ltl::environment& env(spot::ltl::default_environment::instance());
spot::tgba_parse_error_list pel;
spot::tgba_explicit_string* a = spot::tgba_parse(file, pel, dict, env);
if (spot::format_tgba_parse_errors(std::cerr, file, pel))
return 2;
spot::tgba* complement = 0;
if (safra)
complement = new spot::tgba_safra_complement(a);
else
complement = new spot::tgba_kv_complement(a);
if (print_automaton)
{
if (save_spot)
spot::tgba_save_reachable(std::cout, complement);
else
spot::dotty_reachable(std::cout, complement);
}
if (print_safra)
{
spot::tgba_safra_complement* safra_complement =
dynamic_cast<spot::tgba_safra_complement*>(complement);
spot::display_safra(safra_complement);
}
delete complement;
delete a;
}
else if (print_formula)
{
spot::tgba* a;
const spot::ltl::formula* f1 = 0;
spot::ltl::parse_error_list p1;
f1 = spot::ltl::parse(file, p1);
if (spot::ltl::format_parse_errors(std::cerr, file, p1))
return 2;
a = spot::ltl_to_tgba_fm(f1, dict);
spot::tgba* complement = 0;
if (safra)
complement = new spot::tgba_safra_complement(a);
else
complement = new spot::tgba_kv_complement(a);
spot::dotty_reachable(std::cout, complement);
f1->destroy();
delete complement;
delete a;
}
else if (stats)
{
spot::tgba* a;
const spot::ltl::formula* f1 = 0;
if (formula)
{
spot::ltl::parse_error_list p1;
f1 = spot::ltl::parse(file, p1);
if (spot::ltl::format_parse_errors(std::cerr, file, p1))
return 2;
a = spot::ltl_to_tgba_fm(f1, dict);
}
else
{
spot::tgba_parse_error_list pel;
spot::ltl::environment& env(spot::ltl::default_environment::instance());
a = spot::tgba_parse(file, pel, dict, env);
if (spot::format_tgba_parse_errors(std::cerr, file, pel))
return 2;
}
spot::tgba_safra_complement* safra_complement =
new spot::tgba_safra_complement(a);
spot::tgba_statistics a_size = spot::stats_reachable(a);
std::cout << "Original: "
<< a_size.states << ", "
<< a_size.transitions << ", "
<< a->number_of_acceptance_conditions()
<< std::endl;
spot::tgba *buchi = new spot::tgba_sba_proxy(a);
a_size = spot::stats_reachable(buchi);
std::cout << "Buchi: "
<< a_size.states << ", "
<< a_size.transitions << ", "
<< buchi->number_of_acceptance_conditions()
<< std::endl;
delete buchi;
spot::tgba_statistics b_size = spot::stats_reachable(safra_complement);
std::cout << "Safra Complement: "
<< b_size.states << ", "
<< b_size.transitions << ", "
<< safra_complement->number_of_acceptance_conditions()
<< std::endl;
spot::tgba_kv_complement* complement =
new spot::tgba_kv_complement(a);
b_size = spot::stats_reachable(complement);
std::cout << "GBA Complement: "
<< b_size.states << ", "
<< b_size.transitions << ", "
<< complement->number_of_acceptance_conditions()
<< std::endl;
delete complement;
delete a;
if (formula)
{
const spot::ltl::formula* nf1 =
spot::ltl::unop::instance(spot::ltl::unop::Not,
f1->clone());
spot::tgba* a2 = spot::ltl_to_tgba_fm(nf1, dict);
spot::tgba_statistics a_size = spot::stats_reachable(a2);
std::cout << "Not Formula: "
<< a_size.states << ", "
<< a_size.transitions << ", "
<< a2->number_of_acceptance_conditions()
<< std::endl;
delete a2;
f1->destroy();
nf1->destroy();
}
}
else
{
spot::ltl::parse_error_list p1;
const spot::ltl::formula* f1 = spot::ltl::parse(file, p1);
if (spot::ltl::format_parse_errors(std::cerr, file, p1))
return 2;
spot::tgba* Af = spot::ltl_to_tgba_fm(f1, dict);
const spot::ltl::formula* nf1 =
spot::ltl::unop::instance(spot::ltl::unop::Not, f1->clone());
spot::tgba* Anf = spot::ltl_to_tgba_fm(nf1, dict);
spot::tgba* nAf;
spot::tgba* nAnf;
if (safra)
{
nAf = new spot::tgba_safra_complement(Af);
nAnf = new spot::tgba_safra_complement(Anf);
}
else
{
nAf = new spot::tgba_kv_complement(Af);
nAnf = new spot::tgba_kv_complement(Anf);
}
spot::tgba* prod = new spot::tgba_product(nAf, nAnf);
spot::emptiness_check* ec = spot::couvreur99(prod);
spot::emptiness_check_result* res = ec->check();
spot::tgba_statistics a_size = spot::stats_reachable(ec->automaton());
std::cout << "States: "
<< a_size.states << std::endl
<< "Transitions: "
<< a_size.transitions << std::endl
<< "Acc Cond: "
<< ec->automaton()->number_of_acceptance_conditions()
<< std::endl;
if (res)
{
std::cout << "FAIL";
return_value = 1;
}
else
std::cout << "OK";
std::cout << std::endl;
delete res;
delete ec;
delete prod;
delete nAf;
delete Af;
delete nAnf;
delete Anf;
nf1->destroy();
f1->destroy();
}
delete dict;
return return_value;
}