Commit 6a662a6d authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz

get read of twa_safra_complement

* spot/twa/twasafracomplement.cc, spot/twa/twasafracomplement.hh,
tests/core/complementation.cc: Delete.
* tests/Makefile.am, spot/twa/Makefile.am: Adjust.
* tests/core/complementation.test: Rewrite using the new determinization
code.
* python/spot/impl.i: Do not mention twa_safra_complement anymore.
* NEWS: Mention the removal.
parent df0f9941
......@@ -68,6 +68,9 @@ New in spot 1.99.7a (not yet released)
in facts works on transition-based Büchi automaton, and will first
degeneralize any automaton with generalized Büchi acceptance.
* The twa_safra_complement class has been removed. Use
tgba_determinize() and dtwa_complement() instead.
Python:
* The ltsmin interface has been binded in Python. See
......
......@@ -61,7 +61,6 @@
%shared_ptr(spot::taa_tgba)
%shared_ptr(spot::taa_tgba_string)
%shared_ptr(spot::taa_tgba_formula)
%shared_ptr(spot::twa_safra_complement)
%shared_ptr(spot::twa_run)
%shared_ptr(spot::twa_word)
%shared_ptr(spot::emptiness_check_result)
......
## -*- coding: utf-8 -*-
## Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Laboratoire
## Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Laboratoire
## de Recherche et Développement de l'Epita (LRDE).
## Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
## département Systèmes Répartis Coopératifs (SRC), Université Pierre
......@@ -34,8 +34,7 @@ twa_HEADERS = \
taatgba.hh \
twa.hh \
twagraph.hh \
twaproduct.hh \
twasafracomplement.hh
twaproduct.hh
noinst_LTLIBRARIES = libtwa.la
libtwa_la_SOURCES = \
......@@ -46,5 +45,4 @@ libtwa_la_SOURCES = \
taatgba.cc \
twa.cc \
twagraph.cc \
twaproduct.cc \
twasafracomplement.cc
twaproduct.cc
This diff is collapsed.
// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2010, 2011, 2013, 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/>.
#pragma once
#include <vector>
#include <spot/twa/twa.hh>
#ifndef TRANSFORM_TO_TBA
# define TRANSFORM_TO_TBA 0
#endif
#define TRANSFORM_TO_TGBA (!TRANSFORM_TO_TBA)
namespace spot
{
/// \ingroup twa_on_the_fly_algorithms
/// \brief Build a complemented automaton.
///
/// It creates an automaton that recognizes the
/// negated language of \a aut.
///
/// 1. First Safra construction algorithm produces a
/// deterministic Rabin automaton.
/// 2. Interpreting this deterministic Rabin automaton as a
/// deterministic Streett will produce a complemented automaton.
/// 3. Then we use a transformation from deterministic Streett
/// automaton to nondeterministic Büchi automaton.
///
/// Safra construction is done in \a tgba_complement, the transformation
/// is done on-the-fly when successors are called.
///
/// \sa safra_determinisation, tgba_safra_complement::succ_iter.
class SPOT_API tgba_safra_complement : public twa
{
public:
tgba_safra_complement(const const_twa_graph_ptr& a);
virtual ~tgba_safra_complement();
// tgba interface.
virtual state* get_init_state() const;
virtual twa_succ_iterator* succ_iter(const state* state) const;
virtual std::string format_state(const state* state) const;
void* get_safra() const
{
return safra_;
}
protected:
virtual bdd compute_support_conditions(const state* state) const;
private:
const_twa_graph_ptr automaton_;
void* safra_;
#if TRANSFORM_TO_TBA
acc_cond::mark_t the_acceptance_cond_;
#endif
#if TRANSFORM_TO_TGBA
// Map to i the i-th acceptance condition of the final automaton.
std::vector<acc_cond::mark_t> acceptance_cond_vec_;
#endif
};
typedef std::shared_ptr<tgba_safra_complement> tgba_safra_complement_ptr;
typedef std::shared_ptr<const tgba_safra_complement>
const_tgba_safra_complement_ptr;
inline tgba_safra_complement_ptr
make_safra_complement(const const_twa_graph_ptr& a)
{
return std::make_shared<tgba_safra_complement>(a);
}
/// \brief Produce a dot output of the Safra automaton associated
/// to \a a.
///
/// \param a The \c tgba_safra_complement with an intermediate Safra
/// automaton to display
void SPOT_API display_safra(const const_tgba_safra_complement_ptr& a);
}
......@@ -60,7 +60,6 @@ core/defs: $(top_builddir)/config.status $(srcdir)/core/defs.in
check_PROGRAMS = \
core/acc \
core/bitvect \
core/complement \
core/checkpsl \
core/checkta \
core/consterm \
......@@ -101,7 +100,6 @@ core_acc_SOURCES = core/acc.cc
core_bitvect_SOURCES = core/bitvect.cc
core_checkpsl_SOURCES = core/checkpsl.cc
core_checkta_SOURCES = core/checkta.cc
core_complement_SOURCES = core/complementation.cc
core_emptchk_SOURCES = core/emptchk.cc
core_graph_SOURCES = core/graph.cc
core_ikwiad_SOURCES = core/ikwiad.cc
......
// -*- 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 <spot/twaalgos/dot.hh>
#include <spot/twaalgos/hoa.hh>
#include <spot/parseaut/public.hh>
#include <spot/twa/twaproduct.hh>
#include <spot/twaalgos/gtec/gtec.hh>
#include <spot/twaalgos/ltl2tgba_fm.hh>
#include <spot/tl/parse.hh>
#include <spot/twaalgos/stats.hh>
#include <spot/twaalgos/emptiness.hh>
#include <spot/twaalgos/stats.hh>
#include <spot/twaalgos/emptiness_stats.hh>
#include <spot/twaalgos/degen.hh>
#include <spot/twa/twasafracomplement.hh>
static 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::environment& env(spot::default_environment::instance());
auto h = spot::parse_aut(file, dict, env);
if (h->format_errors(std::cerr))
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::parse_error_list p1;
auto f1 = spot::parse_infix_psl(file, p1);
if (spot::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::formula f1 = nullptr;
if (formula)
{
spot::parse_error_list p1;
f1 = spot::parse_infix_psl(file, p1);
if (spot::format_parse_errors(std::cerr, file, p1))
return 2;
a = spot::ltl_to_tgba_fm(f1, dict);
}
else
{
auto h = spot::parse_aut(file, dict);
if (h->format_errors(std::cerr))
return 2;
a = h->aut;
}
auto safra_complement = spot::make_safra_complement(a);
spot::twa_statistics a_size = spot::stats_reachable(a);
std::cout << "Original: "
<< a_size.states << ", "
<< a_size.edges << ", "
<< 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::twa_statistics b_size = spot::stats_reachable(safra_complement);
std::cout << "Safra Complement: "
<< b_size.states << ", "
<< b_size.edges << ", "
<< safra_complement->acc().num_sets()
<< std::endl;
if (formula)
{
auto a2 = spot::ltl_to_tgba_fm(spot::formula::Not(f1), dict);
spot::twa_statistics a_size = spot::stats_reachable(a2);
std::cout << "Not Formula: "
<< a_size.states << ", "
<< a_size.edges << ", "
<< a2->acc().num_sets()
<< std::endl;
}
}
else
{
spot::parse_error_list p1;
auto f1 = spot::parse_infix_psl(file, p1);
if (spot::format_parse_errors(std::cerr, file, p1))
return 2;
auto Af = spot::ltl_to_tgba_fm(f1, dict);
auto nf1 = spot::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::twa_statistics a_size = spot::stats_reachable(ec->automaton());
std::cout << "States: "
<< a_size.states << std::endl
<< "Transitions: "
<< a_size.edges << 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());
std::cout << run;
}
}
else
{
std::cout << "OK\n";
}
}
return return_value;
}
#!/bin/sh
# -*- coding: utf-8 -*-
# Copyright (C) 2009, 2011, 2014, 2015 Laboratoire de Recherche et
# Copyright (C) 2009, 2011, 2014, 2015, 2016 Laboratoire de Recherche et
# Développement de l'Epita (LRDE).
#
# This file is part of Spot, a model checking library.
......@@ -22,9 +22,7 @@
set -e
while read f; do
run 0 ../complement -f "$f"
done <<EOF
cat >input <<EOF
GFa
FGa
<>p1->p0
......@@ -37,8 +35,37 @@ GFa&&FGa
U (p1 || ((p0 && ! p1) U ((p1 || (! p0 U (p1 || [] ! p0))) || [] p0)))))))))
EOF
ltlcross -F input 'ltl2tgba --generic -D' --csv=out.csv
# Make sure all the automata produced where deterministic
cut -d, -f16 < out.csv > det.csv
cat >expected <<EOF
"nondet_aut"
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
EOF
diff det.csv expected
# The following test-case was supplied by Martin Dieguez Lodeiro to
# demonstrate a bug in our Safra implementation.
# demonstrate a bug in our first Safra implementation. It has now
# been adapted to our new determinization function, just in case.
cat >x.hoa <<EOF
HOA: v1
States: 3
......@@ -59,11 +86,15 @@ State: 2
[0] 2 {0}
--END--
EOF
# x.tgba accepts some run
run 0 ../ikwiad -XH -e x.hoa
run 0 autfilt -D x.hoa > x2.hoa
# x.hoa accepts some run
run 0 autfilt -q -v --is-empty x.hoa
run 0 autfilt -q -v --is-empty x2.hoa
# so does its complement
run 0 ../complement -H -a x.hoa > nx.hoa
run 0 ../ikwiad -XH -e nx.hoa
run 0 autfilt -q -v --is-empty --complement x2.hoa > x3.hoa
# however the intersection of both should not
# accept any run.
run 1 autfilt -q nx.hoa --intersect x.hoa
run 1 autfilt -q --intersect x2.hoa x3.hoa
:
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