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