Apollo 11.0
自动驾驶开放平台
gnn_bipartite_graph_matcher.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 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 radar4d {
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();
70 float max_dist = options.cost_thresh;
71 int num_rows = static_cast<int>(cost_matrix->height());
72 int num_cols = static_cast<int>(cost_matrix->width());
73 row_tag_.assign(num_rows, 0);
74 col_tag_.assign(num_cols, 0);
75
76 std::vector<MatchCost> match_costs;
77 for (int r = 0; r < num_rows; r++) {
78 for (int c = 0; c < num_cols; c++) {
79 if ((*cost_matrix)(r, c) < max_dist) {
80 MatchCost item(r, c, (*cost_matrix)(r, c));
81 match_costs.push_back(item);
82 }
83 }
84 }
85
86 // sort costs in ascending order
87 std::sort(match_costs.begin(), match_costs.end());
88
89 // gnn
90 for (size_t i = 0; i < match_costs.size(); ++i) {
91 size_t rid = match_costs[i].RowIdx();
92 size_t cid = match_costs[i].ColIdx();
93 if (row_tag_[rid] == 0 && col_tag_[cid] == 0) {
94 row_tag_[rid] = 1;
95 col_tag_[cid] = 1;
96 assignments->push_back(std::make_pair(rid, cid));
97 }
98 }
99
100 for (int i = 0; i < num_rows; i++) {
101 if (row_tag_[i] == 0) {
102 unassigned_rows->push_back(i);
103 }
104 }
105
106 for (int i = 0; i < num_cols; i++) {
107 if (col_tag_[i] == 0) {
108 unassigned_cols->push_back(i);
109 }
110 }
111}
112
114
115} // namespace radar4d
116} // namespace perception
117} // 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)
std::ostream & operator<<(std::ostream &os, const MatchCost &m)
bool operator<(const MatchCost &m1, const MatchCost &m2)
class register implement
Definition arena_queue.h:37