// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6), // département Systèmes Répartis Coopératifs (SRC), Université Pierre // et Marie Curie. // // 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 #include "emptiness.hh" #include "tgba/tgba.hh" #include "tgba/bddprint.hh" #include "tgba/tgbaexplicit.hh" namespace spot { tgba_run::~tgba_run() { for (steps::const_iterator i = prefix.begin(); i != prefix.end(); ++i) delete i->s; for (steps::const_iterator i = cycle.begin(); i != cycle.end(); ++i) delete i->s; } tgba_run::tgba_run(const tgba_run& run) { for (steps::const_iterator i = run.prefix.begin(); i != run.prefix.end(); ++i) { step s = { s.s->clone(), i->label, i->acc }; prefix.push_back(s); } for (steps::const_iterator i = run.cycle.begin(); i != run.cycle.end(); ++i) { step s = { s.s->clone(), i->label, i->acc }; cycle.push_back(s); } } std::ostream& print_tgba_run(std::ostream& os, const tgba* a, const tgba_run* run) { bdd_dict* d = a->get_dict(); os << "Prefix:" << std::endl; for (tgba_run::steps::const_iterator i = run->prefix.begin(); i != run->prefix.end(); ++i) { os << " " << a->format_state(i->s) << std::endl; os << " | "; bdd_print_formula(os, d, i->label); os << "\t"; bdd_print_accset(os, d, i->acc); os << std::endl; } os << "Cycle:" << std::endl; for (tgba_run::steps::const_iterator i = run->cycle.begin(); i != run->cycle.end(); ++i) { os << " " << a->format_state(i->s) << std::endl; os << " | "; bdd_print_formula(os, d, i->label); os << "\t"; bdd_print_accset(os, d, i->acc); os << std::endl; } return os; } tgba_run& tgba_run::operator=(const tgba_run& run) { if (&run != this) { this->~tgba_run(); new(this) tgba_run(run); } return *this; } tgba_run* emptiness_check_result::accepting_run() { return 0; } emptiness_check::~emptiness_check() { } std::ostream& emptiness_check::print_stats(std::ostream& os) const { return os; } namespace { std::string format_state(const tgba* a, const state* s, int n) { std::ostringstream os; os << a->format_state(s) << " (" << n << ")"; return os.str(); } } tgba* tgba_run_to_tgba(const tgba* a, const tgba_run* run) { tgba_explicit* res = new tgba_explicit(a->get_dict()); res->copy_acceptance_conditions_of(a); const state* s = a->get_init_state(); int number = 1; tgba_explicit::state* source; tgba_explicit::state* dest; const tgba_run::steps* l; bdd seen_acc = bddfalse; typedef Sgi::hash_map state_map; state_map seen; if (run->prefix.empty()) l = &run->cycle; else l = &run->prefix; tgba_run::steps::const_iterator i = l->begin(); assert(s->compare(i->s) == 0); source = res->set_init_state(format_state(a, i->s, number)); ++number; seen.insert(std::make_pair(i->s, source)); for (; i != l->end();) { // expected outgoing transition bdd label = i->label; bdd acc = i->acc; // compute the next expected state const state* next; ++i; if (i != l->end()) { next = i->s; } else { if (l == &run->prefix) { l = &run->cycle; i = l->begin(); } next = l->begin()->s; } // browse the actual outgoing transitions tgba_succ_iterator* j = a->succ_iter(s); delete s; for (j->first(); !j->done(); j->next()) { if (j->current_condition() != label || j->current_acceptance_conditions() != acc) continue; const state* s2 = j->current_state(); if (s2->compare(next) != 0) { delete s2; continue; } else { s = s2; break; } } assert(!j->done()); delete j; state_map::const_iterator its = seen.find(next); if (its == seen.end()) { dest = res->add_state(format_state(a, next, number)); ++number; seen.insert(std::make_pair(next, dest)); } else dest = its->second; tgba_explicit::transition* t = res->create_transition(source, dest); res->add_conditions(t, label); res->add_acceptance_conditions(t, acc); source = dest; // Sum acceptance conditions. if (l == &run->cycle && i != l->begin()) seen_acc |= acc; } delete s; assert(seen_acc == a->all_acceptance_conditions()); res->merge_transitions(); return res; } }