spot  2.14.5
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 
29 namespace 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 
57  const atomic_prop_set* output_ap() const
58  {
59  return output_ap_;
60  }
61 
62  std::function<bool(formula)> is_output_fun() const
63  {
64  return is_output_;
65  }
66 
68  const atomic_prop_set* patterns() const
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 
194  const atomic_prop_set* output_ap = nullptr,
195  std::function<bool(formula)> is_output = nullptr,
196  const atomic_prop_set* subformulas = nullptr);
197 
198  protected:
199  void setup_proba_(const atomic_prop_set* patterns);
200  random_ltl(int size, const atomic_prop_set* ap,
201  const atomic_prop_set* output_ap = nullptr,
202  std::function<bool(formula)> is_output = nullptr);
203  };
204 
214  class SPOT_API random_boolean final: public random_formula
215  {
216  public:
223 
249  const atomic_prop_set* output_ap = nullptr,
250  std::function<bool(formula)> is_output = nullptr,
251  const atomic_prop_set* subformulas = nullptr);
252  };
253 
263  class SPOT_API random_sere final: public random_formula
264  {
265  public:
270 
293 
294  random_boolean rb;
295  };
296 
304  class SPOT_API random_psl: public random_ltl
305  {
306  public:
315 
350 
353  };
354 
355  class SPOT_API randltlgenerator
356  {
357  typedef std::unordered_set<formula> fset_t;
358 
359 
360  public:
361  enum output_type { Bool, LTL, SERE, PSL };
362  static constexpr unsigned MAX_TRIALS = 100000U;
363 
364  randltlgenerator(int aprops_n, const option_map& opts,
365  char* opt_pL = nullptr,
366  char* opt_pS = nullptr,
367  char* opt_pB = nullptr,
368  const atomic_prop_set* subformulas = nullptr,
369  std::function<bool(formula)> is_output = nullptr);
370 
371  randltlgenerator(atomic_prop_set aprops, const option_map& opts,
372  char* opt_pL = nullptr,
373  char* opt_pS = nullptr,
374  char* opt_pB = nullptr,
375  const atomic_prop_set* subformulas = nullptr,
376  std::function<bool(formula)> is_output = nullptr);
377 
378  ~randltlgenerator();
379 
380  formula next();
381 
382  void dump_ltl_priorities(std::ostream& os);
383  void dump_bool_priorities(std::ostream& os);
384  void dump_psl_priorities(std::ostream& os);
385  void dump_sere_priorities(std::ostream& os);
386  void dump_sere_bool_priorities(std::ostream& os);
387  void remove_some_props(atomic_prop_set& s);
388 
389  formula GF_n();
390 
391  private:
392  fset_t unique_set_;
393  atomic_prop_set aprops_;
394  atomic_prop_set aprops_out_;
395 
396  int opt_seed_;
397  int opt_tree_size_min_;
398  int opt_tree_size_max_;
399  bool opt_unique_;
400  bool opt_wf_;
401  int opt_simpl_level_;
402  tl_simplifier simpl_;
403 
404  int output_;
405 
406  random_formula* rf_ = nullptr;
407  random_psl* rp_ = nullptr;
408  random_sere* rs_ = nullptr;
409  };
410 
411 
412 }
Main class for temporal logic formula.
Definition: formula.hh:786
Manage a map of options.
Definition: optionmap.hh:34
Definition: randomltl.hh:356
Generate random Boolean formulas.
Definition: randomltl.hh:215
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 char * parse_options(char *options)
Update the priorities used to generate the formulas.
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
const atomic_prop_set * output_ap() const
Return the set of atomic proposition used to build formulas.
Definition: randomltl.hh:57
bool has_unary_ops() const
whether we can use unary operators
Definition: randomltl.hh:107
const atomic_prop_set * patterns() const
Return the set of patterns (sub-formulas) used to build formulas.
Definition: randomltl.hh:68
const atomic_prop_set * ap() const
Return the set of atomic proposition used to build formulas.
Definition: randomltl.hh:51
formula generate(int n) const
Generate a formula of size n.
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:305
random_sere rs
The SERE generator used to generate SERE subformulas.
Definition: randomltl.hh:352
random_psl(const atomic_prop_set *ap)
Generate random SERE.
Definition: randomltl.hh:264
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.1