LearnTA  0.0.1
experiment_runner.hh
1 
6 #pragma once
7 
8 #include <boost/log/trivial.hpp>
9 #include <boost/log/core.hpp>
10 #include <boost/log/expressions.hpp>
11 #include <utility>
12 
13 #include "timed_automaton.hh"
14 #include "sul.hh"
15 #include "timed_automaton_runner.hh"
16 #include "symbolic_membership_oracle.hh"
17 #include "equivalence_oracle_by_test.hh"
18 #include "timed_automata_equivalence_oracle.hh"
19 #include "learner.hh"
20 #include "equivalance_oracle_chain.hh"
21 #include "equivalence_oracle_memo.hh"
22 
23 namespace learnta {
24 
26  private:
27  const std::vector<Alphabet> alphabet;
28  TimedAutomaton target;
29  std::vector<TimedWord> testWords;
30  public:
31 
32  void pushTestWord(const TimedWord& testWord) {
33  testWords.push_back(testWord);
34  }
35 
36  ExperimentRunner(std::vector<Alphabet> alphabet, TimedAutomaton target) : alphabet(std::move(alphabet)), target(std::move(target)) {}
37 
41  void run() const {
42  BOOST_LOG_TRIVIAL(info) << "Target DTA\n" << this->target;
43  TimedAutomaton complement = this->target.complement(this->alphabet);
44  complement.simplifyStrong();
45  complement.simplifyWithZones();
46  BOOST_LOG_TRIVIAL(info) << "Complement of the target DTA\n" << complement;
47 
48  // Construct the learner
49  auto sul = std::unique_ptr<learnta::SUL>(new learnta::TimedAutomatonRunner(this->target));
50  auto memOracle = std::make_unique<learnta::SymbolicMembershipOracle>(std::move(sul));
51  auto eqOracle = std::make_unique<learnta::EquivalenceOracleChain>();
52  auto eqOracleByTest = std::make_unique<learnta::EquivalenceOracleByTest>(this->target);
53  // Equivalence query by static string to make the evaluation stable
54  // These strings are generated in macOS but the equivalence query returns a different set of counter examples.
55  // This deviation is probably because of the difference in the address handling, which is used in sorting.
56  for (const auto& testWord: this->testWords) {
57  eqOracleByTest->push_back(testWord);
58  }
59 
60  eqOracle->push_back(std::move(eqOracleByTest));
61  eqOracle->push_back(
62  std::make_unique<learnta::ComplementTimedAutomataEquivalenceOracle>(
63  this->target, complement, alphabet));
64  learnta::Learner learner{alphabet, std::move(memOracle),
65  std::make_unique<learnta::EquivalenceOracleMemo>(std::move(eqOracle), this->target)};
66 
67  // Run the learning
68  BOOST_LOG_TRIVIAL(info) << "Start Learning!!";
69  const auto startTime = std::chrono::system_clock::now(); // Current time
70  const auto hypothesis = learner.run();
71  const auto endTime = std::chrono::system_clock::now(); // End time
72 
73  BOOST_LOG_TRIVIAL(info) << "Learning Finished!!";
74  BOOST_LOG_TRIVIAL(info) << "The learned DTA is as follows\n" << hypothesis;
75  learner.printStatistics(std::cout);
76  BOOST_LOG_TRIVIAL(info) << "Execution Time: "
77  << std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count()
78  << " [ms]";
79  }
80  };
81 }
Definition: experiment_runner.hh:25
void run() const
Execute the experiment.
Definition: experiment_runner.hh:41
The deterministic timed automata learner.
Definition: learner.hh:18
Class to execute a timed automaton.
Definition: timed_automaton_runner.hh:22
A timed word.
Definition: timed_word.hh:25
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
TimedAutomaton complement(const std::vector< Alphabet > &alphabet) const
Take the complement of this timed automaton.
Definition: timed_automaton.hh:261