LearnTA  0.0.1
internal_transition_maker.hh
1 
6 #pragma once
7 
8 #include <utility>
9 #include <memory>
10 
11 #include <boost/unordered_map.hpp>
12 #include <boost/log/trivial.hpp>
13 #include <boost/log/core.hpp>
14 #include <boost/log/expressions.hpp>
15 
16 #include "timed_automaton.hh"
17 #include "renaming_relation.hh"
18 #include "timed_condition_set.hh"
19 
20 namespace learnta {
25  private:
26  // TargetTAState -> SourceTimedCondition
27  boost::unordered_map<std::shared_ptr<TAState>, TimedConditionSet> sourceMap;
28 
29  public:
36  void add(const std::shared_ptr<TAState> &targetState, const TimedCondition &sourceCondition) {
37  BOOST_LOG_TRIVIAL(trace) << "sourceCondition: " << sourceCondition;
38 
39  auto it = sourceMap.find(targetState);
40  if (it == sourceMap.end()) {
41  sourceMap[targetState] = TimedConditionSet{sourceCondition};
42  } else {
43 /* // TODO: Implement state merging for optimization
44  // When there is a transition to targetState, we try to merge the timedCondition
45  if (predecessorSourceCondition && !sourceExternalConditionOpt) {
46  auto jt = std::find_if(it->second.begin(), it->second.end(),
47  [&] (const auto &condition) {
48  return condition.includes(*predecessorSourceCondition);
49  });
50  if (jt != it->second.end()) {
51  jt->convexHullAssign(sourceCondition);
52  } else {
53  it->second.push_back(sourceCondition);
54  }
55  } else {*/
56  it->second.push_back(sourceCondition);
57  //}
58  }
59  }
60 
64  [[nodiscard]] std::vector<TATransition> make() const {
65  std::vector<TATransition> result;
66  result.reserve(sourceMap.size());
67 
68  for (const auto &[target, sourceConditions]: sourceMap) {
69  for (const auto &sourceCondition: sourceConditions.getConditions()) {
70  // Generate transitions
71  // We only have to refresh the new variable
72  const TATransition::Resets resets{std::make_pair(sourceCondition.size(), 0.0)};
73  result.emplace_back(target.get(), resets, sourceCondition.toGuard());
74  }
75  }
76 
77  return result;
78  }
79 
80  [[nodiscard]] bool empty() const {
81  return this->sourceMap.empty();
82  }
83 
84  [[nodiscard]] std::size_t size() const {
85  return this->sourceMap.size();
86  }
87  };
88 }
A class to make a transition from P to P.
Definition: internal_transition_maker.hh:24
void add(const std::shared_ptr< TAState > &targetState, const TimedCondition &sourceCondition)
Add a transition to targetState.
Definition: internal_transition_maker.hh:36
std::vector< TATransition > make() const
Generate transitions.
Definition: internal_transition_maker.hh:64
A set of timed conditions to represent non-convex constraints.
Definition: timed_condition_set.hh:18
A timed condition, a finite conjunction of inequalities of the form , where and .
Definition: timed_condition.hh:19
Definition: experiment_runner.hh:23