12#ifndef MCRL2_LTS_BUILDER_H
13#define MCRL2_LTS_BUILDER_H
15#include "mcrl2/lps/explorer.h"
16#include "mcrl2/lts/detail/lts_convert.h"
17#include "mcrl2/lts/lts_io.h"
27 return lps::state(s.begin(), s.size() - 1);
40 m_actions.emplace(std::make_pair(tau, m_actions.size()));
46 auto i = m_actions.find(sorted_multi_action);
47 if (i == m_actions.end())
49 i = m_actions.emplace(std::make_pair(sorted_multi_action, m_actions.size())).first;
61 virtual void save(
const std::string& filename) = 0;
92 m_lts.add_transition(transition(from, label, to));
100 m_lts.set_num_action_labels(m_actions.size());
101 for (
const auto& p: m_actions)
103 m_lts.set_action_label(p.second, action_label_string(lps::pp(p.first)));
106 m_lts.set_num_states(state_map.size());
109 void save(
const std::string& filename)
override
111 m_lts.save(filename);
127 out.open(filename.c_str());
130 throw mcrl2::
runtime_error(
"cannot open '" + filename +
"' for writing");
139 out <<
"(" << from <<
",\"" <<
lps::pp(a
) <<
"\"," << to <<
")\n";
151 throw mcrl2::runtime_error(
"seeking is not supported by the output stream");
173 bool discard_state_labels =
false
177 m_lts.set_data(dataspec);
178 m_lts.set_process_parameters(process_parameters);
179 m_lts.set_action_label_declarations(action_labels);
186 m_lts.add_transition(transition(from, label, to));
194 m_lts.set_num_action_labels(m_actions.size());
195 for (
const auto& p: m_actions)
197 m_lts.set_action_label(p.second, action_label_lts(lps::multi_action(p.first.actions(), p.first.time())));
203 std::size_t n = state_map.size();
204 std::vector<state_label_lts> state_labels(n);
205 for (
std::size_t i = 0; i < n; i++)
209 state_labels[i] = state_label_lts(remove_time_stamp(state_map[i]));
213 state_labels[i] = state_label_lts(state_map[i]);
216 m_lts.state_labels() = std::move(state_labels);
219 m_lts.set_num_states(state_map.size(),
true);
220 m_lts.set_initial_state(0);
223 void save(
const std::string& filename)
override
225 m_lts.save(filename);
239 const std::string& filename,
243 bool discard_state_labels =
false
247 bool to_stdout = filename.empty() || filename ==
"-";
250 fstream.open(filename, std::ofstream::out | std::ofstream::binary);
253 throw mcrl2::
runtime_error(
"Fail to open file " + filename +
" for writing.");
258 stream = std::make_unique<atermpp::binary_aterm_ostream>(to_stdout ? std::cout : fstream);
260 mcrl2::lts::write_lts_header(*stream, dataspec, process_parameters, action_labels);
266 write_transition(*stream, from, a, to);
276 for (
std::size_t i = 0; i < state_map.size(); i++)
278 if (is_aterm_balanced_tree(state_map[i]))
282 write_state_label(*stream, state_label_lts(remove_time_stamp(state_map[i])));
286 write_state_label(*stream, state_label_lts(state_map[i]));
293 write_initial_state(*stream, 0);
304 :
super(dataspec
, action_labels
, process_parameters
)
307 void save(
const std::string& filename)
override
310 detail::lts_convert(m_lts, dot);
320 :
super(dataspec
, action_labels
, process_parameters
)
323 void save(
const std::string& filename)
override
326 detail::lts_convert(m_lts, fsm);
334 switch (output_format)
344 return std::make_unique<lts_aut_disk_builder>(output_filename);
347 case lts_dot:
return std::make_unique<
lts_dot_builder>(lpsspec.data(), lpsspec.action_labels(), lpsspec.process().process_parameters());
348 case lts_fsm:
return std::make_unique<
lts_fsm_builder>(lpsspec.data(), lpsspec.action_labels(), lpsspec.process().process_parameters());
357 return std::make_unique<lts_lts_disk_builder>(output_filename, lpsspec.data(), lpsspec.action_labels(), lpsspec.process().process_parameters(), options.discard_lts_state_labels);
logger(const log_level_t l)
Default constructor.
\brief A timed multi-action
multi_action sort_actions() const
Returns the multiaction in which the list of actions is sorted.
multi_action(const process::action_list &actions=process::action_list(), data::data_expression time=data::undefined_real())
Constructor.
void save(const std::string &filename) override
lts_aut_builder()=default
std::mutex m_exclusive_transition_access
void add_transition(std::size_t from, const lps::multi_action &a, std::size_t to, const std::size_t number_of_threads) override
void finalize(const indexed_set_for_states_type &state_map, bool) override
void finalize(const indexed_set_for_states_type &state_map, bool) override
void save(const std::string &) override
void add_transition(std::size_t from, const lps::multi_action &a, std::size_t to, const std::size_t number_of_threads) override
lts_aut_disk_builder(const std::string &filename)
std::mutex m_exclusive_transition_access
std::size_t m_transition_count
A simple labelled transition format with only strings as action labels.
void save(const std::string &filename) override
lts_dot_builder(const data::data_specification &dataspec, const process::action_label_list &action_labels, const data::variable_list &process_parameters)
A class to contain labelled transition systems in graphviz format.
void save(const std::string &filename) const
Save the labelled transition system to a file.
void save(const std::string &filename) override
lts_fsm_builder(const data::data_specification &dataspec, const process::action_label_list &action_labels, const data::variable_list &process_parameters)
The class lts_fsm_t contains labelled transition systems in .fsm format.
lts_lts_builder(const data::data_specification &dataspec, const process::action_label_list &action_labels, const data::variable_list &process_parameters, bool discard_state_labels=false)
void add_transition(std::size_t from, const lps::multi_action &a, std::size_t to, const std::size_t number_of_threads) override
void save(const std::string &filename) override
bool m_discard_state_labels
void finalize(const indexed_set_for_states_type &state_map, bool timed) override
std::mutex m_exclusive_transition_access
void add_transition(std::size_t from, const lps::multi_action &a, std::size_t to, const std::size_t number_of_threads) override
std::unique_ptr< atermpp::binary_aterm_ostream > stream
bool m_discard_state_labels
lts_lts_disk_builder(const std::string &filename, const data::data_specification &dataspec, const process::action_label_list &action_labels, const data::variable_list &process_parameters, bool discard_state_labels=false)
std::mutex m_exclusive_transition_access
void finalize(const indexed_set_for_states_type &state_map, bool timed) override
void save(const std::string &) override
This class contains labelled transition systems in .lts format.
void finalize(const indexed_set_for_states_type &, bool) override
void add_transition(std::size_t, const lps::multi_action &, std::size_t, const std::size_t) override
void save(const std::string &) override
Standard exception class for reporting runtime errors.
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Namespace for all data library functionality.
const data::data_expression & undefined_real()
Returns a data expression of type Real that corresponds to 'undefined'.
atermpp::term_list< variable > variable_list
\brief list of variables
The main namespace for the LPS library.
atermpp::term_balanced_tree< data::data_expression > state
std::string pp(const lps::multi_action &x)
lps::state remove_time_stamp(const lps::state &s)
Removes the last element from state s.
std::unique_ptr< lts_builder > create_lts_builder(const lps::specification &lpsspec, const lps::explorer_options &options, lts_type output_format, const std::string &output_filename="")
The main namespace for the Process library.
atermpp::term_list< action_label > action_label_list
\brief list of action_labels
static constexpr bool GlobalThreadSafe
Enables thread safety for the whole toolset.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
bool discard_lts_state_labels
virtual ~lts_builder()=default
virtual void add_transition(std::size_t from, const lps::multi_action &a, std::size_t to, const std::size_t number_of_threads=0)=0
atermpp::indexed_set< lps::state, mcrl2::utilities::detail::GlobalThreadSafe > indexed_set_for_states_type
virtual void finalize(const indexed_set_for_states_type &state_map, bool timed)=0
utilities::unordered_map_large< lps::multi_action, std::size_t > m_actions
virtual void save(const std::string &filename)=0
std::size_t add_action(const lps::multi_action &a)
std::size_t operator()(const atermpp::detail::reference_aterm< T > &t) const