00001 00006 /* 00007 * Copyright (c) 2007 John Weaver 00008 * 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 */ 00023 00024 #if !defined(_MUNKRES_H_) 00025 #define _MUNKRES_H_ 00026 00027 #include <mtt/matrix.h> 00028 00029 #include <cmath> 00030 #include <list> 00031 #include <utility> 00032 #include <vector> 00033 00034 #include <Eigen/Dense> 00035 #include <Eigen/Cholesky> 00036 00037 #include <boost/shared_ptr.hpp> 00038 00039 using Eigen::MatrixXd; 00040 00041 using namespace std; 00042 00043 typedef struct 00044 { 00045 int row, col; 00046 00047 }orderedPair; 00048 00049 typedef boost::shared_ptr<orderedPair> orderedPairPtr; 00050 00051 00052 class Munkres { 00053 public: 00054 void solve(Matrix<double> &m); 00055 double solve(MatrixXd& m_in,vector<orderedPairPtr>& results); 00056 00057 private: 00058 static const int NORMAL = 0; 00059 static const int STAR = 1; 00060 static const int PRIME = 2; 00061 inline bool find_uncovered_in_matrix(double,int&,int&); 00062 inline bool pair_in_list(const std::pair<int,int> &, const std::list<std::pair<int,int> > &); 00063 int step1(void); 00064 int step2(void); 00065 int step3(void); 00066 int step4(void); 00067 int step5(void); 00068 int step6(void); 00069 Matrix<int> mask_matrix; 00070 Matrix<double> matrix; 00071 bool *row_mask; 00072 bool *col_mask; 00073 int saverow, savecol; 00074 }; 00075 00076 #endif /* !defined(_MUNKRES_H_) */