MMKP_MCKnap.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef MMKP_MCKNAP_INCLUDED
00014 #define MMKP_MCKNAP_INCLUDED
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 extern "C"{
00032 #include "mcknap.h"
00033 }
00034
00035
00036
00037
00038 #include "UtilMacros.h"
00039 using namespace std;
00040
00041
00042 class MMKP_MCKnap{
00043 private:
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 isetset * m_setset;
00058 double * m_costDbl;
00059 int * m_cost;
00060 int * m_weight;
00061 int m_nCols;
00062 int m_nGroupRows;
00063 int m_nGroupCols;
00064 int m_capacity;
00065 int m_cscale;
00066 int m_wscale;
00067
00068 public:
00069
00070 void solveTrivialMaxSum(const double * redCost,
00071 const double * origCost,
00072 vector<int> & solInd,
00073 double & varRedCost,
00074 double & varOrigCost);
00075
00076 inline const int getIndexIJ(const int i,
00077 const int j) const{
00078 return (i * m_nGroupCols) + j;
00079 }
00080
00081 inline pair<int,int> getIndexInv(const int index) const {
00082 return make_pair(index / m_nGroupCols, index % m_nGroupCols);
00083 }
00084
00085 void setMCKnapData(const double capacity,
00086 const double * weight);
00087
00088 void solveMCKnap(const double * redCost,
00089 const double * origCost,
00090 vector<int> & solInd,
00091 vector<double> & solEls,
00092 double & varRedCost,
00093 double & varOrigCost);
00094
00095 public:
00096 MMKP_MCKnap(const int nGroupRows,
00097 const int nGroupCols) :
00098 m_setset (NULL),
00099 m_costDbl (NULL),
00100 m_cost (NULL),
00101 m_weight (NULL),
00102 m_nCols (nGroupRows * nGroupCols),
00103 m_nGroupRows(nGroupRows),
00104 m_nGroupCols(nGroupCols),
00105 m_capacity (0),
00106 m_cscale (1),
00107 m_wscale (1)
00108 {
00109 m_costDbl = new double[m_nCols];
00110 m_cost = new int[m_nCols];
00111 m_weight = new int[m_nCols];
00112 assert(m_costDbl && m_cost && m_weight);
00113 }
00114 ~MMKP_MCKnap() {
00115 if(m_setset){
00116 itemset * setPtr = m_setset->fset;
00117 if(setPtr){
00118 int i;
00119 for(i = 0; i < m_setset->size; i++){
00120 if(setPtr->fset)
00121 free(setPtr->fset);
00122 setPtr++;
00123 }
00124 free(m_setset->fset);
00125 }
00126 free(m_setset);
00127 }
00128 UTIL_DELARR(m_costDbl);
00129 UTIL_DELARR(m_cost);
00130 UTIL_DELARR(m_weight);
00131 }
00132 };
00133
00134
00135 #endif