spot  1.99.6
 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/word.hh"
33 #include "twaalgos/isdet.hh"
34 #include "common_file.hh"
35 
36 
37 // Format for automaton output
38 enum automaton_format_t {
39  Dot,
40  Lbtt,
41  Spin,
42  Stats,
43  Hoa,
44  Quiet,
45  Count,
46 };
47 
48 // The format to use in output_automaton()
49 extern automaton_format_t automaton_format;
50 // Set to the argument of --name, else nullptr.
51 extern const char* opt_name;
52 // Output options
53 extern const struct argp aoutput_argp;
54 
55 // help text for %F and %L
56 extern char F_doc[32];
57 extern char L_doc[32];
58 
59 // FORMAT help text
60 extern const struct argp aoutput_io_format_argp;
61 extern const struct argp aoutput_o_format_argp;
62 
63 // Parse output options
64 int parse_opt_aoutput(int key, char* arg, struct argp_state* state);
65 
66 
67 enum stat_style { no_input, aut_input, ltl_input };
68 
75 {
76 public:
77  hoa_stat_printer(std::ostream& os, const char* format,
78  stat_style input = no_input)
79  : spot::stat_printer(os, format)
80  {
81  if (input == aut_input)
82  {
83  declare('A', &haut_acc_);
84  declare('C', &haut_scc_);
85  declare('E', &haut_edges_);
86  declare('G', &haut_gen_acc_);
87  declare('M', &haut_name_);
88  declare('S', &haut_states_);
89  declare('T', &haut_trans_);
90  }
91  declare('F', &filename_);
92  declare('L', &location_);
93  if (input != ltl_input)
94  declare('f', &filename_); // Override the formula printer.
95  declare('m', &aut_name_);
96  declare('w', &aut_word_);
97  }
98 
101 
106  std::ostream&
107  print(const spot::const_parsed_aut_ptr& haut,
108  const spot::const_twa_graph_ptr& aut,
109  spot::formula f,
110  const char* filename, int loc, double run_time)
111  {
112  filename_ = filename ? filename : "";
113  if (loc >= 0 && has('L'))
114  {
115  std::ostringstream os;
116  os << loc;
117  location_ = os.str();
118  }
119  if (haut)
120  {
121  if (loc < 0 && has('L'))
122  {
123  std::ostringstream os;
124  os << haut->loc;
125  location_ = os.str();
126  }
127 
128  if (has('T'))
129  {
131  haut_states_ = s.states;
132  haut_edges_ = s.edges;
133  haut_trans_ = s.transitions;
134  }
135  else if (has('E'))
136  {
138  haut_states_ = s.states;
139  haut_edges_ = s.edges;
140  }
141  if (has('M'))
142  {
143  auto n = haut->aut->get_named_prop<std::string>("automaton-name");
144  if (n)
145  haut_name_ = *n;
146  else
147  haut_name_.val().clear();
148  }
149  if (has('S'))
150  haut_states_ = haut->aut->num_states();
151 
152  if (has('A'))
153  haut_acc_ = haut->aut->acc().num_sets();
154 
155  if (has('C'))
156  haut_scc_ = spot::scc_info(haut->aut).scc_count();
157 
158  if (has('G'))
159  {
160  std::ostringstream os;
161  os << haut->aut->get_acceptance();
162  haut_gen_acc_ = os.str();
163  }
164  }
165 
166  if (has('m'))
167  {
168  auto n = aut->get_named_prop<std::string>("automaton-name");
169  if (n)
170  aut_name_ = *n;
171  else
172  aut_name_.val().clear();
173  }
174  if (has('w'))
175  {
176  auto res = spot::couvreur99(aut)->check();
177  if (res)
178  {
179  auto run = res->accepting_run();
180  assert(run);
181  spot::twa_word w(run->reduce());
182  w.simplify();
183  std::ostringstream out;
184  out << w;
185  aut_word_ = out.str();
186  }
187  else
188  {
189  aut_word_.val().clear();
190  }
191  }
192 
193  return this->spot::stat_printer::print(aut, f, run_time);
194  }
195 
196 private:
203  spot::printable_value<unsigned> haut_states_;
208 };
209 
210 
212 {
213  hoa_stat_printer statistics;
214  std::ostringstream name;
215  hoa_stat_printer namer;
216  std::ostringstream outputname;
217  hoa_stat_printer outputnamer;
218  std::map<std::string, std::unique_ptr<output_file>> outputfiles;
219 
220 public:
221 
222  automaton_printer(stat_style input = no_input);
223 
224  void
225  print(const spot::twa_graph_ptr& aut,
226  spot::formula f = nullptr,
227  // Input location for errors and statistics.
228  const char* filename = nullptr,
229  int loc = -1,
230  // Time and input automaton for statistics
231  double time = 0.0,
232  const spot::const_parsed_aut_ptr& haut = nullptr);
233 
234  void add_stat(char c, const spot::printable* p);
235 };
Definition: sccinfo.hh:27
twa_sub_statistics sub_stats_reachable(const const_twa_ptr &g)
Compute sub statistics for an automaton.
void set_output(std::ostream &output)
Remember where to output any string.
Definition: formater.hh:163
An infinite word stored as a lasso.
Definition: word.hh:29
Main class for temporal logic formula.
Definition: formula.hh:578
void declare(char c, const printable *f)
Declare a callback function for c.
Definition: formater.hh:156
std::ostream & print(const const_twa_graph_ptr &aut, formula f=nullptr, double run_time=-1.)
print the configured statistics.
std::ostream & format(const char *fmt)
Expand the %-sequences in fmt, write the result on output_.
emptiness_check_ptr couvreur99(const const_twa_ptr &a, option_map options=option_map())
Check whether the language of an automate is empty.
prints various statistics about a TGBA
Definition: stats.hh:77
Definition: formater.hh:29
std::ostream & print(const spot::const_parsed_aut_ptr &haut, const spot::const_twa_graph_ptr &aut, spot::formula f, const char *filename, int loc, double run_time)
print the configured statistics.
Definition: common_aoutput.hh:107
prints various statistics about a TGBA
Definition: common_aoutput.hh:74
bool has(char c) const
Whether c occurred in the primed formats.
Definition: formater.hh:149
Definition: stats.hh:44
Definition: common_aoutput.hh:211

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Fri Dec 4 2015 07:31:52 for spot by doxygen 1.8.8