mCRL2
Loading...
Searching...
No Matches
disjointness_checker.h
Go to the documentation of this file.
1// Author(s): Luc Engelen
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//
11
12// Interface to class Disjointness_Checker
13// file: disjointness_checker.h
14
15#ifndef MCRL2_LPS_DISJOINTNESS_CHECKER_H
16#define MCRL2_LPS_DISJOINTNESS_CHECKER_H
17
19
30
31namespace mcrl2
32{
33namespace lps
34{
35namespace detail
36{
37
39{
40 private:
43
45 std::vector<std::set<data::variable> > f_used_parameters_per_summand;
46
48 std::vector<std::set<data::variable> > f_changed_parameters_per_summand;
49
51 void process_data_expression(std::size_t n, const data::data_expression& x);
52
54 void process_multi_action(std::size_t n, const multi_action& a);
55
58 void process_summand(std::size_t n, const action_summand& s);
59
60 public:
69 template <typename LinearProcess>
70 Disjointness_Checker(const LinearProcess& a_process_equation);
71
73 bool disjoint(std::size_t n1, std::size_t n2);
74};
75
76inline
78{
79 // This should probably once be replaced by a visitor.
81 {
82 // Do nothing.
83 }
84 else if (data::is_variable(x))
85 {
87 }
88 else if (data::is_where_clause(x))
89 {
90 const data::where_clause& t = atermpp::down_cast<data::where_clause>(x);
92 const data::assignment_list& assignments = t.assignments();
93 for (const auto & assignment : assignments)
94 {
96 }
97 }
98 else if (data::is_function_symbol(x))
99 {
100 // do nothing
101 }
102 else if (data::is_application(x))
103 {
104 const data::application& t = atermpp::down_cast<data::application>(x);
106 for (auto i = t.begin(); i != t.end(); ++i)
107 {
109 }
110 }
111 else if (data::is_abstraction(x))
112 {
113 const data::abstraction& t = atermpp::down_cast<data::abstraction>(x);
115 }
116 else
117 {
118 throw mcrl2::runtime_error("disjointness checker encountered unknown term " + data::pp(x));
119 }
120}
121
122inline
124{
125 if (a.has_time())
126 {
128 }
129
130 const process::action_list& v_actions = a.actions();
131 for (const auto & v_action : v_actions)
132 {
133 const data::data_expression_list v_expressions=v_action.arguments();
134
135 for (const auto & v_expression : v_expressions)
136 {
137 process_data_expression(n, v_expression);
138 }
139 }
140}
141
142inline
144{
145 // variables used in condition
147
148 // variables used in multiaction
150
151 // variables used and changed in assignments
152 const data::assignment_list& v_assignments = s.assignments();
153 for (const auto & v_assignment : v_assignments)
154 {
155 // variables changed in the assignment
156 f_changed_parameters_per_summand[n].insert(v_assignment.lhs());
157
158 // variables used in assignment
159 process_data_expression(n, v_assignment.rhs());
160 }
161}
162
163template <typename LinearProcess>
164Disjointness_Checker::Disjointness_Checker(const LinearProcess& a_process_equation)
165{
166 const auto& v_summands = a_process_equation.action_summands();
167 std::size_t v_summand_number = 1;
168
169 f_number_of_summands = v_summands.size();
171 std::vector<std::set<data::variable> >(f_number_of_summands + 1, std::set<data::variable>());
173 std::vector<std::set<data::variable> >(f_number_of_summands + 1, std::set<data::variable>());
174
175 for (const auto & v_summand : v_summands)
176 {
177 process_summand(v_summand_number, v_summand);
178 v_summand_number++;
179 }
180}
181
182inline
183bool Disjointness_Checker::disjoint(std::size_t n1, std::size_t n2)
184{
186 assert(n1 <= f_number_of_summands && n2 <= f_number_of_summands);
187 bool v_used_1_changed_2 = has_empty_intersection(f_used_parameters_per_summand[n1], f_changed_parameters_per_summand[n2]);
188 bool v_used_2_changed_1 = has_empty_intersection(f_used_parameters_per_summand[n2], f_changed_parameters_per_summand[n1]);
189 bool v_changed_1_changed_2 = has_empty_intersection(f_changed_parameters_per_summand[n1], f_changed_parameters_per_summand[n2]);
190 return v_used_1_changed_2 && v_used_2_changed_1 && v_changed_1_changed_2;
191}
192
193} // namespace detail
194} // namespace lps
195} // namespace mcrl2
196
197#endif
An abstraction expression.
Definition abstraction.h:26
const data_expression & body() const
Definition abstraction.h:68
An application of a data expression to a number of arguments.
const_iterator end() const
Returns an iterator pointing past the last argument of the application.
const_iterator begin() const
Returns an iterator pointing to the first argument of the application.
const data_expression & head() const
Get the function at the head of this expression.
\brief Assignment of a data expression to a variable
Definition assignment.h:91
const data_expression & rhs() const
Definition assignment.h:122
\brief A data variable
Definition variable.h:28
\brief A where expression
const assignment_list & assignments() const
const data_expression & body() const
LPS summand containing a multi-action.
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.
void process_data_expression(std::size_t n, const data::data_expression &x)
Updates the array Disjointness_Checker::f_used_parameters_per_summand, given the expression a_express...
Disjointness_Checker(const LinearProcess &a_process_equation)
Constructor that initializes the sets Disjointness_Checker::f_used_parameters_per_summand and.
std::vector< std::set< data::variable > > f_used_parameters_per_summand
A two dimensional array, indicating which parameters a summand uses, for each of the summands.
std::vector< std::set< data::variable > > f_changed_parameters_per_summand
A two dimensional array, indicating which parameters a summand changes, for each of the summands.
void process_multi_action(std::size_t n, const multi_action &a)
Updates the array Disjointness_Checker::f_used_parameters_per_summand, given the multiaction a.
std::size_t f_number_of_summands
The number of summands of the LPS passed as argument of the constructor.
bool disjoint(std::size_t n1, std::size_t n2)
Indicates whether or not the summands with number n_1 and n_2 are disjoint.
void process_summand(std::size_t n, const action_summand &s)
Updates the arrays Disjointness_Checker::f_changed_parameters_per_summand and.
\brief A timed multi-action
bool has_time() const
Returns true if time is available.
const process::action_list & actions() const
const data::data_expression & time() const
const data::data_expression & condition() const
Returns the condition expression.
Definition summand.h:60
Standard exception class for reporting runtime errors.
Definition exception.h:27
The class linear_process.
bool is_where_clause(const atermpp::aterm &x)
Returns true if the term t is a where clause.
bool is_abstraction(const atermpp::aterm &x)
Returns true if the term t is an abstraction.
std::string pp(const abstraction &x)
Definition data.cpp:39
bool is_function_symbol(const atermpp::aterm &x)
Returns true if the term t is a function symbol.
bool is_machine_number(const atermpp::aterm &x)
Returns true if the term t is a machine_number.
bool is_application(const atermpp::aterm &x)
Returns true if the term t is an application.
bool is_variable(const atermpp::aterm &x)
Returns true if the term t is a variable.
bool has_empty_intersection(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2)
Returns true if the sorted ranges [first1, ..., last1) and [first2, ..., last2) have an empty interse...
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72