deprecate copy() in favor of make_twa_graph()
Fixes #258. * spot/twaalgos/copy.cc: Delete, and move the code... * spot/twa/twagraph.cc: ... in some anonymous namespace here. * spot/twa/twagraph.hh: Adjust the make_twa_graph() overload. * spot/twaalgos/copy.hh, NEWS: Mark copy() as deprecated and redirect to make_twa_graph(). * doc/org/upgrade2.org, doc/org/tut51.org, python/spot/impl.i, spot/twaalgos/dot.cc, spot/twaalgos/langmap.cc, tests/core/ikwiad.cc: Adjust callers. * spot/twaalgos/Makefile.am: Remove copy.cc.
This commit is contained in:
parent
1e9daa73f3
commit
8e685e00c9
12 changed files with 197 additions and 206 deletions
|
|
@ -98,7 +98,6 @@ libtwaalgos_la_SOURCES = \
|
|||
complete.cc \
|
||||
complement.cc \
|
||||
compsusp.cc \
|
||||
copy.cc \
|
||||
cycles.cc \
|
||||
degen.cc \
|
||||
determinize.cc \
|
||||
|
|
|
|||
|
|
@ -1,149 +0,0 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2009, 2011, 2012, 2014, 2015, 2016 Laboratoire de Recherche
|
||||
// et Développement 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.
|
||||
//
|
||||
// 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 <spot/twaalgos/copy.hh>
|
||||
#include <spot/twa/twagraph.hh>
|
||||
#include <deque>
|
||||
|
||||
namespace spot
|
||||
{
|
||||
twa_graph_ptr
|
||||
copy(const const_twa_ptr& aut, twa::prop_set p,
|
||||
bool preserve_names, unsigned max_states)
|
||||
{
|
||||
twa_graph_ptr out = make_twa_graph(aut->get_dict());
|
||||
out->copy_acceptance_of(aut);
|
||||
out->copy_ap_of(aut);
|
||||
out->prop_copy(aut, p);
|
||||
|
||||
std::vector<std::string>* names = nullptr;
|
||||
std::set<unsigned>* incomplete = nullptr;
|
||||
|
||||
// Old highlighting maps
|
||||
typedef std::map<unsigned, unsigned> hmap;
|
||||
hmap* ohstates = nullptr;
|
||||
hmap* ohedges = nullptr;
|
||||
const_twa_graph_ptr aut_g = nullptr;
|
||||
// New highlighting maps
|
||||
hmap* nhstates = nullptr;
|
||||
hmap* nhedges = nullptr;
|
||||
|
||||
if (preserve_names)
|
||||
{
|
||||
names = new std::vector<std::string>;
|
||||
out->set_named_prop("state-names", names);
|
||||
|
||||
// If the input is a twa_graph and we were asked to preserve
|
||||
// names, also preserve highlights.
|
||||
aut_g = std::dynamic_pointer_cast<const twa_graph>(aut);
|
||||
if (aut_g)
|
||||
{
|
||||
ohstates = aut->get_named_prop<hmap>("highlight-states");
|
||||
if (ohstates)
|
||||
nhstates = out->get_or_set_named_prop<hmap>("highlight-states");
|
||||
ohedges = aut->get_named_prop<hmap>("highlight-edges");
|
||||
if (ohedges)
|
||||
nhedges = out->get_or_set_named_prop<hmap>("highlight-edges");
|
||||
}
|
||||
}
|
||||
|
||||
// States already seen.
|
||||
state_map<unsigned> seen;
|
||||
// States to process
|
||||
std::deque<state_map<unsigned>::const_iterator> todo;
|
||||
|
||||
auto new_state = [&](const state* s) -> unsigned
|
||||
{
|
||||
auto p = seen.emplace(s, 0);
|
||||
if (p.second)
|
||||
{
|
||||
p.first->second = out->new_state();
|
||||
todo.emplace_back(p.first);
|
||||
if (names)
|
||||
names->emplace_back(aut->format_state(s));
|
||||
if (ohstates)
|
||||
{
|
||||
auto q = ohstates->find(aut_g->state_number(s));
|
||||
if (q != ohstates->end())
|
||||
nhstates->emplace(p.first->second, q->second);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s->destroy();
|
||||
}
|
||||
return p.first->second;
|
||||
};
|
||||
|
||||
out->set_init_state(new_state(aut->get_init_state()));
|
||||
while (!todo.empty())
|
||||
{
|
||||
const state* src1;
|
||||
unsigned src2;
|
||||
std::tie(src1, src2) = *todo.front();
|
||||
todo.pop_front();
|
||||
for (auto* t: aut->succ(src1))
|
||||
{
|
||||
unsigned edgenum = 0;
|
||||
if (SPOT_UNLIKELY(max_states < out->num_states()))
|
||||
{
|
||||
// If we have reached the max number of state, never try
|
||||
// to create a new one.
|
||||
auto i = seen.find(t->dst());
|
||||
if (i == seen.end())
|
||||
{
|
||||
if (!incomplete)
|
||||
incomplete = new std::set<unsigned>;
|
||||
incomplete->insert(src2);
|
||||
continue;
|
||||
}
|
||||
edgenum = out->new_edge(src2, i->second, t->cond(), t->acc());
|
||||
}
|
||||
else
|
||||
{
|
||||
edgenum =
|
||||
out->new_edge(src2, new_state(t->dst()), t->cond(), t->acc());
|
||||
}
|
||||
if (ohedges)
|
||||
{
|
||||
auto q = ohedges->find(aut_g->edge_number(t));
|
||||
if (q != ohedges->end())
|
||||
nhedges->emplace(edgenum, q->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
auto s = seen.begin();
|
||||
while (s != seen.end())
|
||||
{
|
||||
// Advance the iterator before deleting the "key" pointer.
|
||||
const state* ptr = s->first;
|
||||
++s;
|
||||
ptr->destroy();
|
||||
}
|
||||
|
||||
if (incomplete)
|
||||
out->set_named_prop("incomplete-states", incomplete);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2012, 2013, 2014, 2015, 2016 Laboratoire de Recherche et
|
||||
// Copyright (C) 2012-2017 Laboratoire de Recherche et
|
||||
// Développement de l'Epita (LRDE).
|
||||
// Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de Paris
|
||||
// Copyright (C) 2003-2005 Laboratoire d'Informatique de Paris
|
||||
// 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
|
||||
// Université Pierre et Marie Curie.
|
||||
//
|
||||
|
|
@ -23,18 +23,20 @@
|
|||
#pragma once
|
||||
|
||||
#include <spot/misc/common.hh>
|
||||
#include <spot/twa/fwd.hh>
|
||||
#include <spot/twa/twa.hh>
|
||||
#include <spot/twa/twagraph.hh>
|
||||
|
||||
namespace spot
|
||||
{
|
||||
/// \ingroup twa_misc
|
||||
/// \brief Build an explicit automaton from all states of \a aut,
|
||||
///
|
||||
/// This works using the abstract interface for automata. If you
|
||||
/// have a twa_graph that you want to copy, it is more efficient
|
||||
/// to call make_twa_graph() instead.
|
||||
/// This function was deprecated in Spot 2.4. Use the
|
||||
/// function make_twa_graph() instead.
|
||||
SPOT_DEPRECATED("use make_twa_graph() instead")
|
||||
SPOT_API twa_graph_ptr
|
||||
copy(const const_twa_ptr& aut, twa::prop_set p,
|
||||
bool preserve_names = false, unsigned max_states = -1U);
|
||||
inline copy(const const_twa_ptr& aut, twa::prop_set p,
|
||||
bool preserve_names = false, unsigned max_states = -1U)
|
||||
{
|
||||
return make_twa_graph(aut, p, preserve_names, max_states);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@
|
|||
#include <spot/misc/escape.hh>
|
||||
#include <spot/twa/twagraph.hh>
|
||||
#include <spot/twa/formula2bdd.hh>
|
||||
#include <spot/twaalgos/copy.hh>
|
||||
#include <spot/twaalgos/sccinfo.hh>
|
||||
#include <spot/kripke/fairkripke.hh>
|
||||
#include <cstdlib>
|
||||
|
|
@ -833,7 +832,7 @@ namespace spot
|
|||
d.parse_opts("k");
|
||||
auto aut = std::dynamic_pointer_cast<const twa_graph>(g);
|
||||
if (!aut || (d.max_states_given() && aut->num_states() >= d.max_states()))
|
||||
aut = copy(g, twa::prop_set::all(), true, d.max_states() - 1);
|
||||
aut = make_twa_graph(g, twa::prop_set::all(), true, d.max_states() - 1);
|
||||
d.print(aut);
|
||||
return os;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
#include <numeric>
|
||||
#include <spot/twa/twa.hh>
|
||||
#include <spot/twaalgos/copy.hh>
|
||||
#include <spot/twaalgos/dualize.hh>
|
||||
#include <spot/twaalgos/isdet.hh>
|
||||
#include <spot/twaalgos/langmap.hh>
|
||||
|
|
@ -43,29 +42,26 @@ namespace spot
|
|||
|
||||
// Prepare all automatons needed.
|
||||
for (unsigned i = 0; i < n_states; ++i)
|
||||
{
|
||||
twa_graph_ptr c = copy(aut, twa::prop_set::all());
|
||||
c->set_init_state(i);
|
||||
alt_init_st_auts[i] = c;
|
||||
|
||||
twa_graph_ptr cc =
|
||||
remove_fin(dualize(copy(c, twa::prop_set::all())));
|
||||
compl_alt_init_st_auts[i] = cc;
|
||||
}
|
||||
{
|
||||
twa_graph_ptr c = make_twa_graph(aut, twa::prop_set::all());
|
||||
c->set_init_state(i);
|
||||
alt_init_st_auts[i] = c;
|
||||
compl_alt_init_st_auts[i] = remove_fin(dualize(c));
|
||||
}
|
||||
|
||||
for (unsigned i = 1; i < n_states; ++i)
|
||||
for (unsigned j = 0; j < i; ++j)
|
||||
{
|
||||
if (res[j] != j)
|
||||
continue;
|
||||
|
||||
if (!alt_init_st_auts[i]->intersects(compl_alt_init_st_auts[j])
|
||||
&& (!compl_alt_init_st_auts[i]->intersects(alt_init_st_auts[j])))
|
||||
{
|
||||
res[i] = res[j];
|
||||
break;
|
||||
if (res[j] != j)
|
||||
continue;
|
||||
|
||||
if (!alt_init_st_auts[i]->intersects(compl_alt_init_st_auts[j])
|
||||
&& (!compl_alt_init_st_auts[i]->intersects(alt_init_st_auts[j])))
|
||||
{
|
||||
res[i] = res[j];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue