LearnTA  0.0.1
learner.hh
1 
6 #pragma once
7 
8 #include <memory>
9 
10 #include "equivalence_oracle.hh"
11 #include "symbolic_membership_oracle.hh"
12 #include "observation_table.hh"
13 
14 namespace learnta {
18  class Learner {
19  private:
20  std::unique_ptr<EquivalenceOracle> eqOracle;
21  ObservationTable observationTable;
22  public:
23  Learner(const std::vector<Alphabet> &alphabet,
24  std::unique_ptr<SymbolicMembershipOracle> memOracle,
25  std::unique_ptr<EquivalenceOracle> eqOracle) : eqOracle(std::move(eqOracle)),
26  observationTable(alphabet, std::move(memOracle)) {}
27 
28  TimedAutomaton run() {
29  while (true) {
30  bool notUpdated;
31  do {
32  notUpdated = observationTable.close();
33  notUpdated = notUpdated && observationTable.consistent();
34  notUpdated = notUpdated && observationTable.exteriorConsistent();
35  notUpdated = notUpdated && observationTable.timeSaturate();
36  // notUpdated = notUpdated && observationTable.renameConsistent();
37  } while (!notUpdated);
38  BOOST_LOG_TRIVIAL(debug) << "Start DTA generation";
39  auto hypothesis = observationTable.generateHypothesis();
40  BOOST_LOG_TRIVIAL(debug) << "Hypothesis before simplification\n" << hypothesis;
41  hypothesis.simplifyStrong();
42  BOOST_LOG_TRIVIAL(debug) << "Hypothesis before zone-based simplification\n" << hypothesis;
43  hypothesis.simplifyWithZones();
44  BOOST_LOG_TRIVIAL(info) << "The learner generated a hypothesis\n" << hypothesis;
45  assert(hypothesis.deterministic());
46  const auto counterExample = eqOracle->findCounterExample(hypothesis);
47 
48  if (counterExample) {
49  BOOST_LOG_TRIVIAL(info) << "Equivalence oracle returned a counter example: " << counterExample.value();
50  observationTable.handleCEX(counterExample.value());
51  } else {
52  return hypothesis;
53  }
54  }
55  }
56 
57  std::ostream &printStatistics(std::ostream &stream) const {
58  this->observationTable.printStatistics(stream);
59  this->eqOracle->printStatistics(stream);
60 
61  return stream;
62  }
63 
64  [[nodiscard]] std::size_t numEqQueries() const {
65  return this->eqOracle->numEqQueries();
66  }
67  };
68 }
The deterministic timed automata learner.
Definition: learner.hh:18
Timed observation table.
Definition: observation_table.hh:43
bool exteriorConsistent()
Make the observation table exterior-consistent.
Definition: observation_table.hh:557
bool timeSaturate()
Make the observation table time-saturated.
Definition: observation_table.hh:594
TimedAutomaton generateHypothesis()
Construct a hypothesis DTA from the current timed observation table.
Definition: observation_table.hh:832
void handleCEX(const TimedWord &cex)
Refine the suffixes by the given counterexample.
Definition: observation_table.hh:717
bool close()
Close the observation table.
Definition: observation_table.hh:317
bool consistent()
Make the observation table consistent.
Definition: observation_table.hh:522
Definition: experiment_runner.hh:23
A timed automaton.
Definition: timed_automaton.hh:213
TimedAutomaton simplifyStrong()
Simplify the timed automaton.
Definition: timed_automaton.hh:613
TimedAutomaton simplifyWithZones()
Simplify the timed automaton.
Definition: timed_automaton.cc:51