spot 2.13
randomltl.hh
1// -*- coding: utf-8 -*-
2// Copyright (C) by the Spot authors, see the AUTHORS file for details.
3//
4// This file is part of Spot, a model checking library.
5//
6// Spot is free software; you can redistribute it and/or modify it
7// under the terms of the GNU General Public License as published by
8// the Free Software Foundation; either version 3 of the License, or
9// (at your option) any later version.
10//
11// Spot is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14// License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19#pragma once
20
21#include <spot/tl/apcollect.hh>
22#include <iosfwd>
23
24#include <unordered_set>
25#include <spot/misc/optionmap.hh>
26#include <spot/misc/hash.hh>
27#include <spot/tl/simplify.hh>
28
29namespace spot
30{
33 class SPOT_API random_formula
34 {
35 public:
36 random_formula(unsigned proba_size,
37 const atomic_prop_set* ap,
38 const atomic_prop_set* output_ap = nullptr,
39 std::function<bool(formula)> is_output = nullptr):
40 proba_size_(proba_size), proba_(new op_proba[proba_size_]), ap_(ap),
41 output_ap_(output_ap), is_output_(is_output)
42 {
43 }
44
45 virtual ~random_formula()
46 {
47 delete[] proba_;
48 }
49
51 const atomic_prop_set* ap() const
52 {
53 return ap_;
54 }
55
58 {
59 return output_ap_;
60 }
61
62 std::function<bool(formula)> is_output_fun() const
63 {
64 return is_output_;
65 }
66
69 {
70 return patterns_;
71 }
72
74 bool draw_literals() const
75 {
76 return draw_literals_;
77 }
78
80 void draw_literals(bool lit)
81 {
82 draw_literals_ = lit;
83 }
84
91 formula generate(int n) const;
92
95 std::ostream& dump_priorities(std::ostream& os) const;
96
104 const char* parse_options(char* options);
105
107 bool has_unary_ops() const
108 {
109 return total_2_ > 0.0;
110 }
111
112 protected:
113 void update_sums();
114
115 struct op_proba
116 {
117 const char* name;
118 int min_n;
119 double proba;
120 typedef formula (*builder)(const random_formula* rl, int n);
121 builder build;
122 void setup(const char* name, int min_n, builder build);
123 };
124 unsigned proba_size_;
125 op_proba* proba_;
126 double total_1_;
127 op_proba* proba_2_;
128 double total_2_;
129 op_proba* proba_2_or_more_;
130 double total_2_and_more_;
131 const atomic_prop_set* ap_;
132 const atomic_prop_set* output_ap_ = nullptr;
133 const atomic_prop_set* patterns_ = nullptr;
134 std::function<bool(formula)> is_output_ = nullptr;
135 bool draw_literals_;
136 };
137
138
151 class SPOT_API random_ltl: public random_formula
152 {
153 public:
159
193 const atomic_prop_set* output_ap = nullptr,
194 std::function<bool(formula)> is_output = nullptr,
195 const atomic_prop_set* subformulas = nullptr);
196
197 protected:
198 void setup_proba_(const atomic_prop_set* patterns);
199 random_ltl(int size, const atomic_prop_set* ap,
200 const atomic_prop_set* output_ap = nullptr,
201 std::function<bool(formula)> is_output = nullptr);
202 };
203
213 class SPOT_API random_boolean final: public random_formula
214 {
215 public:
222
248 const atomic_prop_set* output_ap = nullptr,
249 std::function<bool(formula)> is_output = nullptr,
250 const atomic_prop_set* subformulas = nullptr);
251 };
252
262 class SPOT_API random_sere final: public random_formula
263 {
264 public:
269
292
294 };
295
303 class SPOT_API random_psl: public random_ltl
304 {
305 public:
314
349
352 };
353
354 class SPOT_API randltlgenerator
355 {
356 typedef std::unordered_set<formula> fset_t;
357
358
359 public:
360 enum output_type { Bool, LTL, SERE, PSL };
361 static constexpr unsigned MAX_TRIALS = 100000U;
362
363 randltlgenerator(int aprops_n, const option_map& opts,
364 char* opt_pL = nullptr,
365 char* opt_pS = nullptr,
366 char* opt_pB = nullptr,
367 const atomic_prop_set* subformulas = nullptr,
368 std::function<bool(formula)> is_output = nullptr);
369
370 randltlgenerator(atomic_prop_set aprops, const option_map& opts,
371 char* opt_pL = nullptr,
372 char* opt_pS = nullptr,
373 char* opt_pB = nullptr,
374 const atomic_prop_set* subformulas = nullptr,
375 std::function<bool(formula)> is_output = nullptr);
376
378
379 formula next();
380
381 void dump_ltl_priorities(std::ostream& os);
382 void dump_bool_priorities(std::ostream& os);
383 void dump_psl_priorities(std::ostream& os);
384 void dump_sere_priorities(std::ostream& os);
385 void dump_sere_bool_priorities(std::ostream& os);
386 void remove_some_props(atomic_prop_set& s);
387
388 formula GF_n();
389
390 private:
391 fset_t unique_set_;
392 atomic_prop_set aprops_;
393 atomic_prop_set aprops_out_;
394
395 int opt_seed_;
396 int opt_tree_size_min_;
397 int opt_tree_size_max_;
398 bool opt_unique_;
399 bool opt_wf_;
400 int opt_simpl_level_;
401 tl_simplifier simpl_;
402
403 int output_;
404
405 random_formula* rf_ = nullptr;
406 random_psl* rp_ = nullptr;
407 random_sere* rs_ = nullptr;
408 };
409
410
411}
Main class for temporal logic formula.
Definition: formula.hh:760
Manage a map of options.
Definition: optionmap.hh:34
Definition: randomltl.hh:355
Generate random Boolean formulas.
Definition: randomltl.hh:214
random_boolean(const atomic_prop_set *ap, const atomic_prop_set *output_ap=nullptr, std::function< bool(formula)> is_output=nullptr, const atomic_prop_set *subformulas=nullptr)
Base class for random formula generators.
Definition: randomltl.hh:34
std::ostream & dump_priorities(std::ostream &os) const
Print the priorities of each operator, constants, and atomic propositions.
const atomic_prop_set * output_ap() const
Return the set of atomic proposition used to build formulas.
Definition: randomltl.hh:57
bool draw_literals() const
Check whether relabeling APs should use literals.
Definition: randomltl.hh:74
void draw_literals(bool lit)
Set whether relabeling APs should use literals.
Definition: randomltl.hh:80
bool has_unary_ops() const
whether we can use unary operators
Definition: randomltl.hh:107
const char * parse_options(char *options)
Update the priorities used to generate the formulas.
const atomic_prop_set * patterns() const
Return the set of patterns (sub-formulas) used to build formulas.
Definition: randomltl.hh:68
formula generate(int n) const
Generate a formula of size n.
const atomic_prop_set * ap() const
Return the set of atomic proposition used to build formulas.
Definition: randomltl.hh:51
Generate random LTL formulas.
Definition: randomltl.hh:152
random_ltl(const atomic_prop_set *ap, const atomic_prop_set *output_ap=nullptr, std::function< bool(formula)> is_output=nullptr, const atomic_prop_set *subformulas=nullptr)
Generate random PSL formulas.
Definition: randomltl.hh:304
random_sere rs
The SERE generator used to generate SERE subformulas.
Definition: randomltl.hh:351
random_psl(const atomic_prop_set *ap)
Generate random SERE.
Definition: randomltl.hh:263
random_sere(const atomic_prop_set *ap)
Rewrite or simplify f in various ways.
Definition: simplify.hh:109
@ ap
Atomic proposition.
std::set< formula > atomic_prop_set
Set of atomic propositions.
Definition: apcollect.hh:34
Definition: automata.hh:26
Definition: randomltl.hh:116

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Fri Feb 27 2015 10:00:07 for spot by doxygen 1.9.4