mCRL2
Loading...
Searching...
No Matches
pg_parse.h
Go to the documentation of this file.
1// Author(s): Jeroen Keiren, Wieger Wesselink
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/// \file mcrl2/pbes/pg_parse.h
10/// \brief Parsing of parity games in the format used by PGSolver.
11
12#ifndef MCRL2_BES_PG_PARSE_H
13#define MCRL2_BES_PG_PARSE_H
14
15#include <fstream>
16#include <ranges>
17
18#include "mcrl2/core/parser_utility.h"
19#include "mcrl2/pbes/pbes.h"
20#include "mcrl2/pbes/join.h"
21
22extern "C"
23{
24 extern D_ParserTables parser_tables_pg;
25}
26
27
28
29namespace mcrl2::pbes_system
30{
31
32using identifier_t = unsigned long long;
33using priority_t = unsigned short;
34
35using owner_t = bool;
36
37struct node_t
38{
39 identifier_t id = 0ULL;
40 priority_t prio = 0U;
41 owner_t owner = false;
43
44 bool operator<(node_t const& other)
45 {
46 return id < other.id;
47 }
48};
49
50// Build a formula from the strings in v. if p = 0, than a disjunction is built,
51// otherwise the result is a conjunction.
52// Prefix is added to each of the identifiers in v.
53inline
55{
57 for (identifier_t i: v)
58 {
60 id << prefix << i;
62 }
63
64 if (owner == 0)
65 {
67 }
68 else
69 {
71 }
72}
73
75{
76 // Parse node specifications (store in map)
79
83 {}
84
85 template <typename T, typename Function>
87 {
88 std::set<T> result;
90 return result;
91 }
92
94 {
95 // Build Boolean equation system. First we group equations by block
97 // Translation scheme:
98 // prefix every id with X. Owner 0 means ||, owner 1 means &&
99
100 for (std::map<identifier_t, node_t>::const_iterator i = game.begin(); i != game.end(); ++i)
101 {
103 id << "X" << i->second.id;
104
106 if (i->second.prio % 2 == 0)
107 {
108 fp = fixpoint_symbol::nu();
109 }
110
112
114 }
115
117 if(maxpg)
118 {
119 for (auto& block: std::ranges::reverse_view(blocks))
120 {
122 }
123 }
124 else
125 {
127 {
128 eqns.insert(eqns.end(), i->second.begin(), i->second.end());
129 }
130 }
131
132 b.equations() = eqns;
136 }
137
139 {
140 if(node.child_count() == 5)
141 {
142
144 }
145 if(node.child_count() == 3 && node.child(0).string() == "start")
146 {
148 }
149
150 game.clear();
153 }
154
156 {
163 {
165 }
166 game[result.id] = result;
167 }
168
170 {
173 "NodeSpec",
174 [&](const core::parse_node& node)
175 {
177 return;
178 }));
179 }
180
182 {
184 }
185
187 {
188 return parse_Number<priority_t>(node.child(0));
189 }
190
192 {
193 return node.string() == "1";
194 }
195
197 {
200 return result;
201 }
202
203 template <typename T>
205 {
206 T result;
208 tmp << node.string();
209 tmp >> result;
210 return result;
211 }
212};
213
214/// \brief Reads a parity game from an input stream, and stores it as a BES.
215/// \param text A string
216/// \param result A boolean equation system
217/// \param maxpg If true a max-parity game is generated in \a result, otherwise a min-parity
218/// game is obtained.
219inline
220void parse_pgsolver_string(const std::string& text, pbes& result, bool maxpg = true)
221{
222 core::parser p(parser_tables_pg);
223 unsigned int start_symbol_index = p.start_symbol_index("ParityGame");
224 bool partial_parses = false;
225 core::parse_node node = p.parse(text, start_symbol_index, partial_parses);
226 pg_actions(p).parse_ParityGame(node, result, maxpg);
227}
228
229/// \brief Reads a parity game from an input stream, and stores it as a BES.
230/// \param from An input stream
231/// \param result A boolean equation system
232/// \param maxpg If true a max-parity game is generated in \a result, otherwise a min-parity
233/// game is obtained.
234inline
235void parse_pgsolver(std::istream& from, pbes& result, bool maxpg = true)
236{
237 std::string text = utilities::read_text(from);
238 parse_pgsolver_string(text, result, maxpg);
239}
240
241/// \brief Parse parity game in PGSolver format from filename, and store the
242/// resulting BES in b.
243inline void parse_pgsolver(const std::string& filename, pbes& b, bool maxpg = true)
244{
245 if(filename == "-" || filename.empty())
246 {
247 parse_pgsolver(std::cin, b, maxpg);
248 }
249 else
250 {
251 std::ifstream f;
252 f.open(filename.c_str());
253 if(!f)
254 {
255 throw mcrl2::runtime_error("cannot open file " + filename + " for reading");
256 }
257 parse_pgsolver(f, b, maxpg);
258 }
259}
260
261} // namespace mcrl2::pbes_system
262
263
264
265#endif // MCRL2_BES_PG_PARSE_H
parameterized boolean equation system
Definition pbes.h:54
void parse_pgsolver(std::istream &from, pbes &result, bool maxpg=true)
Reads a parity game from an input stream, and stores it as a BES.
Definition pg_parse.h:235
void parse_pgsolver_string(const std::string &text, pbes &result, bool maxpg=true)
Reads a parity game from an input stream, and stores it as a BES.
Definition pg_parse.h:220
void parse_pgsolver(const std::string &filename, pbes &b, bool maxpg=true)
Parse parity game in PGSolver format from filename, and store the resulting BES in b.
Definition pg_parse.h:243
pbes_expression formula(std::set< identifier_t > const &v, const owner_t owner, const std::string &prefix="X")
Definition pg_parse.h:54
D_ParserTables parser_tables_pg
bool operator<(node_t const &other)
Definition pg_parse.h:44
std::set< identifier_t > successors
Definition pg_parse.h:42