LearnTA  0.0.1
equivalence_oracle_by_test.hh
1 
6 #pragma once
7 
8 #include <optional>
9 #include <utility>
10 
11 #include "timed_automaton.hh"
12 #include "timed_word.hh"
13 #include "equivalence_oracle.hh"
14 #include "timed_automaton_runner.hh"
15 
16 namespace learnta {
21  std::vector<TimedWord> words;
22  TimedAutomaton automaton;
23  public:
24  explicit EquivalenceOracleByTest(TimedAutomaton automaton) : automaton(std::move(automaton)) {}
25 
29  [[nodiscard]] std::optional<TimedWord> findCounterExample(const TimedAutomaton &hypothesis) override {
30  ++eqQueryCount;
31  TimedAutomatonRunner runner(automaton);
32  TimedAutomatonRunner hypothesisRunner(hypothesis);
33  for (const auto &word: words) {
34  runner.pre();
35  hypothesisRunner.pre();
36  for (std::size_t i = 0; i < word.wordSize(); ++i) {
37  if (runner.step(word.getDurations().at(i)) != hypothesisRunner.step(word.getDurations().at(i))) {
38  // Minimize the counter example
39  auto cex = TimedWord{word.getWord().substr(0, i),
40  std::vector<double>{word.getDurations().begin(), word.getDurations().begin() + i + 1}};
41  BOOST_LOG_TRIVIAL(debug) << "EquivalenceOracleByTest found a counter example: " << cex;
42  return cex;
43  }
44  if (runner.step(word.getWord().at(i)) != hypothesisRunner.step(word.getWord().at(i))) {
45  // Minimize the counter example
46  auto durations = std::vector<double>{word.getDurations().begin(), word.getDurations().begin() + i + 1};
47  durations.push_back(0);
48  auto cex = TimedWord{word.getWord().substr(0, i + 1), durations};
49  BOOST_LOG_TRIVIAL(debug) << "EquivalenceOracleByTest found a counter example: " << cex;
50  return cex;
51  }
52  }
53  if (runner.step(word.getDurations().at(word.wordSize())) !=
54  hypothesisRunner.step(word.getDurations().at(word.wordSize()))) {
55  BOOST_LOG_TRIVIAL(debug) << "EquivalenceOracleByTest found a counter example: " << word;
56  return word;
57  }
58  }
59 
60  return std::nullopt;
61  }
62 
63  void push_back(TimedWord word) {
64  words.push_back(std::move(word));
65  }
66  };
67 }
Interface of the equivalence oracle.
Definition: equivalence_oracle_by_test.hh:20
std::optional< TimedWord > findCounterExample(const TimedAutomaton &hypothesis) override
Make an equivalence query.
Definition: equivalence_oracle_by_test.hh:29
Interface of the equivalence oracle.
Definition: equivalence_oracle.hh:17
Class to execute a timed automaton.
Definition: timed_automaton_runner.hh:22
bool step(char action) override
Feed a discrete action.
Definition: timed_automaton_runner.hh:80
void pre() override
Reset the configuration.
Definition: timed_automaton_runner.hh:41
A timed word.
Definition: timed_word.hh:25
Definition: experiment_runner.hh:23
A timed automaton.
Definition: timed_automaton.hh:213