spot 2.16
Loading...
Searching...
No Matches
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:
38 random_formula(unsigned proba_size,
39 const atomic_prop_set* ap,
40 const atomic_prop_set* output_ap = nullptr,
41 std::function<bool(formula)> is_output = nullptr):
42 proba_size_(proba_size), proba_(new op_proba[proba_size_]), ap_(ap),
43 output_ap_(output_ap), is_output_(is_output)
44 {
45 }
46
47 virtual ~random_formula()
48 {
49 delete[] proba_;
50 }
51
53 const atomic_prop_set* ap() const
54 {
55 return ap_;
56 }
57
60 {
61 return output_ap_;
62 }
63
65 std::function<bool(formula)> is_output_fun() const
66 {
67 return is_output_;
68 }
69
72 {
73 return patterns_;
74 }
75
77 bool draw_literals() const
78 {
79 return draw_literals_;
80 }
81
83 void draw_literals(bool lit)
84 {
85 draw_literals_ = lit;
86 }
87
94 formula generate(int n) const;
95
98 std::ostream& dump_priorities(std::ostream& os) const;
99
109 const char* parse_options(const char* options);
110
112 bool has_unary_ops() const
113 {
114 return total_2_ > 0.0;
115 }
116
117 protected:
120
123 struct op_proba
124 {
125 const char* name;
126 int min_n;
127 double proba;
129 typedef formula (*builder)(const random_formula* rl, int n);
130 builder build;
132 void setup(const char* name, int min_n, builder build);
133 };
134 unsigned proba_size_;
136 double total_1_;
138 double total_2_;
144 const atomic_prop_set* output_ap_ = nullptr;
146 const atomic_prop_set* patterns_ = nullptr;
148 std::function<bool(formula)> is_output_ = nullptr;
150 };
151
152
165 class SPOT_API random_ltl: public random_formula
166 {
167 public:
173
208 const atomic_prop_set* output_ap = nullptr,
209 std::function<bool(formula)> is_output = nullptr,
210 const atomic_prop_set* subformulas = nullptr);
211
212 protected:
214 void setup_proba_(const atomic_prop_set* patterns);
216 random_ltl(int size, const atomic_prop_set* ap,
217 const atomic_prop_set* output_ap = nullptr,
218 std::function<bool(formula)> is_output = nullptr);
219 };
220
230 class SPOT_API random_boolean final: public random_formula
231 {
232 public:
239
265 const atomic_prop_set* output_ap = nullptr,
266 std::function<bool(formula)> is_output = nullptr,
267 const atomic_prop_set* subformulas = nullptr);
268 };
269
279 class SPOT_API random_sere final: public random_formula
280 {
281 public:
286
309
312 };
313
321 class SPOT_API random_psl: public random_ltl
322 {
323 public:
332
367
370 };
371
374 class SPOT_API randltlgenerator
375 {
376 typedef std::unordered_set<formula> fset_t;
377
378
379 public:
381 enum output_type { Bool, LTL, SERE, PSL };
383 static constexpr unsigned MAX_TRIALS = 100000U;
384
386 randltlgenerator(int aprops_n, const option_map& opts,
387 const char* opt_pL = nullptr,
388 const char* opt_pS = nullptr,
389 const char* opt_pB = nullptr,
390 const atomic_prop_set* subformulas = nullptr,
391 std::function<bool(formula)> is_output = nullptr);
392
395 const char* opt_pL = nullptr,
396 const char* opt_pS = nullptr,
397 const char* opt_pB = nullptr,
398 const atomic_prop_set* subformulas = nullptr,
399 std::function<bool(formula)> is_output = nullptr);
400
402
405
407 void dump_ltl_priorities(std::ostream& os);
409 void dump_bool_priorities(std::ostream& os);
411 void dump_psl_priorities(std::ostream& os);
413 void dump_sere_priorities(std::ostream& os);
415 void dump_sere_bool_priorities(std::ostream& os);
418
421
422 private:
423 fset_t unique_set_;
424 atomic_prop_set aprops_;
425 atomic_prop_set aprops_out_;
426
427 int opt_seed_;
428 int opt_tree_size_min_;
429 int opt_tree_size_max_;
430 bool opt_unique_;
431 bool opt_wf_;
432 tl_simplifier_options simplify_opts_;
433 tl_simplifier simpl_;
434
435 int output_;
436
437 random_formula* rf_ = nullptr;
438 random_psl* rp_ = nullptr;
439 random_sere* rs_ = nullptr;
440 };
441
442
443}
Main class for temporal logic formula.
Definition formula.hh:847
Manage a map of options.
Definition optionmap.hh:34
Generator of random LTL/PSL/SERE/Boolean formulas with configurable options.
Definition randomltl.hh:375
void dump_sere_bool_priorities(std::ostream &os)
Print SERE Boolean operator priorities to os.
randltlgenerator(int aprops_n, const option_map &opts, const char *opt_pL=nullptr, const char *opt_pS=nullptr, const char *opt_pB=nullptr, const atomic_prop_set *subformulas=nullptr, std::function< bool(formula)> is_output=nullptr)
Construct with aprops_n random atomic propositions.
output_type
Output formula type produced by the generator.
Definition randomltl.hh:381
formula next()
Generate the next random formula (up to MAX_TRIALS attempts).
void dump_psl_priorities(std::ostream &os)
Print PSL operator priorities to os.
void dump_sere_priorities(std::ostream &os)
Print SERE operator priorities to os.
void remove_some_props(atomic_prop_set &s)
Remove some propositions from s (used for well-formed generation).
void dump_bool_priorities(std::ostream &os)
Print Boolean operator priorities to os.
void dump_ltl_priorities(std::ostream &os)
Print LTL operator priorities to os.
randltlgenerator(atomic_prop_set aprops, const option_map &opts, const char *opt_pL=nullptr, const char *opt_pS=nullptr, const char *opt_pB=nullptr, const atomic_prop_set *subformulas=nullptr, std::function< bool(formula)> is_output=nullptr)
Construct with an explicit set of atomic propositions.
formula GF_n()
Return a GF(p1 & ... & pn) formula over n random propositions.
Generate random Boolean formulas.
Definition randomltl.hh:231
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.
double total_2_
Total weight of binary operators.
Definition randomltl.hh:138
double total_2_and_more_
Total weight of operators needing two or more children.
Definition randomltl.hh:141
double total_1_
Total weight of unary operators.
Definition randomltl.hh:136
const atomic_prop_set * output_ap() const
Return the set of atomic proposition used to build formulas.
Definition randomltl.hh:59
bool draw_literals() const
Check whether relabeling APs should use literals.
Definition randomltl.hh:77
random_formula(unsigned proba_size, const atomic_prop_set *ap, const atomic_prop_set *output_ap=nullptr, std::function< bool(formula)> is_output=nullptr)
Construct with proba_size operator slots and atomic propositions ap.
Definition randomltl.hh:38
void draw_literals(bool lit)
Set whether relabeling APs should use literals.
Definition randomltl.hh:83
std::function< bool(formula)> is_output_fun() const
Return the predicate that classifies propositions as output.
Definition randomltl.hh:65
bool has_unary_ops() const
whether we can use unary operators
Definition randomltl.hh:112
bool draw_literals_
Whether relabeling APs should use literals.
Definition randomltl.hh:149
const atomic_prop_set * patterns() const
Return the set of patterns (sub-formulas) used to build formulas.
Definition randomltl.hh:71
const atomic_prop_set * ap_
Definition randomltl.hh:142
op_proba * proba_2_or_more_
Definition randomltl.hh:139
formula generate(int n) const
Generate a formula of size n.
void update_sums()
Recompute running probability sums after priorities have changed.
unsigned proba_size_
Number of entries in the operator table.
Definition randomltl.hh:134
op_proba * proba_2_
Pointer to binary operators in the table.
Definition randomltl.hh:137
const char * parse_options(const char *options)
Update the priorities used to generate the formulas.
op_proba * proba_
Operator probability table.
Definition randomltl.hh:135
const atomic_prop_set * ap() const
Return the set of atomic proposition used to build formulas.
Definition randomltl.hh:53
Generate random LTL formulas.
Definition randomltl.hh:166
void setup_proba_(const atomic_prop_set *patterns)
Initialize the probability table, optionally using patterns as atoms.
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)
random_ltl(int size, const atomic_prop_set *ap, const atomic_prop_set *output_ap=nullptr, std::function< bool(formula)> is_output=nullptr)
Construct with explicit table size (for subclasses).
Generate random PSL formulas.
Definition randomltl.hh:322
random_sere rs
The SERE generator used to generate SERE subformulas.
Definition randomltl.hh:369
random_psl(const atomic_prop_set *ap)
Generate random SERE.
Definition randomltl.hh:280
random_boolean rb
The Boolean formula generator used to build Boolean sub-expressions.
Definition randomltl.hh:311
random_sere(const atomic_prop_set *ap)
Options controlling which simplification passes the tl_simplifier applies.
Definition simplify.hh:34
Rewrite or simplify f in various ways.
Definition simplify.hh:145
@ ap
Atomic proposition.
std::set< formula > atomic_prop_set
Set of atomic propositions.
Definition apcollect.hh:34
Definition automata.hh:26
Entry describing one operator and its probability for random formula generation.
Definition randomltl.hh:124
const char * name
Name of the operator.
Definition randomltl.hh:125
builder build
Definition randomltl.hh:130
void setup(const char *name, int min_n, builder build)
Initialize the entry with name, min_n, and build.
double proba
Definition randomltl.hh:127
int min_n
Minimum formula size needed for this operator.
Definition randomltl.hh:126

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.8