#include "match.h" #include #include /** * MATLAB implementation of the hungarian algorithm (2008) * * modified by Henrik Rydberg (2008) */ typedef unsigned short col_t[1]; typedef unsigned short mat_t[DIM_FINGER]; #define GET1(m, x) ((m[0]>>(x))&1U) #define SET1(m, x) (m[0]|=(1U<<(x))) #define CLEAR1(m, x) (m[0]&=~(1U<<(x))) #define GET2(m, row, col) ((m[col]>>(row))&1U) #define SET2(m, row, col) (m[col]|=(1U<<(row))) #define CLEAR2(m, row, col) (m[col]&=~(1U<<(row))) /********************************************************/ static void buildixvector(int *ix, mat_t mstar, int nrows, int ncols) { int row, col; for (row = 0; row < nrows; row++) { for (col = 0; col < ncols; col++) { if (GET2(mstar, row, col)) { ix[row] = col; break; } } } } /********************************************************/ static void step2a(int *ix, float *mdist, mat_t mstar, mat_t nmstar, mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, int dmin); static void step2b(int *ix, float *mdist, mat_t mstar, mat_t nmstar, mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, int dmin); static void step3(int *ix, float *mdist, mat_t mstar, mat_t nmstar, mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, int dmin); static void step4(int *ix, float *mdist, mat_t mstar, mat_t nmstar, mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, int dmin, int row, int col); static void step5(int *ix, float *mdist, mat_t mstar, mat_t nmstar, mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, int dmin); static void ixoptimal(int *ix, float *mdist, int nrows, int ncols) { float *mdistTemp, *mdistEnd, *columnEnd, value, minValue; int dmin, row, col; col_t ccol, crow; mat_t mstar, mprime, nmstar; memset(ccol, 0, sizeof(col_t)); memset(crow, 0, sizeof(col_t)); memset(mstar, 0, sizeof(mat_t)); memset(mprime, 0, sizeof(mat_t)); memset(nmstar, 0, sizeof(mat_t)); /* initialization */ for(row=0; row max) max = A[i]; for (i = 0; i < nrow * ncol; i++) A[i] /= max; ixoptimal(ix, A, nrow, ncol); } ////////////////////////////////////////////////////////