Hungarian.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //
  2. // Created by lqx on 20-4-23.
  3. //
  4. #ifndef TRACK_SORT_HUNGARIAN_H_H
  5. #define TRACK_SORT_HUNGARIAN_H_H
  6. #include <iostream>
  7. #include <vector>
  8. using namespace std;
  9. class HungarianAlgorithm
  10. {
  11. public:
  12. HungarianAlgorithm();
  13. ~HungarianAlgorithm();
  14. double Solve(vector<vector<double>>& DistMatrix, vector<int>& Assignment);
  15. private:
  16. void assignmentoptimal(int *assignment, double *cost, double *distMatrix, int nOfRows, int nOfColumns);
  17. void buildassignmentvector(int *assignment, bool *starMatrix, int nOfRows, int nOfColumns);
  18. void computeassignmentcost(int *assignment, double *cost, double *distMatrix, int nOfRows);
  19. void step2a(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix,
  20. bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
  21. void step2b(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix,
  22. bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
  23. void step3(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix,
  24. bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
  25. void step4(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix,
  26. bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim, int row, int col);
  27. void step5(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix,
  28. bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
  29. };
  30. #endif //TRACK_SORT_HUNGARIAN_H_H