spot/src/tests/complementation.cc
Alexandre Duret-Lutz 1729a79ac7 nullptr cleanup for -Wzero-as-null-pointer-constant
Fixes #106.

* m4/gccwarn.m4: Use -Wzero-as-null-pointer-constant if supported.
* src/bin/autfilt.cc, src/bin/common_aoutput.cc,
src/bin/common_finput.cc, src/bin/common_finput.hh,
src/bin/common_output.cc, src/bin/common_output.hh,
src/bin/common_post.cc, src/bin/common_r.hh, src/bin/common_range.hh,
src/bin/common_setup.cc, src/bin/common_trans.cc, src/bin/dstar2tgba.cc,
src/bin/genltl.cc, src/bin/ltl2tgba.cc, src/bin/ltl2tgta.cc,
src/bin/ltlcross.cc, src/bin/ltldo.cc, src/bin/ltlfilt.cc,
src/bin/ltlgrind.cc, src/bin/randaut.cc, src/bin/randltl.cc,
src/bin/spot-x.cc, src/kripke/kripkeexplicit.cc, src/ltlast/formula.cc,
src/ltlvisit/randomltl.cc, src/ltlvisit/randomltl.hh,
src/ltlvisit/relabel.cc, src/ltlvisit/relabel.hh,
src/ltlvisit/simplify.cc, src/ltlvisit/snf.hh, src/misc/fixpool.hh,
src/misc/mspool.hh, src/misc/hash.hh, src/misc/optionmap.cc,
src/misc/satsolver.cc, src/misc/tmpfile.cc, src/misc/tmpfile.hh,
src/priv/bddalloc.cc, src/ta/ta.hh, src/ta/taexplicit.cc,
src/ta/taexplicit.hh, src/ta/taproduct.cc, src/ta/tgtaexplicit.hh,
src/ta/tgtaproduct.cc, src/taalgos/minimize.cc,
src/taalgos/reachiter.cc, src/taalgos/tgba2ta.cc,
src/tests/complementation.cc, src/tests/ikwiad.cc,
src/tests/randtgba.cc, src/tests/reduc.cc, src/twa/bdddict.cc,
src/twa/bddprint.cc, src/twa/taatgba.cc, src/twa/twa.cc,
src/twa/twagraph.hh, src/twa/twaproduct.cc,
src/twa/twasafracomplement.cc, src/twaalgos/bfssteps.cc,
src/twaalgos/compsusp.cc, src/twaalgos/dtgbasat.cc,
src/twaalgos/emptiness.cc, src/twaalgos/gtec/ce.cc,
src/twaalgos/gv04.cc, src/twaalgos/ltl2taa.cc,
src/twaalgos/ltl2tgba_fm.cc, src/twaalgos/ltl2tgba_fm.hh,
src/twaalgos/magic.cc, src/twaalgos/minimize.cc,
src/twaalgos/ndfs_result.hxx, src/twaalgos/postproc.cc,
src/twaalgos/postproc.hh, src/twaalgos/reachiter.cc,
src/twaalgos/reducerun.cc, src/twaalgos/safety.hh,
src/twaalgos/sccfilter.hh, src/twaalgos/se05.cc,
src/twaalgos/simulation.cc, src/twaalgos/tau03.cc,
src/twaalgos/tau03opt.cc, src/twaalgos/translate.cc,
src/twaalgos/translate.hh, utf8/utf8/core.h,
bench/stutter/stutter_invariance_formulas.cc, iface/ltsmin/ltsmin.cc,
iface/ltsmin/modelcheck.cc: Use nullptr to fix the warning.
2015-09-26 23:07:40 +02:00

261 lines
7.1 KiB
C++

// -*- coding: utf-8 -*-
// Copyright (C) 2008, 2009, 2010, 2011, 2012, 2014, 2015 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 <iomanip>
#include <iostream>
#include "twaalgos/dot.hh"
#include "twaalgos/hoa.hh"
#include "parseaut/public.hh"
#include "twa/twaproduct.hh"
#include "twaalgos/gtec/gtec.hh"
#include "twaalgos/ltl2tgba_fm.hh"
#include "ltlparse/public.hh"
#include "twaalgos/stats.hh"
#include "twaalgos/emptiness.hh"
#include "twaalgos/stats.hh"
#include "twaalgos/emptiness_stats.hh"
#include "twaalgos/degen.hh"
#include "twa/twasafracomplement.hh"
void usage(const char* prog)
{
std::cout << "usage: " << prog << " [options]" << std::endl;
std::cout << "with options" << std::endl
<< "-H Output in HOA\n"
<< "-s buchi_automaton display the safra automaton\n"
<< "-a buchi_automaton display the complemented automaton\n"
<< "-astat buchi_automaton statistics for !a\n"
<< "-fstat formula statistics for !A_f\n"
<< "-f formula test !A_f and !A_!f\n"
<< "-p formula print the automaton for f\n";
}
int main(int argc, char* argv[])
{
char *file = nullptr;
bool print_safra = false;
bool print_automaton = false;
//bool check = false;
int return_value = 0;
bool stats = false;
bool formula = false;
bool print_formula = false;
bool save_hoa = 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, "H") == 0)
{
save_hoa = 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':
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)
{
usage(argv[0]);
return 1;
}
auto dict = spot::make_bdd_dict();
if (print_automaton || print_safra)
{
spot::ltl::environment& env(spot::ltl::default_environment::instance());
spot::parse_aut_error_list pel;
auto h = spot::parse_aut(file, pel, dict, env);
if (spot::format_parse_aut_errors(std::cerr, file, pel))
return 2;
spot::twa_graph_ptr a = h->aut;
spot::twa_ptr complement = nullptr;
complement = spot::make_safra_complement(a);
if (print_automaton)
{
if (save_hoa)
spot::print_hoa(std::cout, complement, nullptr);
else
spot::print_dot(std::cout, complement);
}
if (print_safra)
{
auto safra_complement =
std::dynamic_pointer_cast<spot::tgba_safra_complement>(complement);
spot::display_safra(safra_complement);
}
}
else if (print_formula)
{
spot::ltl::parse_error_list p1;
auto f1 = spot::ltl::parse_infix_psl(file, p1);
if (spot::ltl::format_parse_errors(std::cerr, file, p1))
return 2;
auto a = spot::ltl_to_tgba_fm(f1, dict);
spot::twa_ptr complement = nullptr;
complement = spot::make_safra_complement(a);
spot::print_dot(std::cout, complement);
}
else if (stats)
{
spot::twa_graph_ptr a;
spot::ltl::formula f1 = nullptr;
if (formula)
{
spot::ltl::parse_error_list p1;
f1 = spot::ltl::parse_infix_psl(file, p1);
if (spot::ltl::format_parse_errors(std::cerr, file, p1))
return 2;
a = spot::ltl_to_tgba_fm(f1, dict);
}
else
{
spot::parse_aut_error_list pel;
spot::ltl::environment& env(spot::ltl::default_environment::instance());
auto h = spot::parse_aut(file, pel, dict, env);
if (spot::format_parse_aut_errors(std::cerr, file, pel))
return 2;
a = h->aut;
}
auto safra_complement = spot::make_safra_complement(a);
spot::tgba_statistics a_size = spot::stats_reachable(a);
std::cout << "Original: "
<< a_size.states << ", "
<< a_size.transitions << ", "
<< a->acc().num_sets()
<< std::endl;
auto buchi = spot::degeneralize(a);
std::cout << "Buchi: "
<< buchi->num_states()
<< buchi->num_edges()
<< buchi->acc().num_sets()
<< std::endl;
spot::tgba_statistics b_size = spot::stats_reachable(safra_complement);
std::cout << "Safra Complement: "
<< b_size.states << ", "
<< b_size.transitions << ", "
<< safra_complement->acc().num_sets()
<< std::endl;
if (formula)
{
auto a2 = spot::ltl_to_tgba_fm(spot::ltl::formula::Not(f1), dict);
spot::tgba_statistics a_size = spot::stats_reachable(a2);
std::cout << "Not Formula: "
<< a_size.states << ", "
<< a_size.transitions << ", "
<< a2->acc().num_sets()
<< std::endl;
}
}
else
{
spot::ltl::parse_error_list p1;
auto f1 = spot::ltl::parse_infix_psl(file, p1);
if (spot::ltl::format_parse_errors(std::cerr, file, p1))
return 2;
auto Af = spot::ltl_to_tgba_fm(f1, dict);
auto nf1 = spot::ltl::formula::Not(f1);
auto Anf = spot::ltl_to_tgba_fm(nf1, dict);
auto nAf = spot::make_safra_complement(Af);
auto nAnf = spot::make_safra_complement(Anf);
auto ec = spot::couvreur99(spot::otf_product(nAf, nAnf));
auto 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()->acc().num_sets()
<< std::endl;
if (res)
{
std::cout << "FAIL\n";
return_value = 1;
if (auto run = res->accepting_run())
{
spot::print_dot(std::cout, ec->automaton());
spot::print_tgba_run(std::cout, ec->automaton(), run);
}
}
else
{
std::cout << "OK\n";
}
}
return return_value;
}