Add an ltl2tgba option to read Kripke structure.

Also offers two ways to output Kripke structures.

* src/kripketest/parse_print_test.cc, src/kripke/kripkeexplicit.cc
: Simplify includes.
* src/kripke/kripkeprint.hh (kripke_save_reachable,
kripke_save_reachable_renumbered): New declarations.
(KripkePrinter): Move and rename...
* src/kripke/kripkeprint.cc (kripke_printer): ... here.
(kripke_printer_renumbered): New class.
(kripke_save_reachable, kripke_save_reachable_renumbered): New
function.
* src/tgbatest/ltl2tgba.cc: Add an option to read Kripke
structures.
* iface/dve2/dve2check.cc: Use kripke_save_reachable_renumbered.
* iface/dve2/defs.in (run2): Remove.
* iface/dve2/kripke.test: Adjust tests.
This commit is contained in:
Alexandre Duret-Lutz 2011-11-27 21:05:01 +01:00
parent 172ce2d7fd
commit ba3108f98d
9 changed files with 188 additions and 118 deletions

View file

@ -20,10 +20,9 @@
#include "kripkeexplicit.hh"
#include "../tgba/bddprint.hh"
#include "tgba/bddprint.hh"
#include "tgba/formula2bdd.hh"
#include <iostream>
#include "../tgba/state.hh"
namespace spot
{

View file

@ -21,46 +21,120 @@
#include "kripkeprint.hh"
#include "kripkeexplicit.hh"
#include "../tgba/bddprint.hh"
#include "tgba/bddprint.hh"
#include "misc/escape.hh"
#include "tgbaalgos/reachiter.hh"
#include <iostream>
#include <sstream>
namespace spot
{
KripkePrinter::KripkePrinter(const kripke* automata,
std::ostream& os)
: tgba_reachable_iterator_breadth_first(automata), os_(os)
namespace
{
}
void KripkePrinter::start()
{
}
void KripkePrinter::process_state(const state* s,
int,
tgba_succ_iterator* si)
{
const bdd_dict* d = automata_->get_dict();
std::string cur = automata_->format_state(s);
os_ << "\"";
escape_str(os_, automata_->format_state(s));
os_ << "\", \"";
const kripke* automata = down_cast<const kripke*>
(automata_);
assert(automata);
escape_str(os_, bdd_format_formula(d,
automata->state_condition(s)));
os_ << "\",";
for (si->first(); !si->done(); si->next())
class kripke_printer : public tgba_reachable_iterator_breadth_first
{
state* dest = si->current_state();
os_ << " \"";
escape_str(os_, automata_->format_state(dest));
os_ << "\"";
}
os_ << ";" << std::endl;
public:
kripke_printer(const kripke* a, std::ostream& os)
: tgba_reachable_iterator_breadth_first(a), os_(os)
{
}
void process_state(const state* s, int, tgba_succ_iterator* si)
{
const bdd_dict* d = automata_->get_dict();
os_ << "\"";
escape_str(os_, automata_->format_state(s));
os_ << "\", \"";
const kripke* automata = down_cast<const kripke*> (automata_);
assert(automata);
escape_str(os_, bdd_format_formula(d,
automata->state_condition(s)));
os_ << "\",";
for (si->first(); !si->done(); si->next())
{
state* dest = si->current_state();
os_ << " \"";
escape_str(os_, automata_->format_state(dest));
os_ << "\"";
}
os_ << ";\n";
}
private:
std::ostream& os_;
};
class kripke_printer_renumbered :
public tgba_reachable_iterator_breadth_first
{
public:
kripke_printer_renumbered(const kripke* a, std::ostream& os)
: tgba_reachable_iterator_breadth_first(a), os_(os),
notfirst(false)
{
}
void finish_state()
{
os_ << lastsuccs.str() << ";\n";
lastsuccs.str("");
}
void process_state(const state* s, int in_s, tgba_succ_iterator*)
{
if (notfirst)
finish_state();
else
notfirst = true;
const bdd_dict* d = automata_->get_dict();
std::string cur = automata_->format_state(s);
os_ << "S" << in_s << ", \"";
const kripke* automata = down_cast<const kripke*>(automata_);
assert(automata);
escape_str(os_, bdd_format_formula(d,
automata->state_condition(s)));
os_ << "\",";
}
void
process_link(const state*, int, const state*, int d,
const tgba_succ_iterator*)
{
lastsuccs << " S" << d;
}
void
end()
{
finish_state();
}
private:
std::ostream& os_;
std::ostringstream lastsuccs;
bool notfirst;
};
}
std::ostream&
kripke_save_reachable(std::ostream& os, const kripke* k)
{
kripke_printer p(k, os);
p.run();
return os;
}
std::ostream&
kripke_save_reachable_renumbered(std::ostream& os, const kripke* k)
{
kripke_printer_renumbered p(k, os);
p.run();
return os;
}
} // End namespace Spot

View file

@ -23,30 +23,32 @@
# define SPOT_KRIPKE_KRIPKEPRINT_HH
# include <iosfwd>
# include "tgbaalgos/reachiter.hh"
namespace spot
{
class kripke_explicit;
class state_kripke;
class kripke_succ_iterator;
class kripke;
/// \brief Iterate over all reachable states of a spot::kripke
/// Override start and process_state methods from
/// tgba_reachable_iterator_breadth_first.
class KripkePrinter : public tgba_reachable_iterator_breadth_first
{
public:
KripkePrinter(const kripke* state, std::ostream& os);
/// \brief Save the reachable part of Kripke structure in text format.
///
/// The states will be named with the value returned by the
/// kripke::format_state() method. Such a string can be large, so
/// the output will not be I/O efficient. We recommend using this
/// function only for debugging. Use
/// kripke_save_reachable_renumbered() for large output.
///
/// \ingroup tgba_io
std::ostream& kripke_save_reachable(std::ostream& os, const kripke* k);
void start();
void process_state(const state*, int, tgba_succ_iterator* si);
private:
std::ostream& os_;
};
/// \brief Save the reachable part of Kripke structure in text format.
///
/// States will be renumbered with sequential number. This is much
/// more I/O efficient when dumping large Kripke structures with big
/// state names. The drawback is that any information carried by
/// the state name is lost.
///
/// \ingroup tgba_io
std::ostream& kripke_save_reachable_renumbered(std::ostream& os,
const kripke* k);
} // End namespace spot