Dip-All  0.91.0
MMKP_MCKnap.h
Go to the documentation of this file.
1 //===========================================================================//
2 // This file is part of the Decomp Solver Framework. //
3 // //
4 // Decomp is distributed under the Common Public License as part of the //
5 // COIN-OR repository (http://www.coin-or.org). //
6 // //
7 // Author: Matthew Galati, Lehigh University //
8 // //
9 // Copyright (C) 2002-2015, Lehigh University, Matthew Galati, and Ted Ralphs//
10 // All Rights Reserved. //
11 //===========================================================================//
12 
13 #ifndef MMKP_MCKNAP_INCLUDED
14 #define MMKP_MCKNAP_INCLUDED
15 
16 //---
17 //--- The MMKP MCKnap -- interface class for
18 //--- Pisinger's Multi-Choice Knapsack Solver
19 //--- http://www.diku.dk/~pisinger/codes.html
20 //---
21 
22 //---
23 //--- Multi-Choice Knapsack Problem
24 //--- min sum{i in 1..n, j in 1..l[i]} c[i,j] x[i,j]
25 //--- s.t. sum{i in 1..n, j in 1..l[i]} w[i,j] x[i,j] <= b
26 //--- sum{j in 1..l[i]} x[i,j] = 1 , i in 1..n
27 //---
28 
29 
30 // --------------------------------------------------------------------- //
31 extern "C"{
32 #include "mcknap.h"
33 }
34 
35 //extern solstruct optsol;
36 
37 // --------------------------------------------------------------------- //
38 #include "UtilMacros.h"
39 using namespace std;
40 
41 // --------------------------------------------------------------------- //
43  private:
44 
45  //---
46  //--- typedef int itype; // item profits and weights
47  //--- typedef long stype; // sum of pofit or weight
48  //--- typedef unsigned long vtype; // solution vector
49  //---
50  //---
51  //--- typedef struct {
52  //--- itemset *fset;
53  //--- itemset *lset;
54  //--- ntype size;
55  //--- } isetset;
56  //---
57  isetset * m_setset; // set of itemsetsets
58  double * m_costDbl; // temp storage
59  int * m_cost; // cost vector (integer)
60  int * m_weight; // weight vector (integer)
61  int m_nCols; // size of mc-knap problem
64  int m_capacity; // capacity (integer)
65  int m_cscale; // cost vector scale factor
66  int m_wscale; // weight vector scale factor
67 
68  public:
69  //separate function just to reset cost...from one call to next
70  void solveTrivialMaxSum(const double * redCost,
71  const double * origCost,
72  vector<int> & solInd,
73  double & varRedCost,
74  double & varOrigCost);
75 
76  inline const int getIndexIJ(const int i,
77  const int j) const{
78  return (i * m_nGroupCols) + j;
79  }
80 
81  inline pair<int,int> getIndexInv(const int index) const {
82  return make_pair(index / m_nGroupCols, index % m_nGroupCols);
83  }
84 
85  void setMCKnapData(const double capacity,
86  const double * weight);
87 
88  void solveMCKnap(const double * redCost,
89  const double * origCost,
90  vector<int> & solInd,
91  vector<double> & solEls,
92  double & varRedCost,
93  double & varOrigCost);
94 
95  public:
96  MMKP_MCKnap(const int nGroupRows,
97  const int nGroupCols) :
98  m_setset (NULL),
99  m_costDbl (NULL),
100  m_cost (NULL),
101  m_weight (NULL),
102  m_nCols (nGroupRows * nGroupCols),
103  m_nGroupRows(nGroupRows),
104  m_nGroupCols(nGroupCols),
105  m_capacity (0),
106  m_cscale (1),
107  m_wscale (1)
108  {
109  m_costDbl = new double[m_nCols];
110  m_cost = new int[m_nCols];
111  m_weight = new int[m_nCols];
112  assert(m_costDbl && m_cost && m_weight);
113  }
115  if(m_setset){
116  itemset * setPtr = m_setset->fset;
117  if(setPtr){
118  int i;
119  for(i = 0; i < m_setset->size; i++){
120  if(setPtr->fset)
121  free(setPtr->fset);
122  setPtr++;
123  }
124  free(m_setset->fset);
125  }
126  free(m_setset);
127  }
128  UTIL_DELARR(m_costDbl);
129  UTIL_DELARR(m_cost);
130  UTIL_DELARR(m_weight);
131  }
132 };
133 
134 
135 #endif
int m_nGroupCols
Definition: MMKP_MCKnap.h:63
const int getIndexIJ(const int i, const int j) const
Definition: MMKP_MCKnap.h:76
pair< int, int > getIndexInv(const int index) const
Definition: MMKP_MCKnap.h:81
isetset * m_setset
Definition: MMKP_MCKnap.h:57
itemrec * fset
Definition: mcknap.h:97
int * m_cost
Definition: MMKP_MCKnap.h:59
#define UTIL_DELARR(x)
Definition: UtilMacros.h:29
Definition: mcknap.h:95
int m_capacity
Definition: MMKP_MCKnap.h:64
int * m_weight
Definition: MMKP_MCKnap.h:60
int m_nGroupRows
Definition: MMKP_MCKnap.h:62
double * m_costDbl
Definition: MMKP_MCKnap.h:58
MMKP_MCKnap(const int nGroupRows, const int nGroupCols)
Definition: MMKP_MCKnap.h:96