Apollo 10.0
自动驾驶开放平台
gnn_bipartite_graph_matcher.cc
浏览该文件的文档.
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
18
19#include <algorithm>
20#include <utility>
21
22#include "cyber/common/log.h"
23
24namespace apollo {
25namespace perception {
26namespace lidar {
27
28MatchCost::MatchCost(size_t ridx, size_t cidx, double cost)
29 : row_idx_(ridx), col_idx_(cidx), cost_(cost) {}
30
31size_t MatchCost::RowIdx() const { return row_idx_; }
32
33size_t MatchCost::ColIdx() const { return col_idx_; }
34
35double MatchCost::Cost() const { return cost_; }
36
37bool operator<(const MatchCost& m1, const MatchCost& m2) {
38 return m1.cost_ < m2.cost_;
39}
40
41std::ostream& operator<<(std::ostream& os, const MatchCost& m) {
42 os << "MatchCost ridx:" << m.RowIdx() << " cidx:" << m.ColIdx()
43 << " Cost:" << m.Cost();
44 return os;
45}
46
48 row_tag_.reserve(max_size);
49 col_tag_.reserve(max_size);
51}
52
58
60 const BipartiteGraphMatcherOptions& options,
61 std::vector<NodeNodePair>* assignments,
62 std::vector<size_t>* unassigned_rows,
63 std::vector<size_t>* unassigned_cols) {
64 assignments->clear();
65 unassigned_rows->clear();
66 unassigned_cols->clear();
67 row_tag_.clear();
68 col_tag_.clear();
69 ignore_track_.clear();
71 float max_dist = options.cost_thresh;
72 int num_rows = static_cast<int>(cost_matrix->height());
73 int num_cols = static_cast<int>(cost_matrix->width());
74 row_tag_.assign(num_rows, 0);
75 col_tag_.assign(num_cols, 0);
76 ignore_track_.assign(num_rows, 0);
77
78 std::vector<MatchCost> match_costs;
79 for (int r = 0; r < num_rows; r++) {
80 for (int c = 0; c < num_cols; c++) {
81 if ((*cost_matrix)(r, c) < max_dist) {
82 MatchCost item(r, c, (*cost_matrix)(r, c));
83 match_costs.push_back(item);
84 }
85 }
86 }
87
88 // sort costs in ascending order
89 std::sort(match_costs.begin(), match_costs.end());
90
91 // gnn
92 for (size_t i = 0; i < match_costs.size(); ++i) {
93 size_t rid = match_costs[i].RowIdx();
94 size_t cid = match_costs[i].ColIdx();
95 // if (row_tag_[rid] == 0 && col_tag_[cid] == 0) {
96 // row_tag_[rid] = 1;
97 // col_tag_[cid] = 1;
98 // assignments->push_back(std::make_pair(rid, cid));
99 // }
100 if (row_tag_[rid] == 0 && col_tag_[cid] == 0 && ignore_track_[rid] <= 1) {
101 row_tag_[rid] = 1;
102 col_tag_[cid] = 1;
103 assignments->push_back(std::make_pair(rid, cid));
104 } else if (row_tag_[rid] == 0 && col_tag_[cid] != 0) {
105 ignore_track_[rid]++;
106 }
107 }
108
109 for (int i = 0; i < num_rows; i++) {
110 if (row_tag_[i] == 0) {
111 unassigned_rows->push_back(i);
112 }
113 }
114
115 for (int i = 0; i < num_cols; i++) {
116 if (col_tag_[i] == 0) {
117 unassigned_cols->push_back(i);
118 }
119 }
120}
121
123
124} // namespace lidar
125} // namespace perception
126} // namespace apollo
virtual algorithm::SecureMat< float > * cost_matrix()
Get cost matrix
void Match(const BipartiteGraphMatcherOptions &options, std::vector< NodeNodePair > *assignments, std::vector< size_t > *unassigned_rows, std::vector< size_t > *unassigned_cols)
Match interface
MatchCost(size_t ridx, size_t cidx, double cost)
#define PERCEPTION_REGISTER_BIPARTITEGRAPHMATCHER(name)
bool operator<(const MatchCost &m1, const MatchCost &m2)
std::ostream & operator<<(std::ostream &os, const MatchCost &m)
class register implement
Definition arena_queue.h:37