42 for(
const auto& p :
state)
46 stream << p.probability();
58 const std::size_t value=index.
value();
63 state.set(index.value());
70 for (std::size_t i = 0; i < value; ++i)
73 stream >> probability;
75 state.add(index.value(), probability);
78 state.shrink_to_fit();
99 return probabilistic_mark;
118 if (initial_state.
size() > 1)
120 throw mcrl2::runtime_error(
"The initial state of the non probabilistic input lts is probabilistic.");
128 lts.set_initial_probabilistic_state(initial_state);
134 static_assert(std::is_same<LTS,probabilistic_lts_lts_t>::value ||
135 std::is_same<LTS,lts_lts_t>::value,
136 "Function read_lts can only be applied to a (probabilistic) lts. ");
155 stream >> parameters;
156 stream >> action_labels;
159 lts.set_process_parameters(parameters);
160 lts.set_action_label_declarations(action_labels);
164 multi_actions.
insert(action_label_lts::tau_action());
167 std::optional<probabilistic_lts_lts_t::probabilistic_state_t> initial_state;
174 std::size_t number_of_states = 1;
196 const auto [index, inserted] = multi_actions.
insert(action);
198 std::size_t target_index =
to.value();
199 if constexpr (std::is_same<LTS, probabilistic_lts_lts_t>::value)
205 std::tie(target_index, state_inserted) = probabilistic_states.insert(lts_state);
209 std::size_t actual_index =
lts.add_probabilistic_state(lts_state);
211 assert(actual_index == target_index);
217 number_of_states = std::max(number_of_states, std::max(
from.value() + 1,
to.value() + 1));
223 assert(actual_index == index);
229 if constexpr (std::is_same<LTS, probabilistic_lts_lts_t>::value)
237 const auto [index, inserted] = multi_actions.
insert(action);
240 const auto [to_index, state_inserted] = probabilistic_states.insert(
to);
244 std::size_t actual_index =
lts.add_probabilistic_state(
to);
246 assert(actual_index == to_index);
252 number_of_states = std::max(number_of_states, std::max(
from.value() + 1, to_index + 1));
258 assert(actual_index == index);
276 initial_state =
state;
294 throw mcrl2::runtime_error(
"Missing initial state in labelled transition system (LTS) stream.");
298template <
class LTS_TRANSITION_SYSTEM>
301 static_assert(std::is_same<LTS_TRANSITION_SYSTEM,probabilistic_lts_lts_t>::value ||
302 std::is_same<LTS_TRANSITION_SYSTEM,lts_lts_t>::value,
303 "Function read_from_lts can only be applied to a (probabilistic) lts. ");
305 std::ifstream fstream;
306 if (!filename.empty())
308 fstream.open(filename, std::ifstream::in | std::ifstream::binary);
311 if (filename.empty())
327 catch (
const std::exception& ex)
330 if (filename.empty())
343 stream << detail::initial_state_mark();
344 stream <<
lts.initial_probabilistic_state();
349 stream << detail::initial_state_mark();
356 static_assert(std::is_same<LTS,probabilistic_lts_lts_t>::value ||
357 std::is_same<LTS,lts_lts_t>::value,
358 "Function write_lts can only be applied to a (probabilistic) lts. ");
363 lts.process_parameters(),
364 lts.action_label_declarations());
370 if constexpr (std::is_same<LTS, probabilistic_lts_lts_t>::value)
393template <
class LTS_TRANSITION_SYSTEM>
394static void write_to_lts(
const LTS_TRANSITION_SYSTEM&
lts,
const std::string& filename)
396 static_assert(std::is_same<LTS_TRANSITION_SYSTEM,probabilistic_lts_lts_t>::value ||
397 std::is_same<LTS_TRANSITION_SYSTEM,lts_lts_t>::value,
398 "Function write_to_lts can only be applied to a (probabilistic) lts. ");
400 bool to_stdout = filename.empty() || filename ==
"-";
401 std::ofstream fstream;
404 fstream.open(filename, std::ofstream::out | std::ofstream::binary);
416 catch (
const std::exception& ex)
429 read_lts(stream,
lts);
435 read_lts(stream,
lts);
462 stream << parameters;
463 stream << action_labels;
504 mCRL2log(
log::verbose) <<
"Starting to save a probabilistic lts to the file " << filename <<
".\n";
516 mCRL2log(
log::verbose) <<
"Starting to load a probabilistic lts from the file " << filename <<
".\n";
An integer term stores a single std::size_t value. It carries no arguments.
std::size_t value() const noexcept
Provide the value stored in an aterm.
The interface for a class that reads aterm from a stream. The default constructed term aterm() indica...
virtual void get(aterm &t)=0
Reads an aterm from this stream.
The interface for a class that writes aterm to a stream. Every written term is retrieved by the corre...
A helper class to restore the state of the aterm_{i,o}stream objects upon destruction....
Reads terms from a stream in the steamable binary aterm format.
Writes terms in a streamable binary aterm format to an output stream.
Read-only balanced binary tree of terms.
size_type size() const
Returns the size of the term_balanced_tree.
bool type_is_list() const noexcept
Dynamic check whether the term is an aterm_list.
bool defined() const
Returns true if this term is not equal to the term assigned by the default constructor of aterms,...
\brief A timed multi-action
This class contains labels for probabilistic transistions, consisting of a numerator and a denumerato...
A class containing the values for action labels for the .lts format.
This class contains labelled transition systems in .lts format.
void save(const std::string &filename) const
Save the labelled transition system to file.
void load(const std::string &filename)
Load the labelled transition system from file.
A class that contains a labelled transition system.
states_size_type num_state_labels() const
Gets the number of state labels of this LTS.
void add_transition(const transition &t)
Add a transition to the lts.
void set_num_states(const states_size_type n, const bool has_state_labels=true)
Sets the number of states of this LTS.
ACTION_LABEL_T action_label(const labels_size_type action) const
Gets the label of an action.
bool has_state_info() const
Checks whether this LTS has state values associated with its states.
void set_initial_state(const states_size_type state)
Sets the initial state number of this LTS.
labels_size_type apply_hidden_label_map(const labels_size_type action) const
If the action label is registered hidden, it returns tau, otherwise the original label.
STATE_LABEL_T state_label(const states_size_type state) const
Gets the label of a state.
states_size_type add_state(const STATE_LABEL_T &label=STATE_LABEL_T())
Adds a state to this LTS.
const std::vector< transition > & get_transitions() const
Gets a const reference to the vector of transitions of the current lts.
states_size_type initial_state() const
Gets the initial state number of this LTS.
labels_size_type add_action(const ACTION_LABEL_T &label)
Adds an action with a label to this LTS.
This class contains probabilistic labelled transition systems in .lts format.
void load(const std::string &filename)
Load the labelled transition system from file.
void save(const std::string &filename) const
Save the labelled transition system to file.
probabilistic_state< std::size_t, lps::probabilistic_data_expression > probabilistic_state_t
The type of probabilistic labels.
std::size_t size() const
Gets the number of probabilistic states in the vector representation of this state....
STATE get() const
Get a probabilistic state if is is simple, i.e., consists of a single state.
This class contains state labels for an labelled transition system in .lts format.
A class containing triples, source label and target representing transitions.
Standard exception class for reporting runtime errors.
A set that assigns each element an unique index.
std::pair< size_type, bool > insert(const key_type &key, std::size_t thread_index=0)
Insert a key in the indexed set and return its index.
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
This include file contains routines to read and write labelled transitions from and to files and from...
This file contains a class that contains labelled transition systems in lts (mcrl2) format.
The main namespace for the aterm++ library.
atermpp::aterm remove_index_impl(const atermpp::aterm &x)
atermpp::aterm add_index_impl(const atermpp::aterm &x)
atermpp::aterm_istream & operator>>(atermpp::aterm_istream &stream, data_specification &spec)
Reads a data specification from a stream.
std::ostream & operator<<(std::ostream &out, const abstraction &x)
atermpp::term_balanced_tree< data::data_expression > state
static const atermpp::aterm & initial_state_mark()
static void set_initial_state(lts_lts_t <s, const probabilistic_lts_lts_t::probabilistic_state_t &initial_state)
static const atermpp::aterm & probabilistic_transition_mark()
static void write_to_lts(const LTS_TRANSITION_SYSTEM <s, const std::string &filename)
static void write_lts(atermpp::aterm_ostream &stream, const LTS <s)
static void read_from_lts(LTS_TRANSITION_SYSTEM <s, const std::string &filename)
static const atermpp::aterm & transition_mark()
static void read_lts(atermpp::aterm_istream &stream, LTS <s)
static const atermpp::aterm & labelled_transition_system_mark()
std::size_t to(const outgoing_pair_t &p)
Target state of a label state pair.
void write_lts_header(atermpp::aterm_ostream &stream, const data::data_specification &data, const data::variable_list ¶meters, const process::action_label_list &action_labels)
Writes the start of an LTS stream.
void write_initial_state(atermpp::aterm_ostream &stream, std::size_t index)
Write the initial state to the LTS stream.
void write_state_label(atermpp::aterm_ostream &stream, const state_label_lts &label)
Write a state label to the LTS stream.
std::size_t label(const outgoing_pair_t &p)
Label of a pair of a label and target state.
std::size_t from(const outgoing_transitions_per_state_action_t::const_iterator &i)
From state of an iterator exploring transitions per outgoing state and action.
void write_transition(atermpp::aterm_ostream &stream, std::size_t from, const lps::multi_action &label, std::size_t to)
Write a transition to the LTS stream.
void mcrl2_unused(T &&...)
Function that can be used to silence unused parameter warnings.