* bin/README, bin/common_conv.hh, bin/common_trans.cc,
bin/ltlsynt.cc, bin/spot-x.cc, spot/gen/automata.hh,
spot/graph/graph.hh, spot/ltsmin/ltsmin.hh,
spot/ltsmin/spins_interface.hh, spot/ltsmin/spins_kripke.hh,
spot/mc/bloemen.hh, spot/mc/bloemen_ec.hh, spot/mc/cndfs.hh,
spot/mc/deadlock.hh, spot/mc/intersect.hh, spot/mc/lpar13.hh,
spot/mc/mc_instanciator.hh, spot/misc/bareword.cc,
spot/misc/fixpool.hh, spot/misc/formater.hh, spot/misc/minato.hh,
spot/misc/satsolver.hh, spot/misc/timer.hh,
spot/parseaut/public.hh, spot/priv/partitioned_relabel.cc,
spot/priv/satcommon.hh, spot/ta/ta.hh, spot/ta/taexplicit.cc,
spot/ta/taproduct.hh, spot/ta/tgta.hh, spot/taalgos/reachiter.hh,
spot/taalgos/tgba2ta.hh, spot/tl/apcollect.cc,
spot/tl/apcollect.hh, spot/tl/formula.cc, spot/tl/parse.hh,
spot/tl/randomltl.hh, spot/tl/relabel.hh, spot/tl/simplify.cc,
spot/twa/acc.hh, spot/twa/bddprint.hh, spot/twa/formula2bdd.cc,
spot/twa/twa.hh, spot/twa/twagraph.cc, spot/twa/twagraph.hh,
spot/twaalgos/aiger.cc, spot/twaalgos/aiger.hh,
spot/twaalgos/alternation.hh, spot/twaalgos/cleanacc.cc,
spot/twaalgos/cobuchi.cc, spot/twaalgos/contains.cc,
spot/twaalgos/couvreurnew.cc, spot/twaalgos/cycles.hh,
spot/twaalgos/degen.cc, spot/twaalgos/degen.hh,
spot/twaalgos/dot.hh, spot/twaalgos/dtbasat.cc,
spot/twaalgos/dtwasat.cc, spot/twaalgos/dtwasat.hh,
spot/twaalgos/dualize.cc, spot/twaalgos/emptiness.hh,
spot/twaalgos/emptiness_stats.hh, spot/twaalgos/game.cc,
spot/twaalgos/genem.hh, spot/twaalgos/hoa.hh,
spot/twaalgos/langmap.hh, spot/twaalgos/ltl2tgba_fm.hh,
spot/twaalgos/magic.cc, spot/twaalgos/magic.hh,
spot/twaalgos/mask.hh, spot/twaalgos/mealy_machine.cc,
spot/twaalgos/mealy_machine.hh,
spot/twaalgos/minimize.hh, spot/twaalgos/parity.cc,
spot/twaalgos/parity.hh, spot/twaalgos/postproc.cc,
spot/twaalgos/product.hh, spot/twaalgos/reachiter.hh,
spot/twaalgos/relabel.cc, spot/twaalgos/remfin.cc,
spot/twaalgos/remfin.hh, spot/twaalgos/sccfilter.cc,
spot/twaalgos/sccinfo.hh, spot/twaalgos/se05.cc,
spot/twaalgos/se05.hh, spot/twaalgos/simulation.hh,
spot/twaalgos/split.hh, spot/twaalgos/stats.hh,
spot/twaalgos/synthesis.cc, spot/twaalgos/synthesis.hh,
spot/twaalgos/tau03.hh, spot/twaalgos/tau03opt.hh,
spot/twaalgos/toparity.hh, spot/twaalgos/totgba.hh,
spot/twaalgos/translate.hh, spot/twaalgos/word.cc,
spot/twaalgos/word.hh, spot/twaalgos/zlktree.cc,
spot/twaalgos/zlktree.hh, spot/twacube/cube.hh,
spot/twacube/twacube.hh, tests/core/cube.cc,
tests/core/ltlsynt.test, tests/core/parity.cc,
tests/core/safra.cc, tests/core/twagraph.cc: here
244 lines
8.3 KiB
C++
244 lines
8.3 KiB
C++
// -*- coding: utf-8 -*-
|
|
// Copyright (C) by the Spot authors, see the AUTHORS file for details.
|
|
//
|
|
// 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 <tuple>
|
|
#include <sstream>
|
|
#include <vector>
|
|
#include <spot/misc/bddlt.hh>
|
|
#include <spot/misc/satsolver.hh>
|
|
#include <spot/misc/timer.hh>
|
|
#include <spot/twa/twagraph.hh>
|
|
|
|
#define DEBUG_CMN 0
|
|
|
|
namespace spot
|
|
{
|
|
struct src_cond
|
|
{
|
|
unsigned src;
|
|
bdd cond;
|
|
|
|
src_cond(unsigned src, bdd cond)
|
|
: src(src), cond(cond)
|
|
{
|
|
}
|
|
|
|
bool operator<(const src_cond& other) const
|
|
{
|
|
if (this->src < other.src)
|
|
return true;
|
|
if (this->src > other.src)
|
|
return false;
|
|
return this->cond.id() < other.cond.id();
|
|
}
|
|
|
|
bool operator==(const src_cond& other) const
|
|
{
|
|
return (this->src == other.src
|
|
&& this->cond.id() == other.cond.id());
|
|
}
|
|
};
|
|
|
|
/// \brief Interface with satsolver's litterals.
|
|
///
|
|
/// This class was created to fill the need to optimize memory storage in
|
|
/// SAT-minimization.
|
|
///
|
|
/// All this relies on the fact that almost everything about the automaton
|
|
/// candidate is known in advance and most of the time, litteral's numbers
|
|
/// are just incremented continually (they are continuous...).
|
|
///
|
|
/// This class allows to handle variables by only manipulating indices.
|
|
class vars_helper
|
|
{
|
|
private:
|
|
unsigned size_src_;
|
|
unsigned size_cond_;
|
|
unsigned size_dst_;
|
|
unsigned size_nacc_;
|
|
unsigned size_path_;
|
|
bool state_based_;
|
|
bool dtbasat_;
|
|
int min_t_;
|
|
int min_ta_;
|
|
int min_p_;
|
|
int max_p_;
|
|
|
|
// Vars that will be precalculated.
|
|
unsigned sn_mult_ = 0; // src * nacc
|
|
unsigned cd_mult_ = 0; // cond * dst
|
|
unsigned dn_mult_ = 0; // dst * nacc
|
|
unsigned sd_mult_ = 0; // src * dst
|
|
unsigned dr_mult_ = 0; // dst * 2 --> used only in get_prc(...)
|
|
unsigned sdr_mult_ = 0; // src * dst * 2 --> used only in get_prc(...)
|
|
unsigned scd_mult_ = 0; // src * cond * dst
|
|
unsigned cdn_mult_ = 0; // cond * dst * nacc
|
|
unsigned psd_mult_ = 0; // path * src * dst
|
|
unsigned scdn_mult_ = 0; // src * cond * dst * nacc
|
|
unsigned scdnp_mult_ = 0; // src * cond * dst * nacc * path
|
|
|
|
public:
|
|
vars_helper()
|
|
: size_src_(0), size_cond_(0), size_dst_(0), size_nacc_(0), size_path_(0),
|
|
state_based_(false), dtbasat_(false), min_t_(0), min_ta_(0), min_p_(0),
|
|
max_p_(0)
|
|
{
|
|
#if DEBUG_CMN
|
|
std::cerr << "vars_helper() constructor called\n";
|
|
#endif
|
|
}
|
|
|
|
/// \brief Save all different sizes and precompute some values.
|
|
void
|
|
init(unsigned size_src, unsigned size_cond, unsigned size_dst,
|
|
unsigned size_nacc, unsigned size_path, bool state_based,
|
|
bool dtbasat);
|
|
|
|
/// \brief Compute min_t literal as well as min_ta, min_p and max_p.
|
|
/// After this step, all literals are known.
|
|
void
|
|
declare_all_vars(int& min_t);
|
|
|
|
/// \brief Return the transition's literal corresponding to parameters.
|
|
inline int
|
|
get_t(unsigned src, unsigned cond, unsigned dst) const
|
|
{
|
|
#if DEBUG_CMN
|
|
if (src >= size_src_ || cond >= size_cond_ || dst >= size_dst_)
|
|
{
|
|
std::ostringstream buffer;
|
|
buffer << "bad arguments get_t(" << src << ',' << cond << ',' << dst
|
|
<< ")\n";
|
|
throw std::runtime_error(buffer.str());
|
|
}
|
|
std::cerr << "get_t(" << src << ',' << cond << ',' << dst << ") = "
|
|
<< min_t_ + src * cd_mult_ + cond * size_dst_ + dst << '\n';
|
|
#endif
|
|
return min_t_ + src * cd_mult_ + cond * size_dst_ + dst;
|
|
}
|
|
|
|
/// \brief Return the transition_acc's literal corresponding to parameters.
|
|
/// If (state_based), all outgoing transitions use the same acceptance
|
|
/// variable. Therefore, for each combination (src, nacc) there is only one
|
|
/// literal.
|
|
/// Note that with Büchi automata, there is only one nacc, thus, only one
|
|
/// literal for each src.
|
|
inline int
|
|
get_ta(unsigned src, unsigned cond, unsigned dst, unsigned nacc = 0) const
|
|
{
|
|
#if DEBUG_CMN
|
|
if (src >= size_src_ || cond >= size_cond_ || dst >= size_dst_
|
|
|| nacc >= size_nacc_)
|
|
{
|
|
std::stringstream buffer;
|
|
buffer << "bad arguments get_ta(" << src << ',' << cond << ',' << dst
|
|
<< ',' << nacc << ")\n";
|
|
throw std::runtime_error(buffer.str());
|
|
}
|
|
int res = state_based_ ? min_ta_ + src * size_nacc_ + nacc
|
|
: min_ta_ + src * cdn_mult_ + cond * dn_mult_ + (dst * size_nacc_)
|
|
+ nacc;
|
|
std::cerr << "get_ta(" << src << ',' << cond << ',' << dst << ") = "
|
|
<< res << '\n';
|
|
#endif
|
|
return state_based_ ? min_ta_ + src * size_nacc_ + nacc
|
|
: min_ta_ + src * cdn_mult_ + cond * dn_mult_ + dst * size_nacc_ + nacc;
|
|
}
|
|
|
|
/// \brief Return the path's literal corresponding to parameters.
|
|
inline int
|
|
get_p(unsigned path, unsigned src, unsigned dst) const
|
|
{
|
|
#if DEBUG_CMN
|
|
if (src >= size_src_ || path >= size_path_ || dst >= size_dst_)
|
|
{
|
|
std::stringstream buffer;
|
|
buffer << "bad arguments get_p(" << path << ',' << src << ',' << dst
|
|
<< ")\n";
|
|
throw std::runtime_error(buffer.str());
|
|
}
|
|
std::cerr << "get_p(" << path << ',' << src << ',' << dst << ") = "
|
|
<< min_p_ + path * sd_mult_ + src * size_dst_ + dst << '\n';
|
|
#endif
|
|
assert(!dtbasat_);
|
|
return min_p_ + path * sd_mult_ + src * size_dst_ + dst;
|
|
}
|
|
|
|
/// \brief Return the path's literal corresponding to parameters.
|
|
/// Argument ref serves to say whether it is a candidate or a reference
|
|
/// literal. false -> ref | true -> cand
|
|
inline int
|
|
get_prc(unsigned path, unsigned src, unsigned dst, bool cand) const
|
|
{
|
|
#if DEBUG_CMN
|
|
if (src >= size_src_ || path >= size_path_ || dst >= size_dst_)
|
|
{
|
|
std::stringstream buffer;
|
|
buffer << "bad arguments get_prc(" << path << ',' << src << ',' << dst
|
|
<< ',' << cand << ")\n";
|
|
throw std::runtime_error(buffer.str());
|
|
}
|
|
std::cerr << "get_prc(" << path << ',' << src << ',' << dst << ','
|
|
<< cand << ") = " << min_p_ + path * sdr_mult_ + src * dr_mult_ +
|
|
dst * 2 + cand << '\n';
|
|
#endif
|
|
assert(dtbasat_);
|
|
return min_p_ + path * sdr_mult_ + src * dr_mult_ + dst * 2 + cand;
|
|
}
|
|
|
|
/// \brief Use this function to get a string representation of a transition.
|
|
std::string
|
|
format_t(bdd_dict_ptr& debug_dict, unsigned src, bdd& cond,
|
|
unsigned dst);
|
|
|
|
/// \brief Use this function to get a string representation of a transition
|
|
/// acc.
|
|
std::string
|
|
format_ta(bdd_dict_ptr& debug_dict, unsigned src, bdd& cond, unsigned dst,
|
|
const acc_cond::mark_t& acc);
|
|
|
|
/// \brief Use this function to get a string representation of a path var.
|
|
std::string
|
|
format_p(unsigned src_cand, unsigned src_ref,
|
|
unsigned dst_cand, unsigned dst_ref,
|
|
acc_cond::mark_t acc_cand, acc_cond::mark_t acc_ref);
|
|
|
|
/// \brief Use this function to get a string representation of a path var.
|
|
std::string
|
|
format_p(unsigned src_cand, unsigned src_ref,
|
|
unsigned dst_cand, unsigned dst_ref);
|
|
};
|
|
|
|
/// \brief Give a filename to save the log of the SAT minimization.
|
|
///
|
|
/// This has priority over the SPOT_SATLOG environment variable.
|
|
/// Pass en empty string to reset it.
|
|
void set_satlog_filename(const std::string& filename);
|
|
|
|
/// \brief Prints a line in the SPOT_SATLOG file.
|
|
void print_log(timer_map& t,
|
|
int input_state_number,
|
|
int target_state_number, const twa_graph_ptr& res,
|
|
const satsolver& solver);
|
|
|
|
/// \brief Returns the number of distinct values contained in a vector.
|
|
int
|
|
get_number_of_distinct_vals(std::vector<unsigned> v);
|
|
}
|