19static void read_newline(std::istream& is,
const std::size_t line_no)
36 if (ch !=
'\n' && !is.eof())
44 throw mcrl2::runtime_error(
"Expect a newline after the transition at line " + std::to_string(line_no) +
".");
54 is >> std::skipws >> ch;
55 for( ; isdigit(ch) ; is.get(ch))
66template <
class AUT_LTS_TYPE>
67static std::size_t
find_label_index(
const std::string& s, mcrl2::utilities::unordered_map < action_label_string, std::size_t >& labs, AUT_LTS_TYPE& l)
76 label=l.add_action(as);
86static void check_state(std::size_t
state, std::size_t number_of_states, std::size_t line_no)
88 if (
state>=number_of_states)
91 std::to_string(number_of_states) +
"). Found at line " + std::to_string(line_no) +
".");
96 std::size_t number_of_states, std::size_t line_no)
98 if (probability_state.
size()<=1)
118 const std::size_t line_no)
120 assert(result.
size()==0);
124 is >> std::skipws >>
state;
133 is >> std::skipws >> ch;
145 while (is.good() && !ready)
148 std::string enumerator;
151 is >> std::skipws >> ch;
154 throw mcrl2::runtime_error(
"Expect a / in a probability at line " + std::to_string(line_no) +
".");
157 std::string denominator;
160 remainder=remainder-frac;
163 is >> std::skipws >>
state;
172 is >> std::skipws >> ch;
188 std::size_t& num_transitions,
189 std::size_t& num_states)
193 is >> std::skipws >> s;
201 is >> std::skipws >> ch;
205 throw mcrl2::runtime_error(
"Expect an opening bracket '(' after 'des' in the first line of a .aut file.");
210 is >> std::skipws >> ch;
213 throw mcrl2::runtime_error(
"Expect a comma after the first number in the first line of a .aut file.");
216 is >> std::skipws >> num_transitions;
218 is >> std::skipws >> ch;
221 throw mcrl2::runtime_error(
"Expect a comma after the second number in the first line of a .aut file.");
224 is >> std::skipws >> num_states;
230 throw mcrl2::runtime_error(
"Expect a closing bracket ')' after the third number in the first line of a .aut file.");
240 const std::size_t line_no)
243 is >> std::skipws >> ch;
253 is >> std::skipws >>
from;
255 is >> std::skipws >> ch;
258 throw mcrl2::runtime_error(
"Expect that the first number is followed by a comma at line " + std::to_string(line_no) +
".");
261 is >> std::skipws >> ch;
267 is >> std::noskipws >> ch;
268 while ((ch !=
'"') && !is.eof())
275 throw mcrl2::runtime_error(
"Expect that the second item is a quoted label (using \") at line " + std::to_string(line_no) +
".");
277 is >> std::skipws >> ch;
285 while ((ch !=
',') && !is.eof())
294 throw mcrl2::runtime_error(
"Expect a comma after the quoted label at line " + std::to_string(line_no) +
".");
305 const std::size_t line_no)
318 throw mcrl2::runtime_error(
"Expect a closing bracket at the end of the transition at line " + std::to_string(line_no) +
".");
330 const std::size_t line_no)
337 is >> std::skipws >>
to;
343 throw mcrl2::runtime_error(
"Expect a closing bracket at the end of the transition at line " + std::to_string(line_no) +
".");
353 mcrl2::utilities::unordered_map < std::size_t, std::size_t>& indices_of_single_probabilistic_states,
354 mcrl2::utilities::unordered_map < mcrl2::lts::probabilistic_lts_aut_t::probabilistic_state_t, std::size_t>&
355 indices_of_multiple_probabilistic_states)
357 std::size_t fresh_index = indices_of_single_probabilistic_states.
size()+indices_of_multiple_probabilistic_states.
size();
362 index = indices_of_single_probabilistic_states.
insert(
363 std::pair< std::size_t, std::size_t>
369 index = indices_of_multiple_probabilistic_states.
insert(
370 std::pair< mcrl2::lts::probabilistic_lts_aut_t::probabilistic_state_t, std::size_t>
374 if (index==fresh_index)
377 assert(probabilistic_state_index==index);
378 (void)probabilistic_state_index;
386 std::size_t line_no = 1;
387 std::size_t ntrans=0, nstate=0;
396 mcrl2::utilities::unordered_map < std::size_t, std::size_t> indices_of_single_probabilistic_states;
397 mcrl2::utilities::unordered_map < mcrl2::lts::probabilistic_lts_aut_t::probabilistic_state_t, std::size_t> indices_of_multiple_probabilistic_states;
399 check_states(initial_probabilistic_state, nstate, line_no);
403 throw mcrl2::runtime_error(
"cannot parse AUT input that has no states; at least an initial state is required.");
409 mcrl2::utilities::unordered_map < action_label_string, std::size_t > action_labels;
419 probabilistic_target_state.
clear();
429 check_states(probabilistic_target_state, nstate, line_no);
430 std::size_t index =
add_probablistic_state(probabilistic_target_state, l, indices_of_single_probabilistic_states, indices_of_multiple_probabilistic_states);
438 ") does not correspond to the number of transition given in the header (" + std::to_string(ntrans) +
").");
444 std::size_t line_no = 1;
445 std::size_t ntrans=0, nstate=0;
450 if (initial_probabilistic_state.
size()>1)
452 throw mcrl2::runtime_error(
"Encountered an initial probability distribution while reading an non probabilistic .aut file.");
455 check_states(initial_probabilistic_state, nstate, line_no);
459 throw mcrl2::runtime_error(
"cannot parse AUT input that has no states; at least an initial state is required.");
465 mcrl2::utilities::unordered_map < action_label_string, std::size_t > action_labels;
488 ") does not correspond to the number of transition given in the header (" + std::to_string(ntrans) +
").");
496 bool first_element=
true;
497 if (prob_state.
size()<=1)
499 os << prob_state.
get();
508 previous_probability=p.probability();
513 os <<
" " <<
pp(previous_probability) <<
" " << p.state();
514 previous_probability=p.probability();
543 os <<
"(" << t.from() <<
",\""
545 << t.to() <<
")" <<
"\n";
556 if (filename==
"" || filename==
"-")
562 std::ifstream is(filename.c_str());
581 if (filename==
"" || filename==
"-")
587 std::ofstream os(filename.c_str());
601 if (filename.empty() || filename==
"-")
607 std::ifstream is(filename.c_str());
626 if (filename.empty() || filename==
"-")
632 std::ofstream os(filename.c_str());
Read-only balanced binary tree of terms.
This class contains strings to be used as values for action labels in lts's.
static const action_label_string & tau_action()
A simple labelled transition format with only strings as action labels.
void load(const std::string &filename)
Load the labelled transition system from a file.
void save(const std::string &filename) const
Save the labelled transition system to file.
A class that contains a labelled transition system.
void add_transition(const transition &t)
Add a transition to the lts.
states_size_type num_states() const
Gets the number of states of this LTS.
void clear_transitions(const std::size_t n=0)
Clear the transitions of an 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.
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.
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.
transitions_size_type num_transitions() const
Gets the number of transitions of this LTS.
A simple labelled transition format with only strings as action labels.
void load(const std::string &filename)
Load the labelled transition system from a file.
void save(const std::string &filename) const
Save the labelled transition system to file.
void set_initial_probabilistic_state(const PROBABILISTIC_STATE_T &state)
Sets the probabilistic initial state number of this LTS.
const PROBABILISTIC_STATE_T & initial_probabilistic_state() const
Gets the initial state number of this LTS.
states_size_type add_and_reset_probabilistic_state(PROBABILISTIC_STATE_T &s)
Adds a probabilistic state to this LTS and resets the state to empty.
const PROBABILISTIC_STATE_T & probabilistic_state(const states_size_type index) const
Gets the probabilistic label of an index.
void set(const STATE &s)
Set this probabilistic state to a single state with probability one.
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.
void clear()
Makes the probabilistic state empty.
void add(const STATE &s, const PROBABILITY &p)
Add a state with a probability to the probabilistic state.
A class containing triples, source label and target representing transitions.
Standard exception class for reporting runtime errors.
This class contains labels for probabilistic transistions, consisting of a numerator and a denominato...
static probabilistic_arbitrary_precision_fraction & one()
Constant one.
iterator find(const Args &... args)
std::pair< iterator, bool > insert(const value_type &pair)
Inserts elements.
const T & at(const key_type &key) const
Provides access to the value associated with the given key.
typename Set::const_iterator const_iterator
static void read_probabilistic_state(std::istream &is, mcrl2::lts::probabilistic_lts_aut_t::probabilistic_state_t &result, const std::size_t line_no)
static void write_probabilistic_state(const mcrl2::lts::probabilistic_lts_aut_t::probabilistic_state_t &prob_state, std::ostream &os)
static void read_from_aut(probabilistic_lts_aut_t &l, std::istream &is)
static size_t add_probablistic_state(mcrl2::lts::probabilistic_lts_aut_t::probabilistic_state_t &probabilistic_state, probabilistic_lts_aut_t &l, mcrl2::utilities::unordered_map< std::size_t, std::size_t > &indices_of_single_probabilistic_states, mcrl2::utilities::unordered_map< mcrl2::lts::probabilistic_lts_aut_t::probabilistic_state_t, std::size_t > &indices_of_multiple_probabilistic_states)
static void read_newline(std::istream &is, const std::size_t line_no)
static void read_aut_header(std::istream &is, mcrl2::lts::probabilistic_lts_aut_t::probabilistic_state_t &initial_state, std::size_t &num_transitions, std::size_t &num_states)
static void write_to_aut(const probabilistic_lts_aut_t &l, std::ostream &os)
static bool read_initial_part_of_an_aut_transition(std::istream &is, std::size_t &from, std::string &label, const std::size_t line_no)
static void read_natural_number_to_string(std::istream &is, std::string &s, const std::size_t line_no)
static void check_states(mcrl2::lts::probabilistic_lts_aut_t::probabilistic_state_t &probability_state, std::size_t number_of_states, std::size_t line_no)
static void check_state(std::size_t state, std::size_t number_of_states, std::size_t line_no)
static bool read_aut_transition(std::istream &is, std::size_t &from, std::string &label, mcrl2::lts::probabilistic_lts_aut_t::probabilistic_state_t &target_probabilistic_state, const std::size_t line_no)
static std::size_t find_label_index(const std::string &s, mcrl2::utilities::unordered_map< action_label_string, std::size_t > &labs, AUT_LTS_TYPE &l)
This file contains a class that contains labelled transition systems in aut format.
std::string pp(const abstraction &x)
atermpp::term_balanced_tree< data::data_expression > state
std::size_t to(const outgoing_pair_t &p)
Target state of a label state pair.
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.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...