spot  1.99.3
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
common_aoutput.hh
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2014, 2015 Laboratoire de Recherche et Développement
3 // de l'Epita (LRDE).
4 //
5 // This file is part of Spot, a model checking library.
6 //
7 // Spot is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // Spot is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 
20 #pragma once
21 
22 #include "common_sys.hh"
23 
24 #include <argp.h>
25 #include <memory>
26 
27 #include "parseaut/public.hh"
28 
29 #include "twaalgos/stats.hh"
30 #include "twaalgos/sccinfo.hh"
31 #include "twaalgos/gtec/gtec.hh"
32 #include "twaalgos/reducerun.hh"
33 #include "twaalgos/word.hh"
34 #include "twaalgos/isdet.hh"
35 #include "common_file.hh"
36 
37 
38 // Format for automaton output
39 enum automaton_format_t {
40  Dot,
41  Lbtt,
42  Spin,
43  Stats,
44  Hoa,
45  Quiet,
46  Count,
47 };
48 
49 // The format to use in output_automaton()
50 extern automaton_format_t automaton_format;
51 // Set to the argument of --name, else nullptr.
52 extern const char* opt_name;
53 // Output options
54 extern const struct argp aoutput_argp;
55 
56 // help text for %F and %L
57 extern char F_doc[32];
58 extern char L_doc[32];
59 
60 // FORMAT help text
61 extern const struct argp aoutput_io_format_argp;
62 extern const struct argp aoutput_o_format_argp;
63 
64 // Parse output options
65 int parse_opt_aoutput(int key, char* arg, struct argp_state* state);
66 
67 
68 enum stat_style { no_input, aut_input, ltl_input };
69 
76 {
77 public:
78  hoa_stat_printer(std::ostream& os, const char* format,
79  stat_style input = no_input)
80  : spot::stat_printer(os, format)
81  {
82  if (input == aut_input)
83  {
84  declare('A', &haut_acc_);
85  declare('C', &haut_scc_);
86  declare('E', &haut_edges_);
87  declare('G', &haut_gen_acc_);
88  declare('M', &haut_name_);
89  declare('S', &haut_states_);
90  declare('T', &haut_trans_);
91  }
92  declare('F', &filename_);
93  declare('L', &location_);
94  if (input != ltl_input)
95  declare('f', &filename_); // Override the formula printer.
96  declare('m', &aut_name_);
97  declare('w', &aut_word_);
98  }
99 
102 
107  std::ostream&
108  print(const spot::const_parsed_aut_ptr& haut,
109  const spot::const_twa_graph_ptr& aut,
110  const spot::ltl::formula* f,
111  const char* filename, int loc, double run_time)
112  {
113  filename_ = filename ? filename : "";
114  if (loc >= 0 && has('L'))
115  {
116  std::ostringstream os;
117  os << loc;
118  location_ = os.str();
119  }
120  if (haut)
121  {
122  if (loc < 0 && has('L'))
123  {
124  std::ostringstream os;
125  os << haut->loc;
126  location_ = os.str();
127  }
128 
129  if (has('T'))
130  {
132  haut_states_ = s.states;
133  haut_edges_ = s.transitions;
134  haut_trans_ = s.sub_transitions;
135  }
136  else if (has('E'))
137  {
139  haut_states_ = s.states;
140  haut_edges_ = s.transitions;
141  }
142  if (has('M'))
143  {
144  auto n = haut->aut->get_named_prop<std::string>("automaton-name");
145  if (n)
146  haut_name_ = *n;
147  else
148  haut_name_.val().clear();
149  }
150  if (has('S'))
151  haut_states_ = haut->aut->num_states();
152 
153  if (has('A'))
154  haut_acc_ = haut->aut->acc().num_sets();
155 
156  if (has('C'))
157  haut_scc_ = spot::scc_info(haut->aut).scc_count();
158 
159  if (has('G'))
160  {
161  std::ostringstream os;
162  os << haut->aut->get_acceptance();
163  haut_gen_acc_ = os.str();
164  }
165  }
166 
167  if (has('m'))
168  {
169  auto n = aut->get_named_prop<std::string>("automaton-name");
170  if (n)
171  aut_name_ = *n;
172  else
173  aut_name_.val().clear();
174  }
175  if (has('w'))
176  {
177  auto res = spot::couvreur99(aut)->check();
178  if (res)
179  {
180  auto run = res->accepting_run();
181  assert(run);
182  run = reduce_run(aut, run);
183  spot::tgba_word w(run);
184  w.simplify();
185  std::ostringstream out;
186  w.print(out, aut->get_dict());
187  aut_word_ = out.str();
188  }
189  else
190  {
191  aut_word_.val().clear();
192  }
193  }
194 
195  return this->spot::stat_printer::print(aut, f, run_time);
196  }
197 
198 private:
205  spot::printable_value<unsigned> haut_states_;
210 };
211 
212 
214 {
215  hoa_stat_printer statistics;
216  std::ostringstream name;
217  hoa_stat_printer namer;
218  std::ostringstream outputname;
219  hoa_stat_printer outputnamer;
220  std::map<std::string, std::unique_ptr<output_file>> outputfiles;
221 
222 public:
223 
224  automaton_printer(stat_style input = no_input);
225 
226  void
227  print(const spot::twa_graph_ptr& aut,
228  const spot::ltl::formula* f = nullptr,
229  // Input location for errors and statistics.
230  const char* filename = nullptr,
231  int loc = -1,
232  // Time and input automaton for statistics
233  double time = 0.0,
234  const spot::const_parsed_aut_ptr& haut = nullptr);
235 
236  void add_stat(char c, const spot::printable* p);
237 };
An infinite word stored as a lasso.
Definition: word.hh:29
Definition: sccinfo.hh:27
void set_output(std::ostream &output)
Remember where to output any string.
Definition: formater.hh:163
std::ostream & print(const const_twa_graph_ptr &aut, const ltl::formula *f=0, double run_time=-1.)
print the configured statistics.
std::ostream & print(const spot::const_parsed_aut_ptr &haut, const spot::const_twa_graph_ptr &aut, const spot::ltl::formula *f, const char *filename, int loc, double run_time)
print the configured statistics.
Definition: common_aoutput.hh:108
void declare(char c, const printable *f)
Declare a callback function for c.
Definition: formater.hh:156
std::ostream & format(const char *fmt)
Expand the %-sequences in fmt, write the result on output_.
SPOT_API tgba_run_ptr reduce_run(const const_twa_ptr &a, const const_tgba_run_ptr &org)
Reduce an accepting run.
prints various statistics about a TGBA
Definition: stats.hh:77
Definition: formater.hh:29
prints various statistics about a TGBA
Definition: common_aoutput.hh:75
bool has(char c) const
Whether c occurred in the primed formats.
Definition: formater.hh:149
SPOT_API tgba_sub_statistics sub_stats_reachable(const const_twa_ptr &g)
Compute sub statistics for an automaton.
Definition: stats.hh:44
An LTL formula.
Definition: formula.hh:71
SPOT_API emptiness_check_ptr couvreur99(const const_twa_ptr &a, option_map options=option_map())
Check whether the language of an automate is empty.
Definition: common_aoutput.hh:213

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Wed Aug 26 2015 08:42:37 for spot by doxygen 1.8.8