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  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  int numberRowBlocks_;
228  std::vector<std::string> rowBlockNames_;
230  std::vector<std::string> columnBlockNames_;
238 };
239 #endif
int numberColumnBlocks() const
Return number of column blocks.
int CoinBigIndex
double optimizationDirection() const
Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
This is a simple minded model which is stored in a format which makes it easier to construct and modi...
Definition: CoinModel.hpp:149
virtual ~CoinStructuredModel()
Destructor.
int blockIndex(int row, int column) const
Return block number corresponding to row and column.
int numberRowBlocks() const
Return number of row blocks.
CoinModel ** coinModelBlocks_
CoinModel copies of blocks or NULL if original CoinModel.
int decompose(const CoinModel &model, int type, int maxBlocks=50)
Decompose a CoinModel 1 - try D-W 2 - try Benders 3 - try Staircase Returns number of blocks or zero ...
int addBlock(const std::string &rowBlock, const std::string &columnBlock, const CoinBaseModel &block)
add a block from a CoinModel using names given as parameters returns number of errors (e...
int addColumnBlock(int numberColumns, const std::string &name)
Add or check a column block name and number of columns.
const std::string & getRowBlock(int i) const
Return the i'th row block name.
Sparse Matrix Base Class.
int maximumElementBlocks_
Maximum number of element blocks.
CoinModel * coinModelBlock(CoinModelBlockInfo &info)
Return model as a CoinModel block and fill in info structure and update counts.
const std::string & getColumnBlock(int i) const
Return i'th the column block name.
void setCoinModel(CoinModel *block, int iBlock)
Sets given block into coinModelBlocks_.
void setRowBlock(int i, const std::string &name)
Set i'th row block name.
int fillInfo(CoinModelBlockInfo &info, const CoinModel *block)
Fill in info structure and update counts Returns number of inconsistencies on border.
int columnBlock(const std::string &name) const
Return a column block index given a column block name.
void refresh(int iBlock)
Refresh info in blockType_.
int numberColumns() const
Return number of columns.
Definition: CoinModel.hpp:38
virtual CoinBaseModel * clone() const
Clone.
int numberElementBlocks_
Current number of element blocks.
CoinBaseModel * block(int i) const
Return i'th block.
CoinBigIndex numberElementBlocks() const
Return number of elementBlocks.
CoinStructuredModel()
Default constructor.
int numberRowBlocks_
Current number of row blocks.
struct CoinModelInfo2 CoinModelBlockInfo
This is a model which is made up of Coin(Structured)Model blocks.
double objectiveOffset() const
Returns the (constant) objective offset This is the RHS entry for the objective row.
Definition: CoinModel.hpp:45
CoinStructuredModel & operator=(const CoinStructuredModel &)
=
This is a model which is made up of Coin(Structured)Model blocks.
double optimizationDirection_
Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:91
CoinModelBlockInfo * blockType_
Which parts of model are set in block.
int writeMps(const char *filename, int compression=0, int formatType=0, int numberAcross=2, bool keepStrings=false)
Write the problem in MPS format to a file with the given filename.
void setColumnBlock(int i, const std::string &name)
Set i'th column block name.
CoinBaseModel ** blocks_
Blocks.
const CoinModelBlockInfo & blockType(int i) const
Return i'th block type.
int rowBlock(const std::string &name) const
Return a row block index given a row block name.
int addRowBlock(int numberRows, const std::string &name)
Add or check a row block name and number of rows.
int numberColumnBlocks_
Current number of column blocks.
void setOptimizationDirection(double value)
Set direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
CoinBigIndex numberElements() const
Return number of elements.
std::vector< std::string > columnBlockNames_
Columnblock name.
std::vector< std::string > rowBlockNames_
Rowblock name.
int numberRows() const
Return number of rows.
Definition: CoinModel.hpp:35
CoinModel * coinBlock(int i) const
Return i'th block as CoinModel (or NULL)