LearnTA  0.0.1
timed_automata_equivalence_oracle.hh
1 
6 #pragma once
7 
8 #include "equivalence_oracle.hh"
9 #include "intersection.hh"
10 #include "ta2za.hh"
11 #include "timed_automaton_runner.hh"
12 
13 #include <utility>
14 
15 namespace learnta {
22  private:
23  TimedAutomaton target;
24  TimedAutomaton complement;
25  std::vector<Alphabet> alphabet;
26 
30  [[nodiscard]] std::optional<TimedWord> subset(TimedAutomaton hypothesis) const {
31  TimedAutomaton intersection;
32  boost::unordered_map<std::pair<TAState *, TAState *>, std::shared_ptr<TAState>> toIState;
33  BOOST_LOG_TRIVIAL(debug) << "subset: hypothesis\n" << hypothesis;
34  intersectionTA(complement, hypothesis, intersection, toIState);
35  ZoneAutomaton zoneAutomaton;
36  intersection.simplifyStrong();
37  // This is a quick fix for the urgent semantics of the unobservable transitions
38  intersection.addUpperBoundForUnobservableTransitions();
39  BOOST_LOG_TRIVIAL(debug) << "subset: before ta2za";
40  BOOST_LOG_TRIVIAL(debug) << "Number of states: " << intersection.stateSize();
41  BOOST_LOG_TRIVIAL(debug) << "Number of clock: " << intersection.clockSize();
42  ta2za(intersection, zoneAutomaton);
43  BOOST_LOG_TRIVIAL(debug) << "subset: after ta2za";
44 
45  return zoneAutomaton.sampleWithMemo();
46  }
47 
51  [[nodiscard]] std::optional<TimedWord> superset(const TimedAutomaton& hypothesis) const {
52  TimedAutomaton intersection;
53  boost::unordered_map<std::pair<TAState *, TAState *>, std::shared_ptr<TAState>> toIState;
54  const auto complementedHypothesis = hypothesis.complement(this->alphabet);
55  BOOST_LOG_TRIVIAL(debug) << "superset: complemented hypothesis\n" << complementedHypothesis;
56  intersectionTA(target, complementedHypothesis, intersection, toIState);
57  ZoneAutomaton zoneAutomaton;
58  intersection.simplifyStrong();
59  // This is a quick fix for the urgent semantics of the unobservable transitions
60  intersection.addUpperBoundForUnobservableTransitions();
61  BOOST_LOG_TRIVIAL(debug) << "superset: before ta2za";
62  BOOST_LOG_TRIVIAL(debug) << "Number of states: " << intersection.stateSize();
63  BOOST_LOG_TRIVIAL(debug) << "Number of clock: " << intersection.clockSize();
64  ta2za(intersection.simplify(), zoneAutomaton);
65  BOOST_LOG_TRIVIAL(debug) << "superset: after ta2za";
66 
67  return zoneAutomaton.sampleWithMemo();
68  }
69 
70  public:
75  std::vector<Alphabet> alphabet) : target(std::move(target)),
76  complement(std::move(complement)),
77  alphabet(std::move(alphabet)) {
78  BOOST_LOG_TRIVIAL(debug) << "Target DTA: \n" << this->target;
79  BOOST_LOG_TRIVIAL(debug) << "Complemented target DTA: \n" << this->complement;
80  }
81 
85  [[nodiscard]] std::optional<TimedWord> findCounterExample(const TimedAutomaton &hypothesis) override {
86  ++eqQueryCount;
87  auto subCounterExample = subset(hypothesis);
88  if (subCounterExample) {
89  // Confirm that the generated counterexample is really a counterexample
90  TimedAutomatonRunner targetRunner{this->target};
91  TimedAutomatonRunner hypothesisRunner{hypothesis};
92  targetRunner.pre();
93  hypothesisRunner.pre();
94  for (std::size_t i = 0; i < subCounterExample->wordSize(); ++i) {
95  targetRunner.step(subCounterExample->getDurations().at(i));
96  hypothesisRunner.step(subCounterExample->getDurations().at(i));
97  targetRunner.step(subCounterExample->getWord().at(i));
98  hypothesisRunner.step(subCounterExample->getWord().at(i));
99 
100  }
101  assert(targetRunner.step(subCounterExample->getDurations().back()) != hypothesisRunner.step(subCounterExample->getDurations().back()));
102  targetRunner.post();
103  hypothesisRunner.post();
104 
105  return subCounterExample;
106  }
107  auto supCounterExample = superset(hypothesis);
108  if (supCounterExample) {
109  // Confirm that the generated counterexample is really a counterexample
110  TimedAutomatonRunner targetRunner{this->target};
111  TimedAutomatonRunner hypothesisRunner{hypothesis};
112  targetRunner.pre();
113  hypothesisRunner.pre();
114  for (std::size_t i = 0; i < supCounterExample->wordSize(); ++i) {
115  targetRunner.step(supCounterExample->getDurations().at(i));
116  hypothesisRunner.step(supCounterExample->getDurations().at(i));
117  targetRunner.step(supCounterExample->getWord().at(i));
118  hypothesisRunner.step(supCounterExample->getWord().at(i));
119  }
120  assert(targetRunner.step(supCounterExample->getDurations().back()) != hypothesisRunner.step(supCounterExample->getDurations().back()));
121  targetRunner.post();
122  hypothesisRunner.post();
123  }
124 
125  return supCounterExample;
126  }
127  };
128 }
Equivalence oracle with a timed automaton recognizing the complement of the target language.
Definition: timed_automata_equivalence_oracle.hh:21
std::optional< TimedWord > findCounterExample(const TimedAutomaton &hypothesis) override
Make an equivalence query.
Definition: timed_automata_equivalence_oracle.hh:85
ComplementTimedAutomataEquivalenceOracle(TimedAutomaton target, TimedAutomaton complement, std::vector< Alphabet > alphabet)
Definition: timed_automata_equivalence_oracle.hh:74
Interface of the equivalence oracle.
Definition: equivalence_oracle.hh:17
Class to execute a timed automaton.
Definition: timed_automaton_runner.hh:22
Definition: experiment_runner.hh:23
void ta2za(const TimedAutomaton &TA, ZoneAutomaton &ZA, bool quickReturn=true)
Generate a zone automaton from a timed automaton.
Definition: ta2za.cc:15
Definition: external_transition_maker.hh:149
std::size_t stateSize() const
Returns the number of the states.
Definition: common_types.hh:27
A timed automaton.
Definition: timed_automaton.hh:213
size_t clockSize() const
Returns the number of clock variables used in the timed automaton.
Definition: timed_automaton.hh:252
TimedAutomaton simplify()
Simplify the timed automaton.
Definition: timed_automaton.hh:600
TimedAutomaton simplifyStrong()
Simplify the timed automaton.
Definition: timed_automaton.hh:613
TimedAutomaton complement(const std::vector< Alphabet > &alphabet) const
Take the complement of this timed automaton.
Definition: timed_automaton.hh:261
A Zone automaton.
Definition: zone_automaton.hh:17