Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <iostream>
00024 #include <vector>
00025
00026 #ifndef HUNGARIAN_H
00027 #define HUNGARIAN_H
00028
00029 using std::vector;
00030
00031 typedef enum {
00032 HUNGARIAN_MODE_MINIMIZE_COST,
00033 HUNGARIAN_MODE_MAXIMIZE_UTIL,
00034 } MODE;
00035
00036 typedef enum {
00037 HUNGARIAN_NOT_ASSIGNED,
00038 HUNGARIAN_ASSIGNED,
00039 } ASSIGN;
00040
00041
00042 class Hungarian
00043 {
00044
00045 public:
00050 Hungarian();
00051 Hungarian(const vector<vector<int> >&, int, int, MODE);
00052
00053 int init(const vector<vector<int> >& input_matrix,
00054 int rows,
00055 int cols,
00056 MODE mode);
00057
00059 bool solve();
00060
00062 int cost() const;
00063
00065 const vector<vector<int> >& assignment() const;
00066
00068 void print_assignment();
00069
00071 void print_cost();
00072
00074 void print_status();
00075
00076 protected:
00077 bool check_solution(const vector<int>& row_dec, const vector<int>& col_inc, const vector<int>& col_vertex);
00078 bool assign_solution(const vector<int>& row_dec, const vector<int>& col_inc, const vector<int>& col_vertex);
00079
00080 private:
00081
00082 int m_cost;
00083 int m_rows;
00084 int m_cols;
00085 vector<vector<int> > m_costmatrix;
00086 vector<vector<int> > m_assignment;
00087
00088 };
00089
00090 #endif
00091
00092
00093