hungarian.h
Go to the documentation of this file.
00001 /********************************************************************
00002  ********************************************************************
00003  ** C++ class implementation of the Hungarian algorithm by David Schwarz, 2012
00004  **
00005  **
00006  ** O(n^3) implementation derived from libhungarian by Cyrill Stachniss, 2004
00007  **
00008  **
00009  ** Solving the Minimum Assignment Problem using the 
00010  ** Hungarian Method.
00011  **
00012  ** ** This file may be freely copied and distributed! **
00013  **
00014  **
00015  ** This file is distributed in the hope that it will be useful,
00016  ** but WITHOUT ANY WARRANTY; without even the implied 
00017  ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00018  ** PURPOSE.  
00019  **
00020  ********************************************************************
00021  ********************************************************************/
00022 #ifndef HUNGARIAN_H
00023 #define HUNGARIAN_H
00024 
00025 #include <iostream>
00026 #include <vector>
00027 
00028 using std::vector;
00029 
00030 typedef enum {
00031         HUNGARIAN_MODE_MINIMIZE_COST,
00032         HUNGARIAN_MODE_MAXIMIZE_UTIL,
00033 } MODE;
00034 
00035 typedef enum {
00036         HUNGARIAN_NOT_ASSIGNED,
00037         HUNGARIAN_ASSIGNED,
00038 } ASSIGN;
00039 
00040 
00041 class Hungarian
00042 {
00043 
00044 public:
00049         Hungarian();
00050         Hungarian(const vector<vector<int> >&, int, int, MODE);
00051 
00052         int init(const vector<vector<int> >& input_matrix, 
00053                            int rows, 
00054                            int cols, 
00055                            MODE mode);
00056 
00058         bool solve();
00059 
00061         int cost() const;
00062 
00064         const vector<vector<int> >& assignment() const;
00065 
00067         void print_assignment();
00068 
00070         void print_cost();
00071 
00073         void print_status();
00074 
00075 protected:
00076         bool check_solution(const vector<int>& row_dec, const vector<int>& col_inc, const vector<int>& col_vertex);
00077         bool assign_solution(const vector<int>& row_dec, const vector<int>& col_inc, const vector<int>& col_vertex);
00078 
00079 private:
00080 
00081         int m_cost;
00082         int m_rows;
00083         int m_cols;
00084         vector<vector<int> > m_costmatrix;
00085         vector<vector<int> > m_assignment;   
00086 
00087 };
00088 
00089 #endif
00090 
00091 
00092 


explorer
Author(s): Daniel Neuhold , Torsten Andre
autogenerated on Thu Jun 6 2019 20:59:53