CoinStructuredModel.hpp
Go to the documentation of this file.
1 /* $Id: CoinStructuredModel.hpp 1191 2009-07-25 08:38:12Z forrest $ */
2 // Copyright (C) 2008, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 #ifndef CoinStructuredModel_H
5 #define CoinStructuredModel_H
6 
7 #include "CoinModel.hpp"
8 #include <vector>
9 
13  typedef struct CoinModelInfo2 {
14  int rowBlock; // Which row block
15  int columnBlock; // Which column block
16  char matrix; // nonzero if matrix exists
17  char rhs; // nonzero if non default rhs exists
18  char rowName; // nonzero if row names exists
19  char integer; // nonzero if integer information exists
20  char bounds; // nonzero if non default bounds/objective exists
21  char columnName; // nonzero if column names exists
23  rowBlock(0),
24  columnBlock(0),
25  matrix(0),
26  rhs(0),
27  rowName(0),
28  integer(0),
29  bounds(0),
30  columnName(0)
31  {}
33 
35 
36 public:
42  int addBlock(const std::string & rowBlock,
43  const std::string & columnBlock,
44  const CoinBaseModel & block);
48  int addBlock(const CoinBaseModel & block);
53  int addBlock(const std::string & rowBlock,
54  const std::string & columnBlock,
55  CoinBaseModel * block);
58  int addBlock(const std::string & rowBlock,
59  const std::string & columnBlock,
60  const CoinPackedMatrix & matrix,
61  const double * rowLower, const double * rowUpper,
62  const double * columnLower, const double * columnUpper,
63  const double * objective);
64 
90  int writeMps(const char *filename, int compression = 0,
91  int formatType = 0, int numberAcross = 2, bool keepStrings=false) ;
98  int decompose(const CoinModel &model,int type,
99  int maxBlocks=50);
106  int decompose(const CoinPackedMatrix & matrix,
107  const double * rowLower, const double * rowUpper,
108  const double * columnLower, const double * columnUpper,
109  const double * objective, int type,int maxBlocks=50,
110  double objectiveOffset=0.0);
111 
113 
114 
117 
118  inline int numberRowBlocks() const
119  { return numberRowBlocks_;}
121  inline int numberColumnBlocks() const
122  { return numberColumnBlocks_;}
125  { return numberElementBlocks_;}
129  inline const std::string & getRowBlock(int i) const
130  { return rowBlockNames_[i];}
132  inline void setRowBlock(int i,const std::string &name)
133  { rowBlockNames_[i] = name;}
135  int addRowBlock(int numberRows,const std::string &name) ;
137  int rowBlock(const std::string &name) const;
139  inline const std::string & getColumnBlock(int i) const
140  { return columnBlockNames_[i];}
142  inline void setColumnBlock(int i,const std::string &name)
143  { columnBlockNames_[i] = name;}
145  int addColumnBlock(int numberColumns,const std::string &name) ;
147  int columnBlock(const std::string &name) const;
149  inline const CoinModelBlockInfo & blockType(int i) const
150  { return blockType_[i];}
152  inline CoinBaseModel * block(int i) const
153  { return blocks_[i];}
155  const CoinBaseModel * block(int row,int column) const;
157  CoinModel * coinBlock(int i) const;
159  const CoinBaseModel * coinBlock(int row,int column) const;
161  int blockIndex(int row,int column) const;
167  void setCoinModel(CoinModel * block, int iBlock);
169  void refresh(int iBlock);
172  CoinModelBlockInfo block(int row,int column,
173  const double * & rowLower, const double * & rowUpper,
174  const double * & columnLower, const double * & columnUpper,
175  const double * & objective) const;
177  inline double optimizationDirection() const {
178  return optimizationDirection_;
179  }
181  inline void setOptimizationDirection(double value)
182  { optimizationDirection_=value;}
184 
192  CoinStructuredModel(const char *fileName,int decompose=0,
193  int maxBlocks=50);
195  virtual ~CoinStructuredModel();
197 
205  virtual CoinBaseModel * clone() const;
207 
208 private:
209 
213  int fillInfo(CoinModelBlockInfo & info,const CoinModel * block);
216  void fillInfo(CoinModelBlockInfo & info,const CoinStructuredModel * block);
219 
228  std::vector<std::string> rowBlockNames_;
230  std::vector<std::string> columnBlockNames_;
238 };
239 #endif