mCRL2
Loading...
Searching...
No Matches
lts_lts.h
Go to the documentation of this file.
1// Author(s): Jan Friso Groote
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9
19#ifndef MCRL2_LTS_LTS_MCRL2_H
20#define MCRL2_LTS_LTS_MCRL2_H
21
22#include "mcrl2/lps/parse.h"
23#include "mcrl2/lps/print.h"
24#include "mcrl2/lps/state.h"
27
28namespace mcrl2
29{
30namespace lts
31{
32
39class state_label_lts : public atermpp::term_list< lps::state >
40{
41 public:
43
47 {}
48
51
54
57 template < class CONTAINER >
58 explicit state_label_lts(const CONTAINER& l)
59 {
60 static_assert(std::is_same<typename CONTAINER::value_type, data::data_expression>::value,"Value type must be a data_expression");
61 this->push_front(lps::state(l.begin(),l.size()));
62 }
63
66 explicit state_label_lts(const lps::state& l)
67 {
68 this->push_front(l);
69 }
70
73 explicit state_label_lts(const super& l)
74 : super(l)
75 {
76 }
77
82 {
83 // The order of the state labels should not matter. For efficiency the elements of l are inserted in front of the aterm_list.
84 state_label_lts result(*this);
85
86 for (const lps::state& el : l)
87 {
88 result.push_front(el);
89 }
90
91 return result;
92 }
93
96 static state_label_lts number_to_label(const std::size_t n)
97 {
99 }
100};
101
108inline std::string pp(const state_label_lts& label)
109{
110 std::string s;
111 if (label.size()!=1)
112 {
113 s += "[";
114 }
115 bool first=true;
116 for(const lps::state& l: label)
117 {
118 if (!first)
119 {
120 s += ", ";
121 }
122 first = false;
123 s += "(";
124 for (lps::state::iterator i=l.begin(); i!=l.end(); ++i)
125 {
126 if (i!=l.begin())
127 {
128 s += ",";
129 }
130 s += data::pp(*i);
131 }
132 s += ")";
133 }
134 if (label.size()!=1)
135 {
136 s += "]";
137 }
138 return s;
139}
140
144{
145 public:
146
149 {}
150
153
156
160 {
161 }
162
166 void hide_actions(const std::vector<std::string>& tau_actions)
167 {
168 process::action_vector new_multi_action;
169 for (const process::action& a: this->actions())
170 {
171 if (std::find(tau_actions.begin(),tau_actions.end(),
172 std::string(a.label().name()))==tau_actions.end()) // this action must not be hidden.
173 {
174 new_multi_action.push_back(a);
175 }
176 }
177 *this= action_label_lts(lps::multi_action(process::action_list(new_multi_action.begin(), new_multi_action.end()),time()));
178 }
179
180 /* \brief The action label that represents the internal action.
181 */
183 {
185 return tau_action;
186 }
187
188 protected:
191 {
192 if (a.actions().size()<=1)
193 {
194 return a;
195 }
196 std::multiset<process::action> sorted_actions(a.actions().begin(), a.actions().end());
197 return mcrl2::lps::multi_action(process::action_list(sorted_actions.begin(),sorted_actions.end()),a.time());
198 }
199};
200
202inline std::string pp(const action_label_lts& l)
203{
205}
206
216 const std::string& multi_action_string,
217 const data::data_specification& data_spec,
219{
220 std::string l(multi_action_string);
222 // Find an @ symbol in the action, in which case it is timed.
223 size_t position_of_at=l.find_first_of('@');
224 std::string time_expression_string;
225 if (position_of_at!=std::string::npos)
226 {
227 // The at symbol is found. It is a timed action.
228 time_expression_string=l.substr(position_of_at+1,l.size());
229 l=l.substr(0,position_of_at-1);
230 }
231 try
232 {
233 al=lps::parse_multi_action(l, typechecker, data_spec);
234 }
235 catch (mcrl2::runtime_error& e)
236 {
237 throw mcrl2::runtime_error("Parse error in action label " + multi_action_string + ".\n" + e.what());
238 }
239
240 if (time_expression_string.size()>0)
241 {
242 try
243 {
244 data::data_expression time=parse_data_expression(time_expression_string,data::variable_list(),data_spec);
245 // Translate the sort of time to a real.
246 if (time.sort()==data::sort_pos::pos())
247 {
248#ifdef MCRL2_ENABLE_MACHINENUMBERS
249 time = data::sort_nat::pos2nat(time);
250#else
251 time = data::sort_nat::cnat(time);
252#endif
253 }
254 if (time.sort()==data::sort_nat::nat())
255 {
256 time = data::sort_int::cint(time);
257 }
258 if (time.sort()==data::sort_int::int_())
259 {
261 }
262 if (time.sort()!=data::sort_real::real_())
263 {
264 throw mcrl2::runtime_error("The time is not of sort Pos, Nat, Int or Real\n");
265 }
266 return action_label_lts(lps::multi_action(al.actions(),time));
267 }
268 catch (mcrl2::runtime_error& e)
269 {
270 throw mcrl2::runtime_error("Parse error in the time expression " + multi_action_string + ".\n" + e.what());
271 }
272 }
273 return action_label_lts(al);
274}
275
276namespace detail
277{
278
282{
283 protected:
287
288 public:
291 {}
292
294 bool operator==(const lts_lts_base& other) const
295 {
296 return m_data_spec==other.m_data_spec &&
297 m_parameters==other.m_parameters &&
299 }
300
302 {
305 l.m_data_spec=auxd;
308 }
309
311 static lts_type type()
312 {
313 return lts_lts;
314 }
315
319 {
320 return m_data_spec;
321 }
322
326 {
327 return m_action_decls;
328 }
329
334 {
335 m_action_decls=decls;
336 }
337
342 {
343 m_data_spec=spec;
344 }
345
349 {
350 return m_parameters;
351 }
352
356 const data::variable& process_parameter(std::size_t i) const
357 {
358 assert(i<m_parameters.size());
360 for(std::size_t c=0; c!=i; ++j, ++c)
361 {}
362 return *j;
363 }
364
365
370 {
371 m_parameters=params;
372 }
373
374};
375
376} // namespace detail
377
378
384class lts_lts_t : public lts< state_label_lts, action_label_lts, detail::lts_lts_base >
385{
386 public:
389
394 void load(const std::string& filename);
395
400 void save(const std::string& filename) const;
401};
402
409 public probabilistic_lts< state_label_lts,
410 action_label_lts,
411 probabilistic_state<std::size_t, lps::probabilistic_data_expression>,
412 detail::lts_lts_base >
413{
414 public:
417
422 void load(const std::string& filename);
423
428 void save(const std::string& filename) const;
429};
430} // namespace lts
431} // namespace mcrl2
432
433namespace std
434{
435
437template<>
438struct hash< mcrl2::lts::action_label_lts >
439{
440 std::size_t operator()(const mcrl2::lts::action_label_lts& as) const
441 {
442 hash<mcrl2::lps::multi_action> hasher;
443 return hasher(as);
444 }
445};
446
447} // namespace std
448
449
450#endif
Read-only balanced binary tree of terms.
Iterator for term_list.
A list of aterm objects.
Definition aterm_list.h:24
size_type size() const
Returns the size of the term_list.
Definition aterm_list.h:256
const_iterator end() const
Returns a const_iterator pointing to the end of the term_list.
Definition aterm_list.h:282
const_iterator begin() const
Returns a const_iterator pointing to the beginning of the term_list.
Definition aterm_list.h:275
void push_front(const lps::state &el)
Inserts a new element at the beginning of the current list.
void swap(unprotected_aterm_core &t) noexcept
Swaps this term with its argument.
Definition aterm_core.h:152
sort_expression sort() const
Returns the sort of the data expression.
Definition data.cpp:108
\brief A data variable
Definition variable.h:28
\brief A timed multi-action
const process::action_list & actions() const
const data::data_expression & time() const
A class containing the values for action labels for the .lts format.
Definition lts_lts.h:144
action_label_lts & operator=(const action_label_lts &)=default
Copy assignment.
static mcrl2::lps::multi_action sort_multiactions(const mcrl2::lps::multi_action &a)
A function to sort a multi action to guarantee that multi-actions are compared properly.
Definition lts_lts.h:190
void hide_actions(const std::vector< std::string > &tau_actions)
Hide the actions with labels in tau_actions.
Definition lts_lts.h:166
action_label_lts(const action_label_lts &)=default
Copy constructor.
static const action_label_lts & tau_action()
Definition lts_lts.h:182
action_label_lts()
Default constructor.
Definition lts_lts.h:148
action_label_lts(const mcrl2::lps::multi_action &a)
Constructor.
Definition lts_lts.h:158
a base class for lts_lts_t and probabilistic_lts_t.
Definition lts_lts.h:282
static lts_type type()
Yields the type of this lts, in this case lts_lts.
Definition lts_lts.h:311
void set_process_parameters(const data::variable_list &params)
Set the state parameters for this LTS.
Definition lts_lts.h:369
const data::data_specification & data() const
Returns the mCRL2 data specification of this LTS.
Definition lts_lts.h:318
bool operator==(const lts_lts_base &other) const
Standard equality function;.
Definition lts_lts.h:294
process::action_label_list m_action_decls
Definition lts_lts.h:286
void swap(lts_lts_base &l)
Definition lts_lts.h:301
void set_action_label_declarations(const process::action_label_list &decls)
Set the action label information for this LTS.
Definition lts_lts.h:333
const data::variable & process_parameter(std::size_t i) const
Returns the i-th parameter of the state vectors stored in this LTS.
Definition lts_lts.h:356
data::data_specification m_data_spec
Definition lts_lts.h:284
const data::variable_list & process_parameters() const
Return the process parameters stored in this LTS.
Definition lts_lts.h:348
void set_data(const data::data_specification &spec)
Set the mCRL2 data specification of this LTS.
Definition lts_lts.h:341
lts_lts_base()
Default constructor.
Definition lts_lts.h:290
const process::action_label_list & action_label_declarations() const
Return action label declarations stored in this LTS.
Definition lts_lts.h:325
data::variable_list m_parameters
Definition lts_lts.h:285
This class contains labelled transition systems in .lts format.
Definition lts_lts.h:385
lts_lts_t()
Creates an object containing no information.
Definition lts_lts.h:388
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.
Definition lts.h:83
This class contains probabilistic labelled transition systems in .lts format.
Definition lts_lts.h:413
void load(const std::string &filename)
Load the labelled transition system from file.
probabilistic_lts_lts_t()
Creates an object containing no information.
Definition lts_lts.h:416
void save(const std::string &filename) const
Save the labelled transition system to file.
A class that contains a labelled transition system.
This class contains state labels for an labelled transition system in .lts format.
Definition lts_lts.h:40
state_label_lts()
Default constructor.
Definition lts_lts.h:46
state_label_lts(const state_label_lts &)=default
Copy constructor.
state_label_lts operator+(const state_label_lts &l) const
An operator to concatenate two state labels.
Definition lts_lts.h:81
state_label_lts(const super &l)
Construct a state label out of list of balanced trees of data expressions, representing a state label...
Definition lts_lts.h:73
atermpp::term_list< lps::state > super
Definition lts_lts.h:42
state_label_lts(const lps::state &l)
Construct a state label out of a balanced tree of data expressions, representing a state label.
Definition lts_lts.h:66
state_label_lts & operator=(const state_label_lts &)=default
Copy assignment.
static state_label_lts number_to_label(const std::size_t n)
Create a state label consisting of a number as the only list element.
Definition lts_lts.h:96
state_label_lts(const CONTAINER &l)
Construct a single state label out of the elements in a container.
Definition lts_lts.h:58
Standard exception class for reporting runtime errors.
Definition exception.h:27
add your file description here.
add your file description here.
const function_symbol & cint()
Constructor for function symbol @cInt.
Definition int1.h:80
const basic_sort & int_()
Constructor for sort expression Int.
Definition int1.h:47
const function_symbol & cnat()
Constructor for function symbol @cNat.
Definition nat1.h:140
const basic_sort & nat()
Constructor for sort expression Nat.
Definition nat1.h:46
const function_symbol & pos2nat()
Constructor for function symbol Pos2Nat.
Definition nat1.h:300
const function_symbol & c1()
Constructor for function symbol @c1.
Definition pos1.h:78
const basic_sort & pos()
Constructor for sort expression Pos.
Definition pos1.h:45
const function_symbol & creal()
Constructor for function symbol @cReal.
Definition real1.h:107
const basic_sort & real_()
Constructor for sort expression Real.
Definition real1.h:48
data_expression parse_data_expression(std::istream &in, const VariableContainer &variables, const data_specification &dataspec=detail::default_specification(), bool type_check=true, bool translate_user_notation=true, bool normalize_sorts=true)
Parses and type checks a data expression.
Definition parse.h:276
std::string pp(const abstraction &x)
Definition data.cpp:39
std::string pp(const action_summand &x)
Definition lps.cpp:26
multi_action parse_multi_action(std::stringstream &in, const process::action_label_list &action_decls, const data::data_specification &data_spec=data::detail::default_specification())
Parses a multi_action from an input stream.
Definition parse.h:42
lts_type
The enumerated type lts_type contains an index for every type type of labelled transition system that...
Definition lts_type.h:37
action_label_lts parse_lts_action(const std::string &multi_action_string, const data::data_specification &data_spec, lps::multi_action_type_checker &typechecker)
Parse a string into an action label.
Definition lts_lts.h:215
std::size_t label(const outgoing_pair_t &p)
Label of a pair of a label and target state.
std::vector< action > action_vector
\brief vector of actions
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
STL namespace.
This file contains a class that contains labels for probabilistic transitions as a mCRL2 data express...
The file containing the core class for transition systems.
The class summand.
std::size_t operator()(const mcrl2::lts::action_label_lts &as) const
Definition lts_lts.h:440
#define hash(l, r, m)
Definition tree_set.cpp:23