ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
proposition.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2017-2020 German Aerospace Center (DLR).
3  * Eclipse ADORe, Automated Driving Open Research https://eclipse.org/adore
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License 2.0 which is available at
7  * http://www.eclipse.org/legal/epl-2.0.
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  * Daniel Heß - initial implementation and API
13  ********************************************************************************/
14 
15 #pragma once
16 #include <string>
17 #include <unordered_map>
18 
19 namespace adore
20 {
21  namespace env
22  {
26  struct Proposition
27  {
28  unsigned char order_;
29  std::string term_;
30  bool value_;
31  double timeout_;
32  bool has_timeout_;
34  Proposition(std::string term,bool value)
35  :order_(0),term_(term),value_(value),timeout_(0.0),has_timeout_(false){}
36  };
37 
42  {
43  private:
44  std::unordered_map<std::string,Proposition> map_;
45  double t_;
46  public:
51  void setTime(double t)
52  {
53  t_ = t;
54  }
58  void add(const Proposition& p)
59  {
60  map_.emplace(p.term_, p).first->second = p;
61  }
65  bool getValue(const std::string& term,bool default_value)const
66  {
67  auto it = map_.find(term);
68  if(it==map_.end())
69  {
70  return default_value;
71  }
72  else if(it->second.has_timeout_ && it->second.timeout_<t_)
73  {
74  return default_value;
75  }
76  else
77  {
78  return it->second.value_;
79  }
80  }
84  bool hasValue(const std::string& term)const
85  {
86  auto it = map_.find(term);
87  if(it==map_.end())
88  {
89  return false;
90  }
91  else if(it->second.has_timeout_ && it->second.timeout_<t_)
92  {
93  return false;
94  }
95  else
96  {
97  return true;
98  }
99  }
100 
101  };
102 
103 
104  }
105 }
A data structure managing logical propositions of order 0.
Definition: proposition.h:42
void add(const Proposition &p)
insert or update a proposition
Definition: proposition.h:58
void setTime(double t)
update the current time in order to make use of propositions which are defined for a limited time
Definition: proposition.h:51
bool getValue(const std::string &term, bool default_value) const
returns the boolean value of a term, if known. otherwise default_value is returned
Definition: proposition.h:65
bool hasValue(const std::string &term) const
returns true if value of a term is known.
Definition: proposition.h:84
double t_
Definition: proposition.h:45
PropositionSet0()
Definition: proposition.h:47
std::unordered_map< std::string, Proposition > map_
Definition: proposition.h:44
Definition: areaofeffectconverter.h:20
A logical proposition, with a possible timeout for the information.
Definition: proposition.h:27
Proposition(std::string term, bool value)
Definition: proposition.h:34
unsigned char order_
Definition: proposition.h:28
std::string term_
Definition: proposition.h:29
double timeout_
Definition: proposition.h:31
bool has_timeout_
Definition: proposition.h:32
Proposition()
Definition: proposition.h:33
bool value_
Definition: proposition.h:30