* src/tgbaalgos/Makefile.am (tgbaalgos_HEADERS): Add reachiters.hh.

(libtgbaalgos_la_SOURCES): Add reachiters.cc.
* src/tgbaalgos/dotty.cc, src/tgbaalgos/save.cc: Rewrite using
spot::tgba_reachable_iterator_breadth_first.
* src/tgbatest/explicit.test, src/tgbatest/tgbaread.test,
src/tgbatest/tripprod.test: Adjust expected output.
This commit is contained in:
Alexandre Duret-Lutz 2003-07-25 13:12:01 +00:00
parent 664e49e07e
commit e24d3be8a7
9 changed files with 322 additions and 114 deletions

View file

@ -1,80 +1,60 @@
#include <map>
#include "tgba/tgba.hh"
#include "dotty.hh"
#include "tgba/bddprint.hh"
#include "reachiter.hh"
namespace spot
{
typedef std::map<state*, int, state_ptr_less_than> seen_map;
/// Output and record a state.
static bool
dotty_state(std::ostream& os,
const tgba* g, state* st, seen_map& m, int& node)
class dotty_bfs : public tgba_reachable_iterator_breadth_first
{
seen_map::iterator i = m.find(st);
public:
dotty_bfs(const tgba* a, std::ostream& os)
: tgba_reachable_iterator_breadth_first(a), os_(os)
{
}
// Already drawn?
if (i != m.end())
{
node = i->second;
return false;
}
void
start()
{
os_ << "digraph G {" << std::endl;
os_ << " size=\"7.26,10.69\"" << std::endl;
os_ << " 0 [label=\"\", style=invis]" << std::endl;
os_ << " 0 -> 1" << std::endl;
}
node = m.size() + 1;
m[st] = node;
void
end()
{
os_ << "}" << std::endl;
}
os << " " << node << " [label=\""
<< g->format_state(st) << "\"]" << std::endl;
return true;
}
void
process_state(const state* s, int n, tgba_succ_iterator*)
{
os_ << " " << n << " [label=\""
<< automata_->format_state(s) << "\"]" << std::endl;
}
/// Process successors.
static void
dotty_rec(std::ostream& os,
const tgba* g, state* st, seen_map& m, int father)
{
tgba_succ_iterator* si = g->succ_iter(st);
for (si->first(); !si->done(); si->next())
{
int node;
state* s = si->current_state();
bool recurse = dotty_state(os, g, s, m, node);
os << " " << father << " -> " << node << " [label=\"";
bdd_print_set(os, g->get_dict(), si->current_condition()) << "\\n";
bdd_print_set(os, g->get_dict(), si->current_accepting_conditions())
<< "\"]" << std::endl;
if (recurse)
{
dotty_rec(os, g, s, m, node);
// Do not delete S, it is used as key in M.
}
else
{
delete s;
}
}
delete si;
}
void
process_link(int in, int out, const tgba_succ_iterator* si)
{
os_ << " " << in << " -> " << out << " [label=\"";
bdd_print_set(os_, automata_->get_dict(),
si->current_condition()) << "\\n";
bdd_print_set(os_, automata_->get_dict(),
si->current_accepting_conditions()) << "\"]" << std::endl;
}
private:
std::ostream& os_;
};
std::ostream&
dotty_reachable(std::ostream& os, const tgba* g)
{
seen_map m;
state* state = g->get_init_state();
os << "digraph G {" << std::endl;
os << " size=\"7.26,10.69\"" << std::endl;
os << " 0 [label=\"\", style=invis]" << std::endl;
int init;
dotty_state(os, g, state, m, init);
os << " 0 -> " << init << std::endl;
dotty_rec(os, g, state, m, init);
os << "}" << std::endl;
// Finally delete all states used as keys in m:
for (seen_map::iterator i = m.begin(); i != m.end(); ++i)
delete i->first;
dotty_bfs d(g, os);
d.run();
return os;
}