X-Git-Url: http://47.100.26.94:8080/?a=blobdiff_plain;f=src%2Fhungarian.cpp;h=e8f49e3a83aa45836cce9c6848384a2a6cc8e378;hb=b5f0328f4054d19fcf8a6b870d5448be8087d29c;hp=9b46613d0738a9ce871dddd20f6400bfdf7daf09;hpb=3811d034ba9e1f44a2e9915289438db3807217fe;p=trackerpp.git diff --git a/src/hungarian.cpp b/src/hungarian.cpp index 9b46613..e8f49e3 100644 --- a/src/hungarian.cpp +++ b/src/hungarian.cpp @@ -57,6 +57,11 @@ int linear_sum_assignment(const MatrixXi& cost_matrix, VectorXi& row_ind, Vector { // The algorithm expects more columns than rows in the cost matrix. MatrixXi correct_matrix = cost_matrix; + if (cost_matrix.cols() == 0 || cost_matrix.rows() == 0){ + row_ind = VectorXi::Zero(0); + col_ind = VectorXi::Zero(0); + return 0; + } bool is_transposed = false; if (cost_matrix.cols() < cost_matrix.rows()){ cout << "cols < rows, transpose." << endl; @@ -302,35 +307,14 @@ int step_six(Hungary& state) return 4; } -/* -int main() +//////////////////////////////////////////////////////////////////////////////// +double distance_cosine(const VectorXd& u, const VectorXd& v) { - Matrix3i C; -// MatrixXi C2(4, 3); -// - C << 1, 2, 3, - 2, 4, 2, - 3, 6, 9; - - Matrix3i M; - M << 0, 1, 2, - 0, 0, 0, - 1, 0, 0; - -// C2 << 4, 1, 3, -// 2, 4, 2, -// 3, 6, 9, -// 2, 6, 3; - - Vector3i vv; - //Matrix3i m1 = (M.array() == 1).select(0, MatrixXi::Ones(M.cols(), M.rows())); - //cout << m1.colwise().sum().transpose() << endl; - //vv = vv.rowwise() - - VectorXi row_ind, col_ind; + return (1 - u.dot(v) / std::sqrt(u.dot(u) * v.dot(v))); +} - //MatrixXi RR = MatrixXi::Random(10, 10); - linear_sum_assignment(C, row_ind, col_ind); - cout << "row: [" << row_ind.transpose() << "], col: [" << col_ind.transpose() << "]" << endl; +double distance_euclidean(const VectorXd& u, const VectorXd& v) +{ + VectorXd d = u - v; + return std::sqrt(d.dot(d)); } -*/