1/* $Id: ClpDynamicExampleMatrix.hpp 1665 2011-01-04 17:55:54Z lou $ */
2// Copyright (C) 2004, 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 ClpDynamicExampleMatrix_H
7#define ClpDynamicExampleMatrix_H
8
9
10#include "CoinPragma.hpp"
11
12#include "ClpDynamicMatrix.hpp"
13class ClpSimplex;
14/** This implements a dynamic matrix when we have a limit on the number of
15 "interesting rows". This version inherits from ClpDynamicMatrix and knows that
16 the real matrix is gub. This acts just like ClpDynamicMatrix but generates columns.
17 This "generates" columns by choosing from stored set. It is maent as a starting point
18 as to how you could use shortest path to generate columns.
19
20 So it has its own copy of all data needed. It populates ClpDynamicWatrix with enough
21 to allow for gub keys and active variables. In turn ClpDynamicMatrix populates
22 a CoinPackedMatrix with active columns and rows.
23
24 As there is one copy here and one in ClpDynamicmatrix these names end in Gen_
25
26 It is obviously more efficient to just use ClpDynamicMatrix but the ideas is to
27 show how much code a user would have to write.
28
29 This does not work very well with bounds
30
31*/
32
33class ClpDynamicExampleMatrix : public ClpDynamicMatrix {
34
35public:
36 /**@name Main functions provided */
37 //@{
38 /// Partial pricing
39 virtual void partialPricing(ClpSimplex * model, double start, double end,
40 int & bestSequence, int & numberWanted);
41
42 /** Creates a variable. This is called after partial pricing and will modify matrix.
43 Will update bestSequence.
44 */
45 virtual void createVariable(ClpSimplex * model, int & bestSequence);
46 /** If addColumn forces compression then this allows descendant to know what to do.
47 If >= then entry stayed in, if -1 then entry went out to lower bound.of zero.
48 Entries at upper bound (really nonzero) never go out (at present).
49 */
50 virtual void packDown(const int * in, int numberToPack);
51 //@}
52
53
54
55 /**@name Constructors, destructor */
56 //@{
57 /** Default constructor. */
58 ClpDynamicExampleMatrix();
59 /** This is the real constructor.
60 It assumes factorization frequency will not be changed.
61 This resizes model !!!!
62 The contents of original matrix in model will be taken over and original matrix
63 will be sanitized so can be deleted (to avoid a very small memory leak)
64 */
65 ClpDynamicExampleMatrix(ClpSimplex * model, int numberSets,
66 int numberColumns, const int * starts,
67 const double * lower, const double * upper,
68 const int * startColumn, const int * row,
69 const double * element, const double * cost,
70 const double * columnLower = NULL, const double * columnUpper = NULL,
71 const unsigned char * status = NULL,
72 const unsigned char * dynamicStatus = NULL,
73 int numberIds = 0, const int *ids = NULL);
74 /// This constructor just takes over ownership (except for lower, upper)
75 ClpDynamicExampleMatrix(ClpSimplex * model, int numberSets,
76 int numberColumns, int * starts,
77 const double * lower, const double * upper,
78 int * startColumn, int * row,
79 double * element, double * cost,
80 double * columnLower = NULL, double * columnUpper = NULL,
81 const unsigned char * status = NULL,
82 const unsigned char * dynamicStatus = NULL,
83 int numberIds = 0, const int *ids = NULL);
84
85 /** Destructor */
86 virtual ~ClpDynamicExampleMatrix();
87 //@}
88
89 /**@name Copy method */
90 //@{
91 /** The copy constructor. */
92 ClpDynamicExampleMatrix(const ClpDynamicExampleMatrix&);
93 ClpDynamicExampleMatrix& operator=(const ClpDynamicExampleMatrix&);
94 /// Clone
95 virtual ClpMatrixBase * clone() const ;
96 //@}
97 /**@name gets and sets */
98 //@{
99 /// Starts of each column
100 inline CoinBigIndex * startColumnGen() const {
101 return startColumnGen_;
102 }
103 /// rows
104 inline int * rowGen() const {
105 return rowGen_;
106 }
107 /// elements
108 inline double * elementGen() const {
109 return elementGen_;
110 }
111 /// costs
112 inline double * costGen() const {
113 return costGen_;
114 }
115 /// full starts
116 inline int * fullStartGen() const {
117 return fullStartGen_;
118 }
119 /// ids in next level matrix
120 inline int * idGen() const {
121 return idGen_;
122 }
123 /// Optional lower bounds on columns
124 inline double * columnLowerGen() const {
125 return columnLowerGen_;
126 }
127 /// Optional upper bounds on columns
128 inline double * columnUpperGen() const {
129 return columnUpperGen_;
130 }
131 /// size
132 inline int numberColumns() const {
133 return numberColumns_;
134 }
135 inline void setDynamicStatusGen(int sequence, DynamicStatus status) {
136 unsigned char & st_byte = dynamicStatusGen_[sequence];
137 st_byte = static_cast<unsigned char>(st_byte & ~7);
138 st_byte = static_cast<unsigned char>(st_byte | status);
139 }
140 inline DynamicStatus getDynamicStatusGen(int sequence) const {
141 return static_cast<DynamicStatus> (dynamicStatusGen_[sequence] & 7);
142 }
143 /// Whether flagged
144 inline bool flaggedGen(int i) const {
145 return (dynamicStatusGen_[i] & 8) != 0;
146 }
147 inline void setFlaggedGen(int i) {
148 dynamicStatusGen_[i] = static_cast<unsigned char>(dynamicStatusGen_[i] | 8);
149 }
150 inline void unsetFlagged(int i) {
151 dynamicStatusGen_[i] = static_cast<unsigned char>(dynamicStatusGen_[i] & ~8);
152 }
153 //@}
154
155
156protected:
157 /**@name Data members
158 The data members are protected to allow access for derived classes. */
159 //@{
160 /// size
161 int numberColumns_;
162 /// Starts of each column
163 CoinBigIndex * startColumnGen_;
164 /// rows
165 int * rowGen_;
166 /// elements
167 double * elementGen_;
168 /// costs
169 double * costGen_;
170 /// start of each set
171 int * fullStartGen_;
172 /// for status and which bound
173 unsigned char * dynamicStatusGen_;
174 /** identifier for each variable up one level (startColumn_, etc). This is
175 of length maximumGubColumns_. For this version it is just sequence number
176 at this level */
177 int * idGen_;
178 /// Optional lower bounds on columns
179 double * columnLowerGen_;
180 /// Optional upper bounds on columns
181 double * columnUpperGen_;
182 //@}
183};
184
185#endif
186