CoinUtils  2.9.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CoinStructuredModel.hpp
Go to the documentation of this file.
1 /* $Id: CoinStructuredModel.hpp 1372 2011-01-03 23:31:00Z lou $ */
2 // Copyright (C) 2008, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 // This code is licensed under the terms of the Eclipse Public License (EPL).
5 
6 #ifndef CoinStructuredModel_H
7 #define CoinStructuredModel_H
8 
9 #include "CoinModel.hpp"
10 #include <vector>
11 
15  typedef struct CoinModelInfo2 {
16  int rowBlock; // Which row block
17  int columnBlock; // Which column block
18  char matrix; // nonzero if matrix exists
19  char rhs; // nonzero if non default rhs exists
20  char rowName; // nonzero if row names exists
21  char integer; // nonzero if integer information exists
22  char bounds; // nonzero if non default bounds/objective exists
23  char columnName; // nonzero if column names exists
25  rowBlock(0),
26  columnBlock(0),
27  matrix(0),
28  rhs(0),
29  rowName(0),
30  integer(0),
31  bounds(0),
32  columnName(0)
33  {}
35 
37 
38 public:
44  int addBlock(const std::string & rowBlock,
45  const std::string & columnBlock,
46  const CoinBaseModel & block);
50  int addBlock(const CoinBaseModel & block);
55  int addBlock(const std::string & rowBlock,
56  const std::string & columnBlock,
57  CoinBaseModel * block);
60  int addBlock(const std::string & rowBlock,
61  const std::string & columnBlock,
62  const CoinPackedMatrix & matrix,
63  const double * rowLower, const double * rowUpper,
64  const double * columnLower, const double * columnUpper,
65  const double * objective);
66 
92  int writeMps(const char *filename, int compression = 0,
93  int formatType = 0, int numberAcross = 2, bool keepStrings=false) ;
100  int decompose(const CoinModel &model,int type,
101  int maxBlocks=50);
108  int decompose(const CoinPackedMatrix & matrix,
109  const double * rowLower, const double * rowUpper,
110  const double * columnLower, const double * columnUpper,
111  const double * objective, int type,int maxBlocks=50,
112  double objectiveOffset=0.0);
113 
115 
116 
119  inline int numberRowBlocks() const
121  { return numberRowBlocks_;}
123  inline int numberColumnBlocks() const
124  { return numberColumnBlocks_;}
127  { return numberElementBlocks_;}
131  inline const std::string & getRowBlock(int i) const
132  { return rowBlockNames_[i];}
134  inline void setRowBlock(int i,const std::string &name)
135  { rowBlockNames_[i] = name;}
137  int addRowBlock(int numberRows,const std::string &name) ;
139  int rowBlock(const std::string &name) const;
141  inline const std::string & getColumnBlock(int i) const
142  { return columnBlockNames_[i];}
144  inline void setColumnBlock(int i,const std::string &name)
145  { columnBlockNames_[i] = name;}
147  int addColumnBlock(int numberColumns,const std::string &name) ;
149  int columnBlock(const std::string &name) const;
151  inline const CoinModelBlockInfo & blockType(int i) const
152  { return blockType_[i];}
154  inline CoinBaseModel * block(int i) const
155  { return blocks_[i];}
157  const CoinBaseModel * block(int row,int column) const;
159  CoinModel * coinBlock(int i) const;
161  const CoinBaseModel * coinBlock(int row,int column) const;
163  int blockIndex(int row,int column) const;
169  void setCoinModel(CoinModel * block, int iBlock);
171  void refresh(int iBlock);
174  CoinModelBlockInfo block(int row,int column,
175  const double * & rowLower, const double * & rowUpper,
176  const double * & columnLower, const double * & columnUpper,
177  const double * & objective) const;
179  inline double optimizationDirection() const {
180  return optimizationDirection_;
181  }
183  inline void setOptimizationDirection(double value)
184  { optimizationDirection_=value;}
186 
194  CoinStructuredModel(const char *fileName,int decompose=0,
195  int maxBlocks=50);
197  virtual ~CoinStructuredModel();
199 
207  virtual CoinBaseModel * clone() const;
209 
210 private:
211 
215  int fillInfo(CoinModelBlockInfo & info,const CoinModel * block);
218  void fillInfo(CoinModelBlockInfo & info,const CoinStructuredModel * block);
221  int numberRowBlocks_;
230  std::vector<std::string> rowBlockNames_;
232  std::vector<std::string> columnBlockNames_;
240 };
241 #endif
void refresh(int iBlock)
Refresh info in blockType_.
This is a model which is made up of Coin(Structured)Model blocks.
const CoinModelBlockInfo & blockType(int i) const
Return i&#39;th block type.
CoinBigIndex numberElementBlocks() const
Return number of elementBlocks.
double optimizationDirection_
Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:94
int numberElementBlocks_
Current number of element blocks.
virtual ~CoinStructuredModel()
Destructor.
CoinBaseModel * block(int i) const
Return i&#39;th block.
int fillInfo(CoinModelBlockInfo &info, const CoinModel *block)
Fill in info structure and update counts Returns number of inconsistencies on border.
CoinBaseModel ** blocks_
Blocks.
virtual CoinBaseModel * clone() const
Clone.
This is a simple minded model which is stored in a format which makes it easier to construct and modi...
Definition: CoinModel.hpp:152
CoinStructuredModel & operator=(const CoinStructuredModel &)
=
CoinModelBlockInfo * blockType_
Which parts of model are set in block.
int maximumElementBlocks_
Maximum number of element blocks.
CoinModel * coinBlock(int i) const
Return i&#39;th block as CoinModel (or NULL)
void setCoinModel(CoinModel *block, int iBlock)
Sets given block into coinModelBlocks_.
std::vector< std::string > rowBlockNames_
Rowblock name.
struct CoinModelInfo2 CoinModelBlockInfo
This is a model which is made up of Coin(Structured)Model blocks.
int columnBlock(const std::string &name) const
Return a column block index given a column block name.
int numberColumns() const
Return number of columns.
Definition: CoinModel.hpp:41
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&#39;th row block name.
CoinModel * coinModelBlock(CoinModelBlockInfo &info)
Return model as a CoinModel block and fill in info structure and update counts.
int addRowBlock(int numberRows, const std::string &name)
Add or check a row block name and number of rows.
int numberRowBlocks() const
Return number of row blocks.
const std::string & getColumnBlock(int i) const
Return i&#39;th the column block name.
void setRowBlock(int i, const std::string &name)
Set i&#39;th row block name.
void setColumnBlock(int i, const std::string &name)
Set i&#39;th column block name.
void setOptimizationDirection(double value)
Set direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
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.
CoinModel ** coinModelBlocks_
CoinModel copies of blocks or NULL if original CoinModel.
Sparse Matrix Base Class.
CoinStructuredModel()
Default constructor.
double optimizationDirection() const
Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
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 CoinBigIndex
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 numberColumnBlocks_
Current number of column blocks.
int blockIndex(int row, int column) const
Return block number corresponding to row and column.
double objectiveOffset() const
Returns the (constant) objective offset This is the RHS entry for the objective row.
Definition: CoinModel.hpp:48
int numberRows() const
Return number of rows.
Definition: CoinModel.hpp:38
std::vector< std::string > columnBlockNames_
Columnblock name.
CoinBigIndex numberElements() const
Return number of elements.
int rowBlock(const std::string &name) const
Return a row block index given a row block name.
int numberColumnBlocks() const
Return number of column blocks.
int numberRowBlocks_
Current number of row blocks.