Apollo 11.0
自动驾驶开放平台
dst_evidence.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16#pragma once
17
18#include <map>
19#include <mutex>
20#include <string>
21#include <utility>
22#include <vector>
23
24namespace apollo {
25namespace perception {
26namespace fusion {
27
29 // ensure initialize DSTEvidence once
30 bool init_ = false;
31 // fods
32 size_t fod_loc_ = 0;
33 std::vector<uint64_t> fod_subsets_;
34 // for transforming to probability effectively
35 std::vector<size_t> fod_subset_cardinalities_;
36 std::vector<std::string> fod_subset_names_;
37 // for combining two bbas effectively.
38 std::vector<std::vector<std::pair<size_t, size_t>>> combination_relations_;
39 // for computing support vector effectively
40 std::vector<std::vector<size_t>> subset_relations_;
41 // for computing plausibility vector effectively
42 std::vector<std::vector<size_t>> inter_relations_;
43 std::map<uint64_t, size_t> subsets_ind_map_;
44};
45
47
48// @brief: A singleton class to mange the set of fod subset and the
49// intersection relationship between them.
51 public:
52 static DstManager* Instance() {
53 static DstManager dst_manager;
54 return &dst_manager;
55 }
56
57 // brief: app initialization
58 // param [in]: app_name
59 // param [in]: fod_subsets, hypotheses sets
60 // param [in]: fod_subset_names
61 bool AddApp(const std::string& app_name,
62 const std::vector<uint64_t>& fod_subsets,
63 const std::vector<std::string>& fod_subset_names =
64 std::vector<std::string>());
65
73 bool IsAppAdded(const std::string& app_name);
74
81 DstCommonDataPtr GetAppDataPtr(const std::string& app_name);
82
90 size_t FodSubsetToInd(const std::string& app_name,
91 const uint64_t& fod_subset);
92
100 uint64_t IndToFodSubset(const std::string& app_name, const size_t& ind);
101
102 private:
103 DstManager() {}
104
110 void BuildSubsetsIndMap(DstCommonData* dst_data);
111
117 void FodCheck(DstCommonData* dst_data);
118
124 void ComputeCardinalities(DstCommonData* st_data);
125
133 bool ComputeRelations(DstCommonData* dst_data);
134
141 void BuildNamesMap(const std::vector<std::string>& fod_subset_names,
142 DstCommonData* dst_data);
143
144 private:
145 // Dst data map
146 std::map<std::string, DstCommonData> dst_common_data_;
147
148 std::mutex map_mutex_;
149};
150
151class Dst {
152 public:
153 explicit Dst(const std::string& app_name);
154
162 bool SetBbaVec(const std::vector<double>& bba_vec);
163
171 bool SetBba(const std::map<uint64_t, double>& bba_map);
172
177 void ComputeSptPlsUct() const;
178
183 void ComputeProbability() const;
184
190 const std::vector<double>& GetBbaVec() const { return bba_vec_; }
191
197 const size_t GetBbaSize() const { return bba_vec_.size(); }
198
205 double GetSubsetBfmass(uint64_t fod_subset) const;
206
213 double GetIndBfmass(size_t ind) const;
214
220 const std::vector<double>& GetSupportVec() const { return support_vec_; }
221
227 const std::vector<double>& GetPlausibilityVec() const {
228 return plausibility_vec_;
229 }
230
236 const std::vector<double>& GetUncertaintyVec() const {
237 return uncertainty_vec_;
238 }
239
245 const std::vector<double>& GetProbabilityVec() const {
246 return probability_vec_;
247 }
248
254 std::string PrintBba() const;
255
263 friend Dst operator+(const Dst& lhs, const Dst& rhs);
264
272 friend Dst operator*(const Dst& dst_evidence, double w);
273
279 std::string Name() const { return app_name_; }
280
281 private:
286 void Normalize();
287
292 void SelfCheck() const;
293
294 private:
295 std::string app_name_;
296 // the construction of following vectors is manual.
297 mutable DstCommonDataPtr dst_data_ptr_ = nullptr;
298 mutable std::vector<double> bba_vec_;
299 mutable std::vector<double> support_vec_;
300 mutable std::vector<double> plausibility_vec_;
301 mutable std::vector<double> uncertainty_vec_;
302 mutable std::vector<double> probability_vec_;
303};
304
305} // namespace fusion
306} // namespace perception
307} // namespace apollo
uint64_t IndToFodSubset(const std::string &app_name, const size_t &ind)
DstCommonDataPtr GetAppDataPtr(const std::string &app_name)
Get the app data ptr object
bool IsAppAdded(const std::string &app_name)
Whether app added
size_t FodSubsetToInd(const std::string &app_name, const uint64_t &fod_subset)
bool AddApp(const std::string &app_name, const std::vector< uint64_t > &fod_subsets, const std::vector< std::string > &fod_subset_names=std::vector< std::string >())
const std::vector< double > & GetUncertaintyVec() const
Get the Uncertainty Vec object
const size_t GetBbaSize() const
Get the Bba Size object
const std::vector< double > & GetSupportVec() const
Get the Support Vec object
const std::vector< double > & GetProbabilityVec() const
Get the Probability Vec object
double GetIndBfmass(size_t ind) const
Get the Ind Bfmass object
const std::vector< double > & GetPlausibilityVec() const
Get the Plausibility Vec object
friend Dst operator*(const Dst &dst_evidence, double w)
double GetSubsetBfmass(uint64_t fod_subset) const
Get the Subset Bfmass object
friend Dst operator+(const Dst &lhs, const Dst &rhs)
bool SetBbaVec(const std::vector< double > &bba_vec)
Set the Bba Vec object
bool SetBba(const std::map< uint64_t, double > &bba_map)
Set the Bba object, strictly require the fod in bba_map is valid
const std::vector< double > & GetBbaVec() const
Get the Bba Vec object
DstCommonData * DstCommonDataPtr
class register implement
Definition arena_queue.h:37
std::vector< size_t > fod_subset_cardinalities_
std::vector< std::vector< std::pair< size_t, size_t > > > combination_relations_
std::vector< std::vector< size_t > > subset_relations_
std::vector< std::string > fod_subset_names_
std::vector< std::vector< size_t > > inter_relations_
std::map< uint64_t, size_t > subsets_ind_map_