Dip  0.92.4
AP3_DecompApp.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 // Authors: Matthew Galati, SAS Institute Inc. (matthew.galati@sas.com) //
8 // Ted Ralphs, Lehigh University (ted@lehigh.edu) //
9 // Jiadong Wang, Lehigh University (jiw408@lehigh.edu) //
10 // //
11 // Copyright (C) 2002-2019, Lehigh University, Matthew Galati, and Ted Ralphs//
12 // All Rights Reserved. //
13 //===========================================================================//
14 
15 #ifndef AP3_DECOMPAPP_INCLUDED
16 #define AP3_DECOMPAPP_INCLUDED
17 
18 // --------------------------------------------------------------------- //
19 #include "DecompApp.h"
20 #include "AP3_Instance.h"
21 #include "AP3_DecompParam.h"
22 // --------------------------------------------------------------------- //
23 
33 // --------------------------------------------------------------------- //
34 class AP3_DecompApp : public DecompApp{
35 private:
37  const string m_classTag;
38 
39 private:
42 
43 private:
45  map<int, vector<int> > m_intersection;
46 
49  double ** m_assigncostMin;
51 
52 protected:
55 
56 public:
58  enum ModelType {
65  };
66 
67 public:
68  /* @name Inherited (from pure virtual) methods. */
69 
71  //TODO: model object? vs objCoeff?
72  void APPcreateModel(double *& objCoeff,
73  map<int, DecompConstraintSet*> & modelCore,
74  map<int, vector<DecompConstraintSet*> > & modelRelax);
75 
76 public:
77  /* @name Inherited (from virtual) methods. */
78 
80  //TOOD: too messy?
81  DecompStatus APPsolveRelaxed(const int whichModel,
82  const double * redCostX,
83  const double * origCost,
84  const double alpha,
85  const int n_origCols,
86  const bool checkRC,
87  const bool checkDup,
88  OsiSolverInterface * m_subprobSI,
89  list<DecompVar*> & vars);
90 
92  void printOriginalColumn(const int index,
93  ostream * os = &cout) const ;
94 
95 public:
99  inline const double getKnownOptimalBound() const {
100  return m_ap3data.m_optBound;
101  }
102 
104  inline const string getInstanceName() const {
105  return m_ap3data.m_instance;
106  }
107 
109  inline int indexIJK(const int i,
110  const int j,
111  const int k) const {
112  int n = m_ap3data.m_dimension;
113  return (i * n * n) + (j * n) + k;
114  }
115  inline int indexJIK(const int j,
116  const int i,
117  const int k) const {
118  int n = m_ap3data.m_dimension;
119  return (i * n * n) + (j * n) + k;
120  }
121  inline int indexKIJ(const int k,
122  const int i,
123  const int j) const {
124  int n = m_ap3data.m_dimension;
125  return (i * n * n) + (j * n) + k;
126  }
127 
129  inline void index3Inv(const int index,
130  int & ind1,
131  int & ind2,
132  int & ind3) const {
133  int n = m_ap3data.m_dimension;
134  int nsq = n * n;
135  int indexMod;
136  ind1 = index / nsq;
137  indexMod = index % nsq;
138  ind2 = indexMod / n;
139  ind3 = indexMod % n;
140  }
141 
143  inline int index2(const int ind1,
144  const int ind2) const {
145  int n = m_ap3data.m_dimension;
146  return (ind1 * n) + ind2;
147  }
148 
150  inline pair<int,int> index2Inv(const int index) const {
151  int n = m_ap3data.m_dimension;
152  return make_pair(index / n, index % n);
153  }
154 
156  inline const double getOptBound() const{
157  return m_ap3data.m_optBound;
158  }
159 
160 private:
164  void initializeApp(UtilParameters & utilParam) throw(CoinError);
165 
167  void createModelPart(const int modelType,
168  int * rowInd,
169  double * rowEls,
170  DecompConstraintSet * modelCore,
171  DecompConstraintSet * modelRelax) throw(CoinError);
172 
173 private:
179  AP3_DecompApp(const AP3_DecompApp &);
181 
182 public:
187  DecompApp(utilParam),
188  m_classTag("AP3-APP"),
189  m_ap3data(),
190  m_siAP(0),
191  m_assigncostMin(0),
192  m_assignindexMin(0),
193  m_appParam()
194  {
195  initializeApp(utilParam);
196  }
197 
198  virtual ~AP3_DecompApp() {
199  int d;
200  for(d = 0; d < m_ap3data.m_dimension; d++){
203  }
207  };
208 };
209 
210 #endif
int indexIJK(const int i, const int j, const int k) const
Global index for column (i,j,k) in 3D case.
double ** m_assigncostMin
Definition: AP3_DecompApp.h:49
double m_optBound
Known optimal bound (for debugging)
Definition: AP3_Instance.h:50
const string getInstanceName() const
Get name of instance.
DecompStatus
Definition: Decomp.h:184
int index2(const int ind1, const int ind2) const
Global index for column (ind1, ind2) in 2D case.
void index3Inv(const int index, int &ind1, int &ind2, int &ind3) const
Global index for column (ind1, ind2, ind3) in 3D case.
Relaxation is 2-D Assignment Problem over IxJ.
Definition: AP3_DecompApp.h:64
int indexKIJ(const int k, const int i, const int j) const
Get optimal (or best known) objective.
map< int, vector< int > > m_intersection
Helper data for fast cut separation.
Definition: AP3_DecompApp.h:45
AP3_DecompApp(const AP3_DecompApp &)
void createModelPart(const int modelType, int *rowInd, double *rowEls, DecompConstraintSet *modelCore, DecompConstraintSet *modelRelax)
Create constraint system for one relaxation.
DecompStatus APPsolveRelaxed(const int whichModel, const double *redCostX, const double *origCost, const double alpha, const int n_origCols, const bool checkRC, const bool checkDup, OsiSolverInterface *m_subprobSI, list< DecompVar * > &vars)
Solve the relaxed problem.
#define UTIL_DELARR(x)
Definition: UtilMacros.h:29
void APPcreateModel(double *&objCoeff, map< int, DecompConstraintSet * > &modelCore, map< int, vector< DecompConstraintSet * > > &modelRelax)
Create the application model(s).
pair< int, int > index2Inv(const int index) const
Return the indices (ind1, ind2) for 2D case.
void printOriginalColumn(const int index, ostream *os=&cout) const
Print an original column.
int m_dimension
The dimension of the instance.
Definition: AP3_Instance.h:35
Relaxation is 2-D Assignment Problem over JxK.
Definition: AP3_DecompApp.h:60
string m_instance
Name of AP3 instance.
Definition: AP3_Instance.h:47
virtual void initializeApp()
Initialize applications.
Abstract Base Class for describing an interface to a solver.
Relaxation is 2-D Assignment Problem over IxK.
Definition: AP3_DecompApp.h:62
OsiSolverInterface * m_siAP
Helper data for fast construction of relaxed problems.
Definition: AP3_DecompApp.h:48
#define UTIL_DELPTR(x)
Definition: UtilMacros.h:28
Error Class thrown by an exception.
Definition: CoinError.hpp:42
virtual ~AP3_DecompApp()
Default constructor.
int ** m_assignindexMin
Definition: AP3_DecompApp.h:50
ModelType
Model types.
Definition: AP3_DecompApp.h:58
AP3_DecompParam m_appParam
Application specific parameters.
Definition: AP3_DecompApp.h:54
AP3_DecompApp & operator=(const AP3_DecompApp &)
const double getOptBound() const
Return the known optimal bound.
AP3_DecompApp(UtilParameters &utilParam)
Default constructor.
AP3_Instance m_ap3data
AP3 problem instance data.
Definition: AP3_DecompApp.h:41
const string m_classTag
Class id tag (for log / debugging).
Definition: AP3_DecompApp.h:37
int indexJIK(const int j, const int i, const int k) const
Get optimal (or best known) objective.
const double getKnownOptimalBound() const
Get optimal (or best known) objective.
Definition: AP3_DecompApp.h:99
The main application class.
Definition: DecompApp.h:48