00001
00002 #ifndef MUNKRES_H
00003 #define MUNKRES_H
00004
00005 #include <iostream>
00006 #include <vector>
00007 #include <iomanip>
00008 #include <map>
00009
00010
00011
00012
00013 class munkres{
00014 public:
00015 typedef std::vector<double> vec_type;
00016 typedef std::vector<vec_type > matrix_type;
00017 typedef std::pair<int,int> coords;
00018 typedef std::vector<int> result_type;
00019
00020 enum markertype {kStar = 1, kPrime = 2};
00021
00022 munkres(matrix_type costs);
00023 void printcosts(){printmatrix(m_costmatrix);}
00024 result_type run(vec_type& costvector, bool debug = false);
00025
00026 private:
00027 void step_one();
00028 void step_two();
00029 void step_three();
00030 void step_four();
00031 void step_five();
00032 void step_six();
00033
00034 void printmask() {printmatrix(m_maskmatrix);}
00035 void printmatrix(const matrix_type&);
00036
00037 void find_a_zero(int& row,int& col);
00038 int find_in_row(const int row, markertype what);
00039 int find_in_col(const int col, markertype what);
00040 double find_min_uncov();
00041
00042 void augment_path(const std::vector<coords>& path);
00043 void erase_primes_and_covers();
00044
00045 matrix_type m_costmatrix;
00046 matrix_type m_costs_orig;
00047 matrix_type m_maskmatrix;
00048 int m_step;
00049
00050 std::vector<bool> m_rowIsCovered;
00051 std::vector<bool> m_colIsCovered;
00052 const int m_dim;
00053 };
00054 #endif