rewrite explicit Kripke structures and their parser
Fixes #4 and fixes #5. * NEWS: Mention the change. * src/kripkeparse/: Delete. * README, src/Makefile.am, configure.ac: Adjust. * src/kripke/kripkeexplicit.cc, src/kripke/kripkeexplicit.hh, src/kripke/kripkeprint.cc, src/kripke/kripkeprint.hh: Delete. * src/kripke/kripkegraph.hh: New file. * src/kripke/Makefile.am: Adjust. * src/parseaut/parseaut.yy, src/parseaut/public.hh: Add an option to read kripke structures. * src/tests/bad_parsing.test: Delete. * src/tests/Makefile.am: Adjust. * src/tests/kripke.test, src/tests/parse_print_test.cc: Rewrite. * src/tests/ikwiad.cc, src/tests/parseaut.test, iface/ltsmin/modelcheck.cc, wrap/python/spot_impl.i: Adjust.
This commit is contained in:
parent
073d154540
commit
afbaa54d92
27 changed files with 670 additions and 1472 deletions
|
|
@ -26,12 +26,9 @@ kripke_HEADERS = \
|
|||
fairkripke.hh \
|
||||
fwd.hh \
|
||||
kripke.hh \
|
||||
kripkeexplicit.hh \
|
||||
kripkeprint.hh
|
||||
kripkegraph.hh
|
||||
|
||||
noinst_LTLIBRARIES = libkripke.la
|
||||
libkripke_la_SOURCES = \
|
||||
fairkripke.cc \
|
||||
kripke.cc \
|
||||
kripkeexplicit.cc \
|
||||
kripkeprint.cc
|
||||
kripke.cc
|
||||
|
|
|
|||
|
|
@ -1,269 +0,0 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2011, 2012, 2013, 2014, 2015 Laboratoire de Recherche et
|
||||
// Developpement 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 "kripkeexplicit.hh"
|
||||
#include "twa/bddprint.hh"
|
||||
#include "twa/formula2bdd.hh"
|
||||
#include <iostream>
|
||||
|
||||
namespace spot
|
||||
{
|
||||
|
||||
state_kripke::state_kripke()
|
||||
: bdd_ (bddtrue)
|
||||
{
|
||||
}
|
||||
|
||||
void state_kripke::add_conditions(bdd f)
|
||||
{
|
||||
bdd_ &= f;
|
||||
}
|
||||
|
||||
void state_kripke::add_succ(state_kripke* add_me)
|
||||
{
|
||||
// This method must add only state_kripke for now.
|
||||
state_kripke* to_add = down_cast<state_kripke*>(add_me);
|
||||
assert(to_add);
|
||||
succ_.push_back(to_add);
|
||||
}
|
||||
|
||||
int state_kripke::compare(const state* other) const
|
||||
{
|
||||
// This method should not be called to compare states from different
|
||||
// automata, and all states from the same automaton will use the same
|
||||
// state class.
|
||||
const state_kripke* s = down_cast<const state_kripke*>(other);
|
||||
assert(s);
|
||||
return s - this;
|
||||
}
|
||||
|
||||
size_t
|
||||
state_kripke::hash() const
|
||||
{
|
||||
return
|
||||
reinterpret_cast<const char*>(this) - static_cast<const char*>(nullptr);
|
||||
}
|
||||
|
||||
state_kripke*
|
||||
state_kripke::clone() const
|
||||
{
|
||||
return const_cast<state_kripke*>(this);
|
||||
}
|
||||
|
||||
////////////////////////////
|
||||
// Support for succ_iterator
|
||||
|
||||
const std::list<state_kripke*>&
|
||||
state_kripke::get_succ() const
|
||||
{
|
||||
return succ_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// kripke_explicit_succ_iterator
|
||||
|
||||
kripke_explicit_succ_iterator::kripke_explicit_succ_iterator
|
||||
(const state_kripke* s, bdd cond)
|
||||
: kripke_succ_iterator(cond),
|
||||
s_(s)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
kripke_explicit_succ_iterator::~kripke_explicit_succ_iterator()
|
||||
{
|
||||
}
|
||||
|
||||
bool kripke_explicit_succ_iterator::first()
|
||||
{
|
||||
it_ = s_->get_succ().begin();
|
||||
return it_ != s_->get_succ().end();
|
||||
}
|
||||
|
||||
bool kripke_explicit_succ_iterator::next()
|
||||
{
|
||||
++it_;
|
||||
return it_ != s_->get_succ().end();
|
||||
}
|
||||
|
||||
bool kripke_explicit_succ_iterator::done() const
|
||||
{
|
||||
return it_ == s_->get_succ().end();
|
||||
}
|
||||
|
||||
state_kripke* kripke_explicit_succ_iterator::dst() const
|
||||
{
|
||||
assert(!done());
|
||||
return *it_;
|
||||
}
|
||||
|
||||
/////////////////////////////////////
|
||||
// kripke_explicit
|
||||
|
||||
|
||||
kripke_explicit::kripke_explicit(const bdd_dict_ptr& dict,
|
||||
state_kripke* init)
|
||||
: kripke(dict),
|
||||
init_(init)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
kripke_explicit::format_state(const spot::state* s) const
|
||||
{
|
||||
assert(s);
|
||||
const state_kripke* se = down_cast<const state_kripke*>(s);
|
||||
assert(se);
|
||||
std::map<const state_kripke*, std::string>::const_iterator it =
|
||||
sn_nodes_.find (se);
|
||||
assert(it != sn_nodes_.end());
|
||||
return it->second;
|
||||
}
|
||||
|
||||
kripke_explicit::~kripke_explicit()
|
||||
{
|
||||
get_dict()->unregister_all_my_variables(this);
|
||||
std::map<const std::string, state_kripke*>::iterator it;
|
||||
for (it = ns_nodes_.begin(); it != ns_nodes_.end(); ++it)
|
||||
{
|
||||
state_kripke* del_me = it->second;
|
||||
delete del_me;
|
||||
}
|
||||
}
|
||||
|
||||
state_kripke*
|
||||
kripke_explicit::get_init_state() const
|
||||
{
|
||||
return init_;
|
||||
}
|
||||
|
||||
// FIXME: Change the bddtrue.
|
||||
kripke_explicit_succ_iterator*
|
||||
kripke_explicit::succ_iter(const spot::state* st) const
|
||||
{
|
||||
const state_kripke* s = down_cast<const state_kripke*>(st);
|
||||
assert(s);
|
||||
state_kripke* it = const_cast<state_kripke*>(s);
|
||||
return new kripke_explicit_succ_iterator(it, bddtrue);
|
||||
}
|
||||
|
||||
bdd
|
||||
kripke_explicit::state_condition(const state* s) const
|
||||
{
|
||||
const state_kripke* f = down_cast<const state_kripke*>(s);
|
||||
assert(f);
|
||||
return (f->as_bdd());
|
||||
}
|
||||
|
||||
bdd
|
||||
kripke_explicit::state_condition(const std::string& name) const
|
||||
{
|
||||
std::map<const std::string, state_kripke*>::const_iterator it;
|
||||
it = ns_nodes_.find(name);
|
||||
assert(it != ns_nodes_.end());
|
||||
return state_condition(it->second);
|
||||
}
|
||||
|
||||
const std::map<const state_kripke*, std::string>&
|
||||
kripke_explicit::sn_get() const
|
||||
{
|
||||
return sn_nodes_;
|
||||
}
|
||||
|
||||
|
||||
void kripke_explicit::add_state(std::string name,
|
||||
state_kripke* state)
|
||||
{
|
||||
if (ns_nodes_.find(name) == ns_nodes_.end())
|
||||
{
|
||||
ns_nodes_[name] = state;
|
||||
sn_nodes_[state] = name;
|
||||
if (!init_)
|
||||
init_ = state;
|
||||
}
|
||||
}
|
||||
|
||||
void kripke_explicit::add_state(std::string name)
|
||||
{
|
||||
if (ns_nodes_.find(name) == ns_nodes_.end())
|
||||
{
|
||||
state_kripke* state = new state_kripke;
|
||||
add_state(name, state);
|
||||
}
|
||||
}
|
||||
|
||||
void kripke_explicit::add_transition(state_kripke* source,
|
||||
const state_kripke* dest)
|
||||
{
|
||||
state_kripke* Dest = const_cast<state_kripke*>(dest);
|
||||
source->add_succ(Dest);
|
||||
}
|
||||
|
||||
void kripke_explicit::add_transition(std::string source,
|
||||
const state_kripke* dest)
|
||||
{
|
||||
add_transition(ns_nodes_[source], dest);
|
||||
}
|
||||
|
||||
void kripke_explicit::add_transition(std::string source,
|
||||
std::string dest)
|
||||
{
|
||||
auto destination = ns_nodes_.find(dest);
|
||||
if (destination == ns_nodes_.end())
|
||||
{
|
||||
state_kripke* neo = new state_kripke;
|
||||
add_state(dest, neo);
|
||||
add_transition(source, neo);
|
||||
}
|
||||
else
|
||||
{
|
||||
add_transition(source, destination->second);
|
||||
}
|
||||
}
|
||||
|
||||
void kripke_explicit::add_conditions(bdd add,
|
||||
state_kripke* on_me)
|
||||
{
|
||||
on_me->add_conditions(add);
|
||||
}
|
||||
|
||||
void kripke_explicit::add_conditions(bdd add,
|
||||
std::string on_me)
|
||||
{
|
||||
add_conditions(add, ns_nodes_[on_me]);
|
||||
}
|
||||
|
||||
|
||||
void kripke_explicit::add_condition(formula f, std::string on_me)
|
||||
{
|
||||
add_conditions(formula_to_bdd(f, get_dict(), this), on_me);
|
||||
}
|
||||
|
||||
|
||||
} // End namespace spot.
|
||||
|
|
@ -1,184 +0,0 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2011, 2012, 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 <iosfwd>
|
||||
#include "kripke.hh"
|
||||
#include "tl/formula.hh"
|
||||
#include "kripkeprint.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
/// \brief Concrete class for kripke states.
|
||||
class SPOT_API state_kripke : public state
|
||||
{
|
||||
friend class kripke_explicit;
|
||||
friend class kripke_explicit_succ_iterator;
|
||||
private:
|
||||
state_kripke();
|
||||
|
||||
/// \brief Compare two states.
|
||||
///
|
||||
/// This method returns an integer less than, equal to, or greater
|
||||
/// than zero if \a this is found, respectively, to be less than, equal
|
||||
/// to, or greater than \a other according to some implicit total order.
|
||||
///
|
||||
/// For moment, this method only compare the adress on the heap of the
|
||||
/// twice pointers.
|
||||
virtual int compare (const state* other) const;
|
||||
|
||||
/// \brief Hash a state
|
||||
virtual size_t hash() const;
|
||||
|
||||
/// \brief Duplicate a state.
|
||||
virtual state_kripke* clone() const;
|
||||
|
||||
/// \brief Add a condition to the conditions already in the state.
|
||||
/// \param f The condition to add.
|
||||
void add_conditions(bdd f);
|
||||
|
||||
/// \brief Add a new successor in the list.
|
||||
/// \param succ The successor state to add.
|
||||
void add_succ(state_kripke* succ);
|
||||
|
||||
virtual bdd
|
||||
as_bdd() const
|
||||
{
|
||||
return bdd_;
|
||||
}
|
||||
|
||||
/// \brief Release a state.
|
||||
///
|
||||
virtual void
|
||||
destroy() const
|
||||
{
|
||||
}
|
||||
|
||||
virtual
|
||||
~state_kripke ()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Management for succ_iterator
|
||||
|
||||
const std::list<state_kripke*>& get_succ() const;
|
||||
|
||||
bdd bdd_;
|
||||
std::list<state_kripke*> succ_;
|
||||
};
|
||||
|
||||
|
||||
/// \class kripke_explicit_succ_iterator
|
||||
/// \brief Implement iterator pattern on successor of a state_kripke.
|
||||
class SPOT_API kripke_explicit_succ_iterator : public kripke_succ_iterator
|
||||
{
|
||||
public:
|
||||
kripke_explicit_succ_iterator(const state_kripke*, bdd);
|
||||
|
||||
~kripke_explicit_succ_iterator();
|
||||
|
||||
virtual bool first();
|
||||
virtual bool next();
|
||||
virtual bool done() const;
|
||||
|
||||
virtual state_kripke* dst() const;
|
||||
|
||||
private:
|
||||
const state_kripke* s_;
|
||||
std::list<state_kripke*>::const_iterator it_;
|
||||
};
|
||||
|
||||
|
||||
/// \class kripke_explicit
|
||||
/// \brief Kripke Structure.
|
||||
class SPOT_API kripke_explicit : public kripke
|
||||
{
|
||||
public:
|
||||
kripke_explicit(const bdd_dict_ptr&, state_kripke* = nullptr);
|
||||
~kripke_explicit();
|
||||
|
||||
state_kripke* get_init_state() const;
|
||||
|
||||
/// \brief Allow to get an iterator on the state we passed in
|
||||
/// parameter.
|
||||
kripke_explicit_succ_iterator*
|
||||
succ_iter(const spot::state* state) const;
|
||||
|
||||
/// \brief Get the condition on the state
|
||||
bdd state_condition(const state* s) const;
|
||||
/// \brief Get the condition on the state
|
||||
bdd state_condition(const std::string&) const;
|
||||
|
||||
/// \brief Return the name of the state.
|
||||
std::string format_state(const state*) const;
|
||||
|
||||
|
||||
/// \brief Create state, if it does not already exists.
|
||||
///
|
||||
/// Used by the parser.
|
||||
void add_state(std::string);
|
||||
|
||||
/// \brief Add a transition between two states.
|
||||
void add_transition(std::string source,
|
||||
std::string dest);
|
||||
|
||||
/// \brief Add a BDD condition to the state
|
||||
///
|
||||
/// \param add the condition.
|
||||
/// \param on_me where add the condition.
|
||||
void add_conditions(bdd add,
|
||||
std::string on_me);
|
||||
|
||||
/// \brief Add a formula to the state corresponding to the name.
|
||||
///
|
||||
/// \param f the formula to add.
|
||||
/// \param on_me the state where to add.
|
||||
void add_condition(formula f, std::string on_me);
|
||||
|
||||
/// \brief Return map between states and their names.
|
||||
const std::map<const state_kripke*, std::string>&
|
||||
sn_get() const;
|
||||
|
||||
private:
|
||||
/// \brief Add a state in the two maps.
|
||||
void add_state(std::string, state_kripke*);
|
||||
|
||||
void add_conditions(bdd add,
|
||||
state_kripke* on_me);
|
||||
|
||||
void add_transition(std::string source,
|
||||
const state_kripke* dest);
|
||||
|
||||
void add_transition(state_kripke* source,
|
||||
const state_kripke* dest);
|
||||
|
||||
state_kripke* init_;
|
||||
std::map<const std::string, state_kripke*> ns_nodes_;
|
||||
std::map<const state_kripke*, std::string> sn_nodes_;
|
||||
};
|
||||
|
||||
inline kripke_explicit_ptr
|
||||
make_kripke_explicit(const bdd_dict_ptr& d,
|
||||
state_kripke* init = nullptr)
|
||||
{
|
||||
return std::make_shared<kripke_explicit>(d, init);
|
||||
}
|
||||
}
|
||||
283
src/kripke/kripkegraph.hh
Normal file
283
src/kripke/kripkegraph.hh
Normal file
|
|
@ -0,0 +1,283 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2011, 2012, 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 <iosfwd>
|
||||
#include "kripke.hh"
|
||||
#include "graph/graph.hh"
|
||||
#include "tl/formula.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
/// \brief Concrete class for kripke_graph states.
|
||||
struct SPOT_API kripke_graph_state: public spot::state
|
||||
{
|
||||
public:
|
||||
kripke_graph_state(bdd cond = bddfalse) noexcept
|
||||
: cond_(cond)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~kripke_graph_state() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
virtual int compare(const spot::state* other) const
|
||||
{
|
||||
auto o = down_cast<const kripke_graph_state*>(other);
|
||||
assert(o);
|
||||
|
||||
// Do not simply return "other - this", it might not fit in an int.
|
||||
if (o < this)
|
||||
return -1;
|
||||
if (o > this)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual size_t hash() const
|
||||
{
|
||||
return
|
||||
reinterpret_cast<const char*>(this) - static_cast<const char*>(nullptr);
|
||||
}
|
||||
|
||||
virtual kripke_graph_state*
|
||||
clone() const
|
||||
{
|
||||
return const_cast<kripke_graph_state*>(this);
|
||||
}
|
||||
|
||||
virtual void destroy() const
|
||||
{
|
||||
}
|
||||
|
||||
bdd cond() const
|
||||
{
|
||||
return cond_;
|
||||
}
|
||||
|
||||
void cond(bdd c)
|
||||
{
|
||||
cond_ = c;
|
||||
}
|
||||
|
||||
private:
|
||||
bdd cond_;
|
||||
};
|
||||
|
||||
template<class Graph>
|
||||
class SPOT_API kripke_graph_succ_iterator final: public kripke_succ_iterator
|
||||
{
|
||||
private:
|
||||
typedef typename Graph::edge edge;
|
||||
typedef typename Graph::state_data_t state;
|
||||
const Graph* g_;
|
||||
edge t_;
|
||||
edge p_;
|
||||
public:
|
||||
kripke_graph_succ_iterator(const Graph* g,
|
||||
const typename Graph::state_storage_t* s):
|
||||
kripke_succ_iterator(s->cond()),
|
||||
g_(g),
|
||||
t_(s->succ)
|
||||
{
|
||||
}
|
||||
|
||||
~kripke_graph_succ_iterator()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void recycle(const typename Graph::state_storage_t* s)
|
||||
{
|
||||
cond_ = s->cond();
|
||||
t_ = s->succ;
|
||||
}
|
||||
|
||||
virtual bool first()
|
||||
{
|
||||
p_ = t_;
|
||||
return p_;
|
||||
}
|
||||
|
||||
virtual bool next()
|
||||
{
|
||||
p_ = g_->edge_storage(p_).next_succ;
|
||||
return p_;
|
||||
}
|
||||
|
||||
virtual bool done() const
|
||||
{
|
||||
return !p_;
|
||||
}
|
||||
|
||||
virtual kripke_graph_state* dst() const
|
||||
{
|
||||
assert(!done());
|
||||
return const_cast<kripke_graph_state*>
|
||||
(&g_->state_data(g_->edge_storage(p_).dst));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/// \class kripke_graph
|
||||
/// \brief Kripke Structure.
|
||||
class SPOT_API kripke_graph : public kripke
|
||||
{
|
||||
public:
|
||||
typedef digraph<kripke_graph_state, void> graph_t;
|
||||
typedef graph_t::edge_storage_t edge_storage_t;
|
||||
protected:
|
||||
graph_t g_;
|
||||
mutable unsigned init_number_;
|
||||
public:
|
||||
kripke_graph(const bdd_dict_ptr& d)
|
||||
: kripke(d), init_number_(0)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~kripke_graph()
|
||||
{
|
||||
get_dict()->unregister_all_my_variables(this);
|
||||
}
|
||||
|
||||
unsigned num_states() const
|
||||
{
|
||||
return g_.num_states();
|
||||
}
|
||||
|
||||
unsigned num_edges() const
|
||||
{
|
||||
return g_.num_edges();
|
||||
}
|
||||
|
||||
void set_init_state(graph_t::state s)
|
||||
{
|
||||
assert(s < num_states());
|
||||
init_number_ = s;
|
||||
}
|
||||
|
||||
graph_t::state get_init_state_number() const
|
||||
{
|
||||
if (num_states() == 0)
|
||||
const_cast<graph_t&>(g_).new_state();
|
||||
return init_number_;
|
||||
}
|
||||
|
||||
// FIXME: The return type ought to be const.
|
||||
virtual kripke_graph_state* get_init_state() const
|
||||
{
|
||||
if (num_states() == 0)
|
||||
const_cast<graph_t&>(g_).new_state();
|
||||
return const_cast<kripke_graph_state*>(state_from_number(init_number_));
|
||||
}
|
||||
|
||||
/// \brief Allow to get an iterator on the state we passed in
|
||||
/// parameter.
|
||||
virtual kripke_graph_succ_iterator<graph_t>*
|
||||
succ_iter(const spot::state* st) const
|
||||
{
|
||||
auto s = down_cast<const typename graph_t::state_storage_t*>(st);
|
||||
assert(s);
|
||||
assert(!s->succ || g_.valid_trans(s->succ));
|
||||
|
||||
if (this->iter_cache_)
|
||||
{
|
||||
auto it =
|
||||
down_cast<kripke_graph_succ_iterator<graph_t>*>(this->iter_cache_);
|
||||
it->recycle(s);
|
||||
this->iter_cache_ = nullptr;
|
||||
return it;
|
||||
}
|
||||
return new kripke_graph_succ_iterator<graph_t>(&g_, s);
|
||||
|
||||
}
|
||||
|
||||
graph_t::state
|
||||
state_number(const state* st) const
|
||||
{
|
||||
auto s = down_cast<const typename graph_t::state_storage_t*>(st);
|
||||
assert(s);
|
||||
return s - &g_.state_storage(0);
|
||||
}
|
||||
|
||||
const kripke_graph_state*
|
||||
state_from_number(graph_t::state n) const
|
||||
{
|
||||
return &g_.state_data(n);
|
||||
}
|
||||
|
||||
kripke_graph_state*
|
||||
state_from_number(graph_t::state n)
|
||||
{
|
||||
return &g_.state_data(n);
|
||||
}
|
||||
|
||||
std::string format_state(unsigned n) const
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << n;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
virtual std::string format_state(const state* st) const
|
||||
{
|
||||
return format_state(state_number(st));
|
||||
}
|
||||
|
||||
/// \brief Get the condition on the state
|
||||
virtual bdd state_condition(const state* s) const
|
||||
{
|
||||
return down_cast<const kripke_graph_state*>(s)->cond();
|
||||
}
|
||||
|
||||
edge_storage_t& edge_storage(unsigned t)
|
||||
{
|
||||
return g_.edge_storage(t);
|
||||
}
|
||||
|
||||
const edge_storage_t edge_storage(unsigned t) const
|
||||
{
|
||||
return g_.edge_storage(t);
|
||||
}
|
||||
|
||||
unsigned new_state(bdd cond)
|
||||
{
|
||||
return g_.new_state(cond);
|
||||
}
|
||||
|
||||
unsigned new_states(unsigned n, bdd cond)
|
||||
{
|
||||
return g_.new_states(n, cond);
|
||||
}
|
||||
|
||||
unsigned new_edge(unsigned src, unsigned dst)
|
||||
{
|
||||
return g_.new_edge(src, dst);
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<kripke_graph> kripke_graph_ptr;
|
||||
|
||||
inline kripke_graph_ptr
|
||||
make_kripke_graph(const bdd_dict_ptr& d)
|
||||
{
|
||||
return std::make_shared<kripke_graph>(d);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2011, 2012, 2014 Laboratoire de Recherche et
|
||||
// Developpement 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 "kripkeprint.hh"
|
||||
#include "kripkeexplicit.hh"
|
||||
#include "twa/bddprint.hh"
|
||||
#include "misc/escape.hh"
|
||||
#include "twaalgos/reachiter.hh"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace spot
|
||||
{
|
||||
namespace
|
||||
{
|
||||
|
||||
class kripke_printer : public tgba_reachable_iterator_breadth_first
|
||||
{
|
||||
public:
|
||||
kripke_printer(const const_kripke_ptr& a, std::ostream& os)
|
||||
: tgba_reachable_iterator_breadth_first(a), os_(os)
|
||||
{
|
||||
}
|
||||
|
||||
void process_state(const state* s, int, twa_succ_iterator* si)
|
||||
{
|
||||
const bdd_dict_ptr d = aut_->get_dict();
|
||||
os_ << '"';
|
||||
escape_str(os_, aut_->format_state(s));
|
||||
os_ << "\", \"";
|
||||
auto aut = std::static_pointer_cast<const kripke> (aut_);
|
||||
assert(aut);
|
||||
escape_str(os_, bdd_format_formula(d, aut->state_condition(s)));
|
||||
|
||||
os_ << "\",";
|
||||
for (si->first(); !si->done(); si->next())
|
||||
{
|
||||
state* dest = si->dst();
|
||||
os_ << " \"";
|
||||
escape_str(os_, aut_->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 const_kripke_ptr& 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, twa_succ_iterator*)
|
||||
{
|
||||
if (notfirst)
|
||||
finish_state();
|
||||
else
|
||||
notfirst = true;
|
||||
|
||||
const bdd_dict_ptr d = aut_->get_dict();
|
||||
os_ << 'S' << in_s << ", \"";
|
||||
auto aut = std::static_pointer_cast<const kripke>(aut_);
|
||||
assert(aut);
|
||||
escape_str(os_, bdd_format_formula(d,
|
||||
aut->state_condition(s)));
|
||||
os_ << "\",";
|
||||
}
|
||||
|
||||
void
|
||||
process_link(const state*, int, const state*, int d,
|
||||
const twa_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 const_kripke_ptr& k)
|
||||
{
|
||||
kripke_printer p(k, os);
|
||||
p.run();
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
kripke_save_reachable_renumbered(std::ostream& os, const const_kripke_ptr& k)
|
||||
{
|
||||
kripke_printer_renumbered p(k, os);
|
||||
p.run();
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
} // End namespace Spot
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2011, 2013, 2014 Laboratoire de Recherche et Developpement
|
||||
// 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 "misc/common.hh"
|
||||
#include <iosfwd>
|
||||
#include "kripke.hh"
|
||||
|
||||
namespace spot
|
||||
{
|
||||
|
||||
/// \ingroup twa_io
|
||||
/// \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.
|
||||
///
|
||||
SPOT_API std::ostream&
|
||||
kripke_save_reachable(std::ostream& os, const const_kripke_ptr& k);
|
||||
|
||||
/// \ingroup twa_io
|
||||
/// \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.
|
||||
///
|
||||
SPOT_API std::ostream&
|
||||
kripke_save_reachable_renumbered(std::ostream& os, const const_kripke_ptr& k);
|
||||
|
||||
} // End namespace spot
|
||||
Loading…
Add table
Add a link
Reference in a new issue