mCRL2
Loading...
Searching...
No Matches
lps_io.cpp
Go to the documentation of this file.
1// Author(s): Maurice Laveaux
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
10#include "mcrl2/lps/io.h"
11
14
15namespace mcrl2::lps
16{
17
19{
20 return atermpp::aterm(atermpp::function_symbol("linear_process_specification", 0));
21}
22
24{
25 stream << action.actions();
26 stream << action.time();
27 return stream;
28}
29
31{
34
35 stream >> actions;
36 stream >> time;
37
38 action = multi_action(actions, time);
39 return stream;
40}
41
43{
44 stream << summand.summation_variables();
45 stream << summand.condition();
46 stream << summand.deadlock().time();
47 return stream;
48}
49
51{
52 data::variable_list summation_variables;
53 data::data_expression condition;
55
56 stream >> summation_variables;
57 stream >> condition;
58 stream >> time;
59
60 summand = deadlock_summand(summation_variables, condition, lps::deadlock(time));
61 return stream;
62}
63
65{
66 stream << summand.distribution();
67 stream << summand.summation_variables();
68 stream << summand.condition();
69 stream << summand.multi_action();
70 stream << summand.assignments();
71 return stream;
72}
73
75{
76 stochastic_distribution distribution;
77 data::variable_list summation_variables;
78 data::data_expression condition;
80 data::assignment_list assignments;
81
82 stream >> distribution;
83 stream >> summation_variables;
84 stream >> condition;
85 stream >> multi_action;
86 stream >> assignments;
87
88 summand = stochastic_action_summand(summation_variables,
89 condition,
91 assignments,
92 distribution);
93 return stream;
94}
95
96template <typename ActionSummand>
98{
99 stream << lps.process_parameters();
100 stream << lps.action_summands();
101 stream << lps.deadlock_summands();
102
103 return stream;
104}
105
106template <typename ActionSummand>
108{
109 data::variable_list process_parameters;
110 deadlock_summand_vector deadlock_summands;
111 std::vector<ActionSummand> action_summands;
112
113 stream >> process_parameters;
114 stream >> action_summands;
115 stream >> deadlock_summands;
116
117 lps = linear_process_base<ActionSummand>(process_parameters, deadlock_summands, action_summands);
118 return stream;
119}
120
121static
123{
126
128 stream << spec.data();
129 stream << spec.action_labels();
130 stream << spec.global_variables();
131 stream << spec.process();
132 stream << spec.initial_process();
133}
134
135static
137{
140
141 try
142 {
143 atermpp::aterm marker;
144 stream >> marker;
145
147 {
148 throw mcrl2::runtime_error("Stream does not contain a linear process specification (LPS).");
149 }
150
152 process::action_label_list action_labels;
153 std::set<data::variable> global_variables;
155 stochastic_process_initializer initial_process;
156
157 stream >> data;
158 stream >> action_labels;
159 stream >> global_variables;
160 stream >> process;
161 stream >> initial_process;
162 spec = stochastic_specification(data, action_labels, global_variables, process, initial_process);
163 }
164 catch (std::exception& ex)
165 {
166 mCRL2log(log::error) << ex.what() << "\n";
167 throw mcrl2::runtime_error(std::string("Error reading linear process specification (LPS)."));
168 }
169}
170
172{
174 return stream;
175}
176
178{
179 write_spec(stream, spec);
180 return stream;
181}
182
184{
185 stochastic_specification stochastic_spec;
186 read_spec(stream, stochastic_spec);
187 spec = remove_stochastic_operators(stochastic_spec);
188 return stream;
189}
190
192{
193 read_spec(stream, spec);
194 return stream;
195}
196
197} // namespace mcrl2::lps
The interface for a class that reads aterm from a stream. The default constructed term aterm() indica...
Definition aterm_io.h:59
The interface for a class that writes aterm to a stream. Every written term is retrieved by the corre...
Definition aterm_io.h:48
A helper class to restore the state of the aterm_{i,o}stream objects upon destruction....
Definition aterm_io.h:84
A list of aterm objects.
Definition aterm_list.h:24
const lps::multi_action & multi_action() const
Returns the multi-action of this summand.
const data::assignment_list & assignments() const
Returns the sequence of assignments.
LPS summand containing a deadlock.
const lps::deadlock & deadlock() const
Returns the deadlock of this summand.
Represents a deadlock.
Definition deadlock.h:26
const data::data_expression & time() const
Returns the time.
Definition deadlock.h:49
const std::vector< ActionSummand > & action_summands() const
Returns the sequence of action summands.
const deadlock_summand_vector & deadlock_summands() const
Returns the sequence of deadlock summands.
const data::variable_list & process_parameters() const
Returns the sequence of process parameters.
\brief A timed multi-action
const process::action_list & actions() const
const data::data_expression & time() const
const std::set< data::variable > & global_variables() const
Returns the declared free variables of the LPS.
const process::action_label_list & action_labels() const
Returns a sequence of action labels. This sequence contains all action labels occurring in the specif...
const InitialProcessExpression & initial_process() const
Returns the initial process.
const LinearProcess & process() const
Returns the linear process of the specification.
const data::data_specification & data() const
Returns the data specification.
Linear process specification.
LPS summand containing a multi-action.
const stochastic_distribution & distribution() const
Returns the distribution of this summand.
\brief A stochastic distribution
const data::data_expression & condition() const
Returns the condition expression.
Definition summand.h:60
data::variable_list & summation_variables()
Returns the sequence of summation variables.
Definition summand.h:46
Standard exception class for reporting runtime errors.
Definition exception.h:27
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:391
IO routines for linear process specifications.
atermpp::aterm remove_index_impl(const atermpp::aterm &x)
Definition io.h:28
atermpp::aterm add_index_impl(const atermpp::aterm &x)
Definition io.h:39
The main namespace for the LPS library.
atermpp::term_balanced_tree< data::data_expression > state
Definition state.h:24
std::vector< deadlock_summand > deadlock_summand_vector
\brief vector of deadlock_summands
std::ostream & operator<<(std::ostream &out, const action_summand &x)
atermpp::aterm linear_process_specification_marker()
Definition lps_io.cpp:18
specification remove_stochastic_operators(const stochastic_specification &spec)
Converts a stochastic specification to a specification. Throws an exception if non-empty distribution...
std::istream & operator>>(std::istream &is, exploration_strategy &strat)
static void read_spec(atermpp::aterm_istream &stream, stochastic_specification &spec)
Definition lps_io.cpp:136
static void write_spec(atermpp::aterm_ostream &stream, const stochastic_specification &spec)
Definition lps_io.cpp:122
The class specification.