Limi
results.h
1 /*
2  * Copyright 2016, IST Austria
3  *
4  * This file is part of Limi.
5  *
6  * Limi is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser 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  * Limi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with Limi. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIMI_RESULTS_H
21 #define LIMI_RESULTS_H
22 
23 #include <unordered_set>
24 #include <list>
25 #include <algorithm>
26 #include "generics.h"
27 
28 namespace Limi {
29 
40 template<class Symbol>
42  Symbol current;
43  std::shared_ptr<counterexample_chain> parent;
44 
45  counterexample_chain(const Symbol& current, const std::shared_ptr<counterexample_chain>& parent) :
46  current(current), parent(parent) { }
47 
48  std::list<Symbol> to_list() const {
49  std::list<Symbol> result;
50  const counterexample_chain* c = this;
51  while (c) {
52  result.push_front(c->current);
53  c = c->parent.get();
54  }
55  return result;
56  }
57 
58  std::vector<Symbol> to_vector() const {
59  std::vector<Symbol> result;
60  const counterexample_chain* c = this;
61  while (c) {
62  result.push_back(c->current);
63  c = c->parent.get();
64  }
65  std::reverse(result.begin(), result.end());
66  return result;
67  }
68 
69 private:
70 };
71 
72 
77 template <class Symbol>
86  bool included = false;
96  bool bound_hit = false;
106  std::vector<Symbol> counter_example;
107 
118  void filter_trace(std::function<bool(Symbol)> to_remove) {
119  counter_example.erase( std::remove_if(counter_example.begin(), counter_example.end(), to_remove), std::end(counter_example));
120  }
121 
128  unsigned max_bound = 0;
129 
136  void print_long(std::ostream& stream, const printer_base<Symbol>& symbol_printer) {
137  if (included)
138  stream << "Included" << std::endl;
139  else {
140  stream << "Not Included";
141  if (bound_hit) stream << "; bound";
142  stream << std::endl;
143  for (const auto& s : counter_example) {
144  stream << symbol_printer(s);
145  //s.symbol->instr_id->printPretty(lout, nullptr, pp);
146  stream << std::endl;
147  }
148  }
149  }
150 };
151 
152 
153 }
154 
155 #endif //LIMI_RESULTS_H
The main namespace of the library.
Definition: antichain_algo.h:40
The result of the language inclusion test.
Definition: results.h:78
Represents a list of symbols.
Definition: results.h:41
unsigned max_bound
The maximum bound used to obtain this inclusion result.
Definition: results.h:128
std::vector< Symbol > counter_example
A counter-example if applicable.
Definition: results.h:106
void filter_trace(std::function< bool(Symbol)> to_remove)
Filters the result trace.
Definition: results.h:118
bool included
True if automaton A is included in automaton B.
Definition: results.h:86
bool bound_hit
Was the bound hit during automata exploration.
Definition: results.h:96
void print_long(std::ostream &stream, const printer_base< Symbol > &symbol_printer)
Print this result.
Definition: results.h:136