Commit 49701ca3 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz

dotty: get rid of the decorated version

* src/tgbaalgos/dottydec.cc, src/tgbaalgos/dottydec.hh,
src/tgbaalgos/rundotdec.cc, src/tgbaalgos/rundotdec.hh: Delete.
* src/tgbaalgos/Makefile.am, wrap/python/spot.i: Adjust.
* src/tgbaalgos/dotty.cc, src/tgbaalgos/dotty.hh: Remove the
decorated version, and the related arguments.
* src/bin/common_aoutput.cc, src/bin/dstar2tgba.cc,
src/tgbatest/ltl2tgba.cc, src/tgbatest/complementation.cc,
src/tgbatest/emptchk.cc: Adjust calls.
* wrap/python/ajax/spot.in: Draw the accepting run as an
automaton instead of painting it.
* wrap/python/ajax/ltl2tgba.html: Update help text.
parent 947ab17b
......@@ -236,10 +236,7 @@ automaton_printer::print(const spot::tgba_digraph_ptr& aut,
// Do not output anything.
break;
case Dot:
spot::dotty_reachable(std::cout, aut,
(type == spot::postprocessor::BA)
|| (type == spot::postprocessor::Monitor),
opt_dot);
spot::dotty_reachable(std::cout, aut, opt_dot);
break;
case Lbtt:
spot::lbtt_reachable(std::cout, aut, type == spot::postprocessor::BA);
......
......@@ -353,10 +353,7 @@ namespace
switch (format)
{
case Dot:
spot::dotty_reachable(std::cout, aut,
(type == spot::postprocessor::BA)
|| (type == spot::postprocessor::Monitor),
opt_dot);
spot::dotty_reachable(std::cout, aut, opt_dot);
break;
case Lbtt:
spot::lbtt_reachable(std::cout, aut, type == spot::postprocessor::BA);
......
......@@ -36,7 +36,6 @@ tgbaalgos_HEADERS = \
cycles.hh \
dtgbacomp.hh \
degen.hh \
dottydec.hh \
dotty.hh \
dtbasat.hh \
dtgbasat.hh \
......@@ -62,7 +61,6 @@ tgbaalgos_HEADERS = \
reachiter.hh \
reducerun.hh \
replayrun.hh \
rundotdec.hh \
safety.hh \
save.hh \
sccfilter.hh \
......@@ -89,7 +87,6 @@ libtgbaalgos_la_SOURCES = \
dtgbacomp.cc \
degen.cc \
dotty.cc \
dottydec.cc \
dtbasat.cc \
dtgbasat.cc \
dupexp.cc \
......@@ -114,7 +111,6 @@ libtgbaalgos_la_SOURCES = \
reachiter.cc \
reducerun.cc \
replayrun.cc \
rundotdec.cc \
safety.cc \
save.cc \
scc.cc \
......
......@@ -24,7 +24,6 @@
#include <stdexcept>
#include "tgba/tgbagraph.hh"
#include "dotty.hh"
#include "dottydec.hh"
#include "tgba/bddprint.hh"
#include "reachiter.hh"
#include "misc/escape.hh"
......@@ -168,147 +167,12 @@ namespace spot
end();
}
};
class dotty_bfs : public tgba_reachable_iterator_breadth_first
{
public:
dotty_bfs(std::ostream& os, const_tgba_ptr a, bool mark_accepting_states,
const char* options, dotty_decorator* dd)
: tgba_reachable_iterator_breadth_first(a), os_(os),
mark_accepting_states_(mark_accepting_states), dd_(dd),
sba_(std::dynamic_pointer_cast<const tgba_digraph>(a))
{
if (options)
while (char c = *options++)
switch (c)
{
case 'c':
opt_circles = true;
break;
case 'h':
opt_horizontal = true;
break;
case 'n':
opt_name = true;
break;
case 'N':
opt_name = false;
break;
case 'v':
opt_horizontal = false;
break;
case 't':
mark_accepting_states_ = false;
break;
default:
throw std::runtime_error
(std::string("unknown option for dotty(): ") + c);
}
}
void
start()
{
os_ << "digraph G {\n";
if (opt_horizontal)
os_ << " rankdir=LR\n";
if (opt_name)
if (auto n = aut_->get_named_prop<std::string>("automaton-name"))
escape_str(os_ << " label=\"", *n) << "\"\n labelloc=\"t\"\n";
if (opt_circles)
os_ << " node [shape=\"circle\"]\n";
os_ << " 0 [label=\"\", style=invis, ";
os_ << (opt_horizontal ? "width" : "height");
os_ << "=0]\n 0 -> 1\n";
}
void
end()
{
os_ << '}' << std::endl;
}
void
process_state(const state* s, int n, tgba_succ_iterator* si)
{
bool accepting;
if (mark_accepting_states_)
{
if (sba_)
{
accepting = sba_->state_is_accepting(s);
}
else
{
si->first();
auto a = si->current_acceptance_conditions();
accepting = !si->done() && aut_->acc().accepting(a);
}
}
else
{
accepting = false;
}
os_ << " " << n << ' '
<< dd_->state_decl(aut_, s, n, si,
escape_str(aut_->format_state(s)),
accepting)
<< '\n';
}
void
process_link(const state* in_s, int in,
const state* out_s, int out, const tgba_succ_iterator* si)
{
std::string label =
bdd_format_formula(aut_->get_dict(),
si->current_condition());
if (!mark_accepting_states_)
if (auto a = si->current_acceptance_conditions())
{
label += "\n";
label += aut_->acc().format(a);
}
std::string s = aut_->transition_annotation(si);
if (!s.empty())
{
if (*label.rbegin() != '\n')
label += '\n';
label += s;
}
os_ << " " << in << " -> " << out << ' '
<< dd_->link_decl(aut_, in_s, in, out_s, out, si,
escape_str(label))
<< '\n';
}
private:
std::ostream& os_;
bool mark_accepting_states_;
dotty_decorator* dd_;
const_tgba_digraph_ptr sba_;
bool opt_horizontal = true;
bool opt_name = true;
bool opt_circles = false;
};
}
} // anonymous namespace
std::ostream&
dotty_reachable(std::ostream& os, const const_tgba_ptr& g,
bool assume_sba, const char* options,
dotty_decorator* dd)
const char* options)
{
if (dd)
{
dotty_bfs d(os, g, assume_sba || g->has_state_based_acc(), options, dd);
d.run();
return os;
}
dotty_output d(os, options);
auto aut = std::dynamic_pointer_cast<const tgba_digraph>(g);
if (!aut)
......
// -*- coding: utf-8 -*-
// Copyright (C) 2011, 2012, 2013, 2014 Laboratoire de Recherche et
// Developpement de l'Epita (LRDE).
// Copyright (C) 2011, 2012, 2013, 2014, 2015 Laboratoire de Recherche
// et Developpement 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
// et Marie Curie.
......@@ -29,19 +29,12 @@
namespace spot
{
class dotty_decorator;
/// \ingroup tgba_io
/// \brief Print reachable states in dot format.
///
/// If \a assume_sba is set, this assumes that the automaton
/// is an SBA and use double elipse to mark accepting states.
///
/// The \a dd argument allows to customize the output in various
/// ways. See \ref tgba_dotty "this page" for a list of available
/// decorators. If no decorator is specified, the dotty_decorator
/// is used.
///
/// \param options an optional string of letters, each indicating a
/// different option. Presently the following options are
/// supported: 'v' for vertical output, 'h' for horizontal output,
......@@ -50,9 +43,7 @@ namespace spot
SPOT_API std::ostream&
dotty_reachable(std::ostream& os,
const const_tgba_ptr& g,
bool assume_sba = false,
const char* options = nullptr,
dotty_decorator* dd = nullptr);
const char* options = nullptr);
}
#endif // SPOT_TGBAALGOS_DOTTY_HH
// -*- coding: utf-8 -*-
// Copyright (C) 2011, 2014 Laboratoire de Recherche et Developpement de
// l'Epita (LRDE).
// 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 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 "dottydec.hh"
#include "tgba/tgba.hh"
namespace spot
{
dotty_decorator::dotty_decorator()
{
}
dotty_decorator::~dotty_decorator()
{
}
std::string
dotty_decorator::state_decl(const const_tgba_ptr&, const state*, int,
tgba_succ_iterator*, const std::string& label,
bool accepting)
{
if (accepting)
return "[label=\"" + label + "\", peripheries=2]";
else
return "[label=\"" + label + "\"]";
}
std::string
dotty_decorator::link_decl(const const_tgba_ptr&, const state*, int,
const state*, int,
const tgba_succ_iterator*,
const std::string& label)
{
return "[label=\"" + label + "\"]";
}
dotty_decorator*
dotty_decorator::instance()
{
static dotty_decorator d;
return &d;
}
}
// -*- coding: utf-8 -*-
// Copyright (C) 2011, 2013, 2014 Laboratoire de Recherche et
// Developpement de l'Epita (LRDE).
// 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 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/>.
#ifndef SPOT_TGBAALGOS_DOTTYDEC_HH
# define SPOT_TGBAALGOS_DOTTYDEC_HH
# include "misc/common.hh"
# include <string>
# include <tgba/fwd.hh>
namespace spot
{
class state;
class tgba_succ_iterator;
/// \addtogroup tgba_dotty Decorating the dot output
/// \ingroup tgba_io
/// \ingroup tgba_dotty
/// \brief Choose state and link styles for spot::dotty_reachable.
class SPOT_API dotty_decorator
{
public:
virtual ~dotty_decorator();
/// \brief Compute the style of a state.
///
/// This function should output a string of the form
/// <code>[label="foo", style=bar, ...]</code>. The
/// default implementation will simply output <code>[label="LABEL"]</code>
/// with <code>LABEL</code> replaced by the value of \a label.
///
/// \param a the automaton being drawn
/// \param s the state being drawn (owned by the caller)
/// \param n a unique number for this state
/// \param si an iterator over the successors of this state (owned by the
/// caller, but can be freely iterated)
/// \param label the computed name of this state
/// \param accepting whether the state is accepting (it makes sense only
/// for state-acceptance automata)
virtual std::string state_decl(const const_tgba_ptr& a,
const state* s, int n,
tgba_succ_iterator* si,
const std::string& label,
bool accepting);
/// \brief Compute the style of a link.
///
/// This function should output a string of the form
/// <code>[label="foo", style=bar, ...]</code>. The
/// default implementation will simply output <code>[label="LABEL"]</code>
/// with <code>LABEL</code> replaced by the value of \a label.
///
/// \param a the automaton being drawn
/// \param in_s the source state of the transition being drawn
/// (owned by the caller)
/// \param in the unique number associated to \a in_s
/// \param out_s the destination state of the transition being drawn
/// (owned by the caller)
/// \param out the unique number associated to \a out_s
/// \param si an iterator over the successors of \a in_s, pointing to
/// the current transition (owned by the caller and cannot
/// be iterated)
/// \param label the computed name of this state
virtual std::string link_decl(const const_tgba_ptr& a,
const state* in_s, int in,
const state* out_s, int out,
const tgba_succ_iterator* si,
const std::string& label);
/// Get the unique instance of the default dotty_decorator.
static dotty_decorator* instance();
protected:
dotty_decorator();
};
}
#endif // SPOT_TGBAALGOS_DOTTYDEC_HH
// -*- coding: utf-8 -*-
// Copyright (C) 2014 Laboratoire de Recherche et Developpement
// de l'Epita (LRDE).
// Copyright (C) 2004, 2011 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 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 <sstream>
#include "rundotdec.hh"
namespace spot
{
tgba_run_dotty_decorator::tgba_run_dotty_decorator(const
const_tgba_run_ptr& run)
: run_(run)
{
int n = 1;
for (tgba_run::steps::const_iterator i = run->prefix.begin();
i != run->prefix.end(); ++i, ++n)
map_[i->s].first.emplace_back(i, n);
for (tgba_run::steps::const_iterator i = run->cycle.begin();
i != run->cycle.end(); ++i, ++n)
map_[i->s].second.emplace_back(i, n);
}
tgba_run_dotty_decorator::~tgba_run_dotty_decorator()
{
}
std::string
tgba_run_dotty_decorator::state_decl(const const_tgba_ptr&,
const state* s, int,
tgba_succ_iterator*,
const std::string& label,
bool accepting)
{
step_map::const_iterator i = map_.find(s);
std::string acc = accepting ? ", peripheries=2" : "";
if (i == map_.end())
return "[label=\"" + label + acc + "\"]";
std::ostringstream os;
std::string sep = "(";
bool in_prefix = false;
bool in_cycle = false;
for (auto j: i->second.first)
{
os << sep << j.second;
sep = ", ";
in_prefix = true;
}
if (sep == ", ")
sep = "; ";
for (auto j: i->second.second)
{
os << sep << j.second;
sep = ", ";
in_cycle = true;
}
assert(in_cycle || in_prefix);
os << ")\\n" << label;
std::string color = in_prefix ? (in_cycle ? "violet" : "blue") : "red";
return "[label=\"" + os.str() + "\", style=bold, color="
+ color + acc + "]";
}
std::string
tgba_run_dotty_decorator::link_decl(const const_tgba_ptr&,
const state* in_s, int,
const state* out_s, int,
const tgba_succ_iterator* si,
const std::string& label)
{
step_map::const_iterator i = map_.find(in_s);
if (i != map_.end())
{
std::ostringstream os;
std::string sep = "(";
bool in_prefix = false;
bool in_cycle = false;
for (step_set::const_iterator j = i->second.first.begin();
j != i->second.first.end(); ++j)
if (j->first->label == si->current_condition()
&& j->first->acc == si->current_acceptance_conditions())
{
tgba_run::steps::const_iterator j2 = j->first;
++j2;
if (j2 == run_->prefix.end())
j2 = run_->cycle.begin();
if (out_s->compare(j2->s))
continue;
os << sep << j->second;
sep = ", ";
in_prefix = true;
}
if (sep == ", ")
sep = "; ";
for (step_set::const_iterator j = i->second.second.begin();
j != i->second.second.end(); ++j)
if (j->first->label == si->current_condition()
&& j->first->acc == si->current_acceptance_conditions())
{
tgba_run::steps::const_iterator j2 = j->first;
++j2;
if (j2 == run_->cycle.end())
j2 = run_->cycle.begin();
if (out_s->compare(j2->s))
continue;
os << sep << j->second;
sep = ", ";
in_cycle = true;
}
os << ")\\n";
if (in_prefix || in_cycle)
{
std::string
color = in_prefix ? (in_cycle ? "violet" : "blue") : "red";
return ("[label=\"" + os.str() + label
+ "\", style=bold, color=" + color + "]");
}
}
return "[label=\"" + label + "\"]";
}
}
// -*- coding: utf-8 -*-
// Copyright (C) 2011, 2013, 2014 Laboratoire de Recherche et Developpement
// de l'Epita (LRDE).
// 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 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/>.
#ifndef SPOT_TGBAALGOS_RUNDOTDEC_HH
# define SPOT_TGBAALGOS_RUNDOTDEC_HH
#include <map>
#include <utility>
#include <list>
#include "dottydec.hh"
#include "emptiness.hh"
namespace spot
{
/// \ingroup tgba_dotty
/// \brief Highlight a spot::tgba_run on a spot::tgba.
///
/// An instance of this class can be passed to spot::dotty_reachable.
class SPOT_API tgba_run_dotty_decorator: public dotty_decorator
{
public:
tgba_run_dotty_decorator(const const_tgba_run_ptr& run);
virtual ~tgba_run_dotty_decorator();
virtual std::string state_decl(const const_tgba_ptr& a,
const state* s, int n,
tgba_succ_iterator* si,
const std::string& label,
bool accepting);
virtual std::string link_decl(const const_tgba_ptr& a,
const state* in_s, int in,
const state* out_s, int out,
const tgba_succ_iterator* si,
const std::string& label);
private:
const_tgba_run_ptr run_;
typedef std::pair<tgba_run::steps::const_iterator, int> step_num;
typedef std::list<step_num> step_set;
typedef std::map<const state*, std::pair<step_set,