1 | /* $Id: ClpPackedMatrix.hpp 1836 2011-12-15 20:22:39Z stefan $ */ |
---|
2 | // Copyright (C) 2002, 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 ClpPackedMatrix_H |
---|
7 | #define ClpPackedMatrix_H |
---|
8 | |
---|
9 | #include "CoinPragma.hpp" |
---|
10 | |
---|
11 | #include "ClpMatrixBase.hpp" |
---|
12 | |
---|
13 | // Compilers can produce better code if they know about __restrict |
---|
14 | #ifndef COIN_RESTRICT |
---|
15 | #ifdef COIN_USE_RESTRICT |
---|
16 | #define COIN_RESTRICT __restrict |
---|
17 | #else |
---|
18 | #define COIN_RESTRICT |
---|
19 | #endif |
---|
20 | #endif |
---|
21 | |
---|
22 | /** This implements CoinPackedMatrix as derived from ClpMatrixBase. |
---|
23 | |
---|
24 | It adds a few methods that know about model as well as matrix |
---|
25 | |
---|
26 | For details see CoinPackedMatrix */ |
---|
27 | |
---|
28 | class ClpPackedMatrix2; |
---|
29 | class ClpPackedMatrix3; |
---|
30 | class ClpPackedMatrix : public ClpMatrixBase { |
---|
31 | |
---|
32 | public: |
---|
33 | /**@name Useful methods */ |
---|
34 | //@{ |
---|
35 | /// Return a complete CoinPackedMatrix |
---|
36 | virtual CoinPackedMatrix * getPackedMatrix() const { |
---|
37 | return matrix_; |
---|
38 | } |
---|
39 | /** Whether the packed matrix is column major ordered or not. */ |
---|
40 | virtual bool isColOrdered() const { |
---|
41 | return matrix_->isColOrdered(); |
---|
42 | } |
---|
43 | /** Number of entries in the packed matrix. */ |
---|
44 | virtual CoinBigIndex getNumElements() const { |
---|
45 | return matrix_->getNumElements(); |
---|
46 | } |
---|
47 | /** Number of columns. */ |
---|
48 | virtual int getNumCols() const { |
---|
49 | return matrix_->getNumCols(); |
---|
50 | } |
---|
51 | /** Number of rows. */ |
---|
52 | virtual int getNumRows() const { |
---|
53 | return matrix_->getNumRows(); |
---|
54 | } |
---|
55 | |
---|
56 | /** A vector containing the elements in the packed matrix. Note that there |
---|
57 | might be gaps in this list, entries that do not belong to any |
---|
58 | major-dimension vector. To get the actual elements one should look at |
---|
59 | this vector together with vectorStarts and vectorLengths. */ |
---|
60 | virtual const double * getElements() const { |
---|
61 | return matrix_->getElements(); |
---|
62 | } |
---|
63 | /// Mutable elements |
---|
64 | inline double * getMutableElements() const { |
---|
65 | return matrix_->getMutableElements(); |
---|
66 | } |
---|
67 | /** A vector containing the minor indices of the elements in the packed |
---|
68 | matrix. Note that there might be gaps in this list, entries that do not |
---|
69 | belong to any major-dimension vector. To get the actual elements one |
---|
70 | should look at this vector together with vectorStarts and |
---|
71 | vectorLengths. */ |
---|
72 | virtual const int * getIndices() const { |
---|
73 | return matrix_->getIndices(); |
---|
74 | } |
---|
75 | |
---|
76 | virtual const CoinBigIndex * getVectorStarts() const { |
---|
77 | return matrix_->getVectorStarts(); |
---|
78 | } |
---|
79 | /** The lengths of the major-dimension vectors. */ |
---|
80 | virtual const int * getVectorLengths() const { |
---|
81 | return matrix_->getVectorLengths(); |
---|
82 | } |
---|
83 | /** The length of a single major-dimension vector. */ |
---|
84 | virtual int getVectorLength(int index) const { |
---|
85 | return matrix_->getVectorSize(index); |
---|
86 | } |
---|
87 | |
---|
88 | /** Delete the columns whose indices are listed in <code>indDel</code>. */ |
---|
89 | virtual void deleteCols(const int numDel, const int * indDel); |
---|
90 | /** Delete the rows whose indices are listed in <code>indDel</code>. */ |
---|
91 | virtual void deleteRows(const int numDel, const int * indDel); |
---|
92 | #ifndef CLP_NO_VECTOR |
---|
93 | /// Append Columns |
---|
94 | virtual void appendCols(int number, const CoinPackedVectorBase * const * columns); |
---|
95 | /// Append Rows |
---|
96 | virtual void appendRows(int number, const CoinPackedVectorBase * const * rows); |
---|
97 | #endif |
---|
98 | /** Append a set of rows/columns to the end of the matrix. Returns number of errors |
---|
99 | i.e. if any of the new rows/columns contain an index that's larger than the |
---|
100 | number of columns-1/rows-1 (if numberOther>0) or duplicates |
---|
101 | If 0 then rows, 1 if columns */ |
---|
102 | virtual int appendMatrix(int number, int type, |
---|
103 | const CoinBigIndex * starts, const int * index, |
---|
104 | const double * element, int numberOther = -1); |
---|
105 | /** Replace the elements of a vector. The indices remain the same. |
---|
106 | This is only needed if scaling and a row copy is used. |
---|
107 | At most the number specified will be replaced. |
---|
108 | The index is between 0 and major dimension of matrix */ |
---|
109 | virtual void replaceVector(const int index, |
---|
110 | const int numReplace, const double * newElements) { |
---|
111 | matrix_->replaceVector(index, numReplace, newElements); |
---|
112 | } |
---|
113 | /** Modify one element of packed matrix. An element may be added. |
---|
114 | This works for either ordering If the new element is zero it will be |
---|
115 | deleted unless keepZero true */ |
---|
116 | virtual void modifyCoefficient(int row, int column, double newElement, |
---|
117 | bool keepZero = false) { |
---|
118 | matrix_->modifyCoefficient(row, column, newElement, keepZero); |
---|
119 | } |
---|
120 | /** Returns a new matrix in reverse order without gaps */ |
---|
121 | virtual ClpMatrixBase * reverseOrderedCopy() const; |
---|
122 | /// Returns number of elements in column part of basis |
---|
123 | virtual CoinBigIndex countBasis(const int * whichColumn, |
---|
124 | int & numberColumnBasic); |
---|
125 | /// Fills in column part of basis |
---|
126 | virtual void fillBasis(ClpSimplex * model, |
---|
127 | const int * whichColumn, |
---|
128 | int & numberColumnBasic, |
---|
129 | int * row, int * start, |
---|
130 | int * rowCount, int * columnCount, |
---|
131 | CoinFactorizationDouble * element); |
---|
132 | /** Creates scales for column copy (rowCopy in model may be modified) |
---|
133 | returns non-zero if no scaling done */ |
---|
134 | virtual int scale(ClpModel * model, const ClpSimplex * baseModel = NULL) const ; |
---|
135 | /** Scales rowCopy if column copy scaled |
---|
136 | Only called if scales already exist */ |
---|
137 | virtual void scaleRowCopy(ClpModel * model) const ; |
---|
138 | /// Creates scaled column copy if scales exist |
---|
139 | void createScaledMatrix(ClpSimplex * model) const; |
---|
140 | /** Realy really scales column copy |
---|
141 | Only called if scales already exist. |
---|
142 | Up to user ro delete */ |
---|
143 | virtual ClpMatrixBase * scaledColumnCopy(ClpModel * model) const ; |
---|
144 | /** Checks if all elements are in valid range. Can just |
---|
145 | return true if you are not paranoid. For Clp I will |
---|
146 | probably expect no zeros. Code can modify matrix to get rid of |
---|
147 | small elements. |
---|
148 | check bits (can be turned off to save time) : |
---|
149 | 1 - check if matrix has gaps |
---|
150 | 2 - check if zero elements |
---|
151 | 4 - check and compress duplicates |
---|
152 | 8 - report on large and small |
---|
153 | */ |
---|
154 | virtual bool allElementsInRange(ClpModel * model, |
---|
155 | double smallest, double largest, |
---|
156 | int check = 15); |
---|
157 | /** Returns largest and smallest elements of both signs. |
---|
158 | Largest refers to largest absolute value. |
---|
159 | */ |
---|
160 | virtual void rangeOfElements(double & smallestNegative, double & largestNegative, |
---|
161 | double & smallestPositive, double & largestPositive); |
---|
162 | |
---|
163 | /** Unpacks a column into an CoinIndexedvector |
---|
164 | */ |
---|
165 | virtual void unpack(const ClpSimplex * model, CoinIndexedVector * rowArray, |
---|
166 | int column) const ; |
---|
167 | /** Unpacks a column into an CoinIndexedvector |
---|
168 | ** in packed foramt |
---|
169 | Note that model is NOT const. Bounds and objective could |
---|
170 | be modified if doing column generation (just for this variable) */ |
---|
171 | virtual void unpackPacked(ClpSimplex * model, |
---|
172 | CoinIndexedVector * rowArray, |
---|
173 | int column) const; |
---|
174 | /** Adds multiple of a column into an CoinIndexedvector |
---|
175 | You can use quickAdd to add to vector */ |
---|
176 | virtual void add(const ClpSimplex * model, CoinIndexedVector * rowArray, |
---|
177 | int column, double multiplier) const ; |
---|
178 | /** Adds multiple of a column into an array */ |
---|
179 | virtual void add(const ClpSimplex * model, double * array, |
---|
180 | int column, double multiplier) const; |
---|
181 | /// Allow any parts of a created CoinPackedMatrix to be deleted |
---|
182 | virtual void releasePackedMatrix() const { } |
---|
183 | /** Given positive integer weights for each row fills in sum of weights |
---|
184 | for each column (and slack). |
---|
185 | Returns weights vector |
---|
186 | */ |
---|
187 | virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model, int * inputWeights) const; |
---|
188 | /// Says whether it can do partial pricing |
---|
189 | virtual bool canDoPartialPricing() const; |
---|
190 | /// Partial pricing |
---|
191 | virtual void partialPricing(ClpSimplex * model, double start, double end, |
---|
192 | int & bestSequence, int & numberWanted); |
---|
193 | /// makes sure active columns correct |
---|
194 | virtual int refresh(ClpSimplex * model); |
---|
195 | // Really scale matrix |
---|
196 | virtual void reallyScale(const double * rowScale, const double * columnScale); |
---|
197 | /** Set the dimensions of the matrix. In effect, append new empty |
---|
198 | columns/rows to the matrix. A negative number for either dimension |
---|
199 | means that that dimension doesn't change. Otherwise the new dimensions |
---|
200 | MUST be at least as large as the current ones otherwise an exception |
---|
201 | is thrown. */ |
---|
202 | virtual void setDimensions(int numrows, int numcols); |
---|
203 | //@} |
---|
204 | |
---|
205 | /**@name Matrix times vector methods */ |
---|
206 | //@{ |
---|
207 | /** Return <code>y + A * scalar *x</code> in <code>y</code>. |
---|
208 | @pre <code>x</code> must be of size <code>numColumns()</code> |
---|
209 | @pre <code>y</code> must be of size <code>numRows()</code> */ |
---|
210 | virtual void times(double scalar, |
---|
211 | const double * x, double * y) const; |
---|
212 | /// And for scaling |
---|
213 | virtual void times(double scalar, |
---|
214 | const double * x, double * y, |
---|
215 | const double * rowScale, |
---|
216 | const double * columnScale) const; |
---|
217 | /** Return <code>y + x * scalar * A</code> in <code>y</code>. |
---|
218 | @pre <code>x</code> must be of size <code>numRows()</code> |
---|
219 | @pre <code>y</code> must be of size <code>numColumns()</code> */ |
---|
220 | virtual void transposeTimes(double scalar, |
---|
221 | const double * x, double * y) const; |
---|
222 | /// And for scaling |
---|
223 | virtual void transposeTimes(double scalar, |
---|
224 | const double * x, double * y, |
---|
225 | const double * rowScale, |
---|
226 | const double * columnScale, |
---|
227 | double * spare = NULL) const; |
---|
228 | /** Return <code>y - pi * A</code> in <code>y</code>. |
---|
229 | @pre <code>pi</code> must be of size <code>numRows()</code> |
---|
230 | @pre <code>y</code> must be of size <code>numColumns()</code> |
---|
231 | This just does subset (but puts in correct place in y) */ |
---|
232 | void transposeTimesSubset( int number, |
---|
233 | const int * which, |
---|
234 | const double * pi, double * y, |
---|
235 | const double * rowScale, |
---|
236 | const double * columnScale, |
---|
237 | double * spare = NULL) const; |
---|
238 | /** Return <code>x * scalar * A + y</code> in <code>z</code>. |
---|
239 | Can use y as temporary array (will be empty at end) |
---|
240 | Note - If x packed mode - then z packed mode |
---|
241 | Squashes small elements and knows about ClpSimplex */ |
---|
242 | virtual void transposeTimes(const ClpSimplex * model, double scalar, |
---|
243 | const CoinIndexedVector * x, |
---|
244 | CoinIndexedVector * y, |
---|
245 | CoinIndexedVector * z) const; |
---|
246 | /** Return <code>x * scalar * A + y</code> in <code>z</code>. |
---|
247 | Note - If x packed mode - then z packed mode |
---|
248 | This does by column and knows no gaps |
---|
249 | Squashes small elements and knows about ClpSimplex */ |
---|
250 | void transposeTimesByColumn(const ClpSimplex * model, double scalar, |
---|
251 | const CoinIndexedVector * x, |
---|
252 | CoinIndexedVector * y, |
---|
253 | CoinIndexedVector * z) const; |
---|
254 | /** Return <code>x * scalar * A + y</code> in <code>z</code>. |
---|
255 | Can use y as temporary array (will be empty at end) |
---|
256 | Note - If x packed mode - then z packed mode |
---|
257 | Squashes small elements and knows about ClpSimplex. |
---|
258 | This version uses row copy*/ |
---|
259 | virtual void transposeTimesByRow(const ClpSimplex * model, double scalar, |
---|
260 | const CoinIndexedVector * x, |
---|
261 | CoinIndexedVector * y, |
---|
262 | CoinIndexedVector * z) const; |
---|
263 | /** Return <code>x *A</code> in <code>z</code> but |
---|
264 | just for indices in y. |
---|
265 | Note - z always packed mode */ |
---|
266 | virtual void subsetTransposeTimes(const ClpSimplex * model, |
---|
267 | const CoinIndexedVector * x, |
---|
268 | const CoinIndexedVector * y, |
---|
269 | CoinIndexedVector * z) const; |
---|
270 | /** Returns true if can combine transposeTimes and subsetTransposeTimes |
---|
271 | and if it would be faster */ |
---|
272 | virtual bool canCombine(const ClpSimplex * model, |
---|
273 | const CoinIndexedVector * pi) const; |
---|
274 | /// Updates two arrays for steepest |
---|
275 | virtual void transposeTimes2(const ClpSimplex * model, |
---|
276 | const CoinIndexedVector * pi1, CoinIndexedVector * dj1, |
---|
277 | const CoinIndexedVector * pi2, |
---|
278 | CoinIndexedVector * spare, |
---|
279 | double referenceIn, double devex, |
---|
280 | // Array for exact devex to say what is in reference framework |
---|
281 | unsigned int * reference, |
---|
282 | double * weights, double scaleFactor); |
---|
283 | /// Updates second array for steepest and does devex weights |
---|
284 | virtual void subsetTimes2(const ClpSimplex * model, |
---|
285 | CoinIndexedVector * dj1, |
---|
286 | const CoinIndexedVector * pi2, CoinIndexedVector * dj2, |
---|
287 | double referenceIn, double devex, |
---|
288 | // Array for exact devex to say what is in reference framework |
---|
289 | unsigned int * reference, |
---|
290 | double * weights, double scaleFactor); |
---|
291 | /// Sets up an effective RHS |
---|
292 | void useEffectiveRhs(ClpSimplex * model); |
---|
293 | #if COIN_LONG_WORK |
---|
294 | // For long double versions |
---|
295 | virtual void times(CoinWorkDouble scalar, |
---|
296 | const CoinWorkDouble * x, CoinWorkDouble * y) const ; |
---|
297 | virtual void transposeTimes(CoinWorkDouble scalar, |
---|
298 | const CoinWorkDouble * x, CoinWorkDouble * y) const ; |
---|
299 | #endif |
---|
300 | //@} |
---|
301 | |
---|
302 | /**@name Other */ |
---|
303 | //@{ |
---|
304 | /// Returns CoinPackedMatrix (non const) |
---|
305 | inline CoinPackedMatrix * matrix() const { |
---|
306 | return matrix_; |
---|
307 | } |
---|
308 | /** Just sets matrix_ to NULL so it can be used elsewhere. |
---|
309 | used in GUB |
---|
310 | */ |
---|
311 | inline void setMatrixNull() { |
---|
312 | matrix_ = NULL; |
---|
313 | } |
---|
314 | /// Say we want special column copy |
---|
315 | inline void makeSpecialColumnCopy() { |
---|
316 | flags_ |= 16; |
---|
317 | } |
---|
318 | /// Say we don't want special column copy |
---|
319 | void releaseSpecialColumnCopy(); |
---|
320 | /// Are there zeros? |
---|
321 | inline bool zeros() const { |
---|
322 | return ((flags_ & 1) != 0); |
---|
323 | } |
---|
324 | /// Do we want special column copy |
---|
325 | inline bool wantsSpecialColumnCopy() const { |
---|
326 | return ((flags_ & 16) != 0); |
---|
327 | } |
---|
328 | /// Flags |
---|
329 | inline int flags() const { |
---|
330 | return flags_; |
---|
331 | } |
---|
332 | /// Sets flags_ correctly |
---|
333 | inline void checkGaps() { |
---|
334 | flags_ = (matrix_->hasGaps()) ? (flags_ | 2) : (flags_ & (~2)); |
---|
335 | } |
---|
336 | /// number of active columns (normally same as number of columns) |
---|
337 | inline int numberActiveColumns() const |
---|
338 | { return numberActiveColumns_;} |
---|
339 | /// Set number of active columns (normally same as number of columns) |
---|
340 | inline void setNumberActiveColumns(int value) |
---|
341 | { numberActiveColumns_ = value;} |
---|
342 | //@} |
---|
343 | |
---|
344 | |
---|
345 | /**@name Constructors, destructor */ |
---|
346 | //@{ |
---|
347 | /** Default constructor. */ |
---|
348 | ClpPackedMatrix(); |
---|
349 | /** Destructor */ |
---|
350 | virtual ~ClpPackedMatrix(); |
---|
351 | //@} |
---|
352 | |
---|
353 | /**@name Copy method */ |
---|
354 | //@{ |
---|
355 | /** The copy constructor. */ |
---|
356 | ClpPackedMatrix(const ClpPackedMatrix&); |
---|
357 | /** The copy constructor from an CoinPackedMatrix. */ |
---|
358 | ClpPackedMatrix(const CoinPackedMatrix&); |
---|
359 | /** Subset constructor (without gaps). Duplicates are allowed |
---|
360 | and order is as given */ |
---|
361 | ClpPackedMatrix (const ClpPackedMatrix & wholeModel, |
---|
362 | int numberRows, const int * whichRows, |
---|
363 | int numberColumns, const int * whichColumns); |
---|
364 | ClpPackedMatrix (const CoinPackedMatrix & wholeModel, |
---|
365 | int numberRows, const int * whichRows, |
---|
366 | int numberColumns, const int * whichColumns); |
---|
367 | |
---|
368 | /** This takes over ownership (for space reasons) */ |
---|
369 | ClpPackedMatrix(CoinPackedMatrix * matrix); |
---|
370 | |
---|
371 | ClpPackedMatrix& operator=(const ClpPackedMatrix&); |
---|
372 | /// Clone |
---|
373 | virtual ClpMatrixBase * clone() const ; |
---|
374 | /// Copy contents - resizing if necessary - otherwise re-use memory |
---|
375 | virtual void copy(const ClpPackedMatrix * from); |
---|
376 | /** Subset clone (without gaps). Duplicates are allowed |
---|
377 | and order is as given */ |
---|
378 | virtual ClpMatrixBase * subsetClone ( |
---|
379 | int numberRows, const int * whichRows, |
---|
380 | int numberColumns, const int * whichColumns) const ; |
---|
381 | /// make special row copy |
---|
382 | void specialRowCopy(ClpSimplex * model, const ClpMatrixBase * rowCopy); |
---|
383 | /// make special column copy |
---|
384 | void specialColumnCopy(ClpSimplex * model); |
---|
385 | /// Correct sequence in and out to give true value |
---|
386 | virtual void correctSequence(const ClpSimplex * model, int & sequenceIn, int & sequenceOut) ; |
---|
387 | //@} |
---|
388 | private: |
---|
389 | /// Meat of transposeTimes by column when not scaled |
---|
390 | int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi, |
---|
391 | int * COIN_RESTRICT index, |
---|
392 | double * COIN_RESTRICT array, |
---|
393 | const double tolerance) const; |
---|
394 | /// Meat of transposeTimes by column when scaled |
---|
395 | int gutsOfTransposeTimesScaled(const double * COIN_RESTRICT pi, |
---|
396 | const double * COIN_RESTRICT columnScale, |
---|
397 | int * COIN_RESTRICT index, |
---|
398 | double * COIN_RESTRICT array, |
---|
399 | const double tolerance) const; |
---|
400 | /// Meat of transposeTimes by column when not scaled and skipping |
---|
401 | int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi, |
---|
402 | int * COIN_RESTRICT index, |
---|
403 | double * COIN_RESTRICT array, |
---|
404 | const unsigned char * status, |
---|
405 | const double tolerance) const; |
---|
406 | /** Meat of transposeTimes by column when not scaled and skipping |
---|
407 | and doing part of dualColumn */ |
---|
408 | int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi, |
---|
409 | int * COIN_RESTRICT index, |
---|
410 | double * COIN_RESTRICT array, |
---|
411 | const unsigned char * status, |
---|
412 | int * COIN_RESTRICT spareIndex, |
---|
413 | double * COIN_RESTRICT spareArray, |
---|
414 | const double * COIN_RESTRICT reducedCost, |
---|
415 | double & upperTheta, |
---|
416 | double & bestPossible, |
---|
417 | double acceptablePivot, |
---|
418 | double dualTolerance, |
---|
419 | int & numberRemaining, |
---|
420 | const double zeroTolerance) const; |
---|
421 | /// Meat of transposeTimes by column when scaled and skipping |
---|
422 | int gutsOfTransposeTimesScaled(const double * COIN_RESTRICT pi, |
---|
423 | const double * COIN_RESTRICT columnScale, |
---|
424 | int * COIN_RESTRICT index, |
---|
425 | double * COIN_RESTRICT array, |
---|
426 | const unsigned char * status, |
---|
427 | const double tolerance) const; |
---|
428 | /// Meat of transposeTimes by row n > K if packed - returns number nonzero |
---|
429 | int gutsOfTransposeTimesByRowGEK(const CoinIndexedVector * COIN_RESTRICT piVector, |
---|
430 | int * COIN_RESTRICT index, |
---|
431 | double * COIN_RESTRICT output, |
---|
432 | int numberColumns, |
---|
433 | const double tolerance, |
---|
434 | const double scalar) const; |
---|
435 | /// Meat of transposeTimes by row n > 2 if packed - returns number nonzero |
---|
436 | int gutsOfTransposeTimesByRowGE3(const CoinIndexedVector * COIN_RESTRICT piVector, |
---|
437 | int * COIN_RESTRICT index, |
---|
438 | double * COIN_RESTRICT output, |
---|
439 | double * COIN_RESTRICT array2, |
---|
440 | const double tolerance, |
---|
441 | const double scalar) const; |
---|
442 | /// Meat of transposeTimes by row n > 2 if packed - returns number nonzero |
---|
443 | int gutsOfTransposeTimesByRowGE3a(const CoinIndexedVector * COIN_RESTRICT piVector, |
---|
444 | int * COIN_RESTRICT index, |
---|
445 | double * COIN_RESTRICT output, |
---|
446 | int * COIN_RESTRICT lookup, |
---|
447 | char * COIN_RESTRICT marked, |
---|
448 | const double tolerance, |
---|
449 | const double scalar) const; |
---|
450 | /// Meat of transposeTimes by row n == 2 if packed |
---|
451 | void gutsOfTransposeTimesByRowEQ2(const CoinIndexedVector * piVector, CoinIndexedVector * output, |
---|
452 | CoinIndexedVector * spareVector, const double tolerance, const double scalar) const; |
---|
453 | /// Meat of transposeTimes by row n == 1 if packed |
---|
454 | void gutsOfTransposeTimesByRowEQ1(const CoinIndexedVector * piVector, CoinIndexedVector * output, |
---|
455 | const double tolerance, const double scalar) const; |
---|
456 | /// Gets rid of special copies |
---|
457 | void clearCopies(); |
---|
458 | |
---|
459 | |
---|
460 | protected: |
---|
461 | /// Check validity |
---|
462 | void checkFlags(int type) const; |
---|
463 | /**@name Data members |
---|
464 | The data members are protected to allow access for derived classes. */ |
---|
465 | //@{ |
---|
466 | /// Data |
---|
467 | CoinPackedMatrix * matrix_; |
---|
468 | /// number of active columns (normally same as number of columns) |
---|
469 | int numberActiveColumns_; |
---|
470 | /** Flags - |
---|
471 | 1 - has zero elements |
---|
472 | 2 - has gaps |
---|
473 | 4 - has special row copy |
---|
474 | 8 - has special column copy |
---|
475 | 16 - wants special column copy |
---|
476 | */ |
---|
477 | mutable int flags_; |
---|
478 | /// Special row copy |
---|
479 | ClpPackedMatrix2 * rowCopy_; |
---|
480 | /// Special column copy |
---|
481 | ClpPackedMatrix3 * columnCopy_; |
---|
482 | //@} |
---|
483 | }; |
---|
484 | #ifdef THREAD |
---|
485 | #include <pthread.h> |
---|
486 | typedef struct { |
---|
487 | double acceptablePivot; |
---|
488 | const ClpSimplex * model; |
---|
489 | double * spare; |
---|
490 | int * spareIndex; |
---|
491 | double * arrayTemp; |
---|
492 | int * indexTemp; |
---|
493 | int * numberInPtr; |
---|
494 | double * bestPossiblePtr; |
---|
495 | double * upperThetaPtr; |
---|
496 | int * posFreePtr; |
---|
497 | double * freePivotPtr; |
---|
498 | int * numberOutPtr; |
---|
499 | const unsigned short * count; |
---|
500 | const double * pi; |
---|
501 | const CoinBigIndex * rowStart; |
---|
502 | const double * element; |
---|
503 | const unsigned short * column; |
---|
504 | int offset; |
---|
505 | int numberInRowArray; |
---|
506 | int numberLook; |
---|
507 | } dualColumn0Struct; |
---|
508 | #endif |
---|
509 | class ClpPackedMatrix2 { |
---|
510 | |
---|
511 | public: |
---|
512 | /**@name Useful methods */ |
---|
513 | //@{ |
---|
514 | /** Return <code>x * -1 * A in <code>z</code>. |
---|
515 | Note - x packed and z will be packed mode |
---|
516 | Squashes small elements and knows about ClpSimplex */ |
---|
517 | void transposeTimes(const ClpSimplex * model, |
---|
518 | const CoinPackedMatrix * rowCopy, |
---|
519 | const CoinIndexedVector * x, |
---|
520 | CoinIndexedVector * spareArray, |
---|
521 | CoinIndexedVector * z) const; |
---|
522 | /// Returns true if copy has useful information |
---|
523 | inline bool usefulInfo() const { |
---|
524 | return rowStart_ != NULL; |
---|
525 | } |
---|
526 | //@} |
---|
527 | |
---|
528 | |
---|
529 | /**@name Constructors, destructor */ |
---|
530 | //@{ |
---|
531 | /** Default constructor. */ |
---|
532 | ClpPackedMatrix2(); |
---|
533 | /** Constructor from copy. */ |
---|
534 | ClpPackedMatrix2(ClpSimplex * model, const CoinPackedMatrix * rowCopy); |
---|
535 | /** Destructor */ |
---|
536 | virtual ~ClpPackedMatrix2(); |
---|
537 | //@} |
---|
538 | |
---|
539 | /**@name Copy method */ |
---|
540 | //@{ |
---|
541 | /** The copy constructor. */ |
---|
542 | ClpPackedMatrix2(const ClpPackedMatrix2&); |
---|
543 | ClpPackedMatrix2& operator=(const ClpPackedMatrix2&); |
---|
544 | //@} |
---|
545 | |
---|
546 | |
---|
547 | protected: |
---|
548 | /**@name Data members |
---|
549 | The data members are protected to allow access for derived classes. */ |
---|
550 | //@{ |
---|
551 | /// Number of blocks |
---|
552 | int numberBlocks_; |
---|
553 | /// Number of rows |
---|
554 | int numberRows_; |
---|
555 | /// Column offset for each block (plus one at end) |
---|
556 | int * offset_; |
---|
557 | /// Counts of elements in each part of row |
---|
558 | mutable unsigned short * count_; |
---|
559 | /// Row starts |
---|
560 | mutable CoinBigIndex * rowStart_; |
---|
561 | /// columns within block |
---|
562 | unsigned short * column_; |
---|
563 | /// work arrays |
---|
564 | double * work_; |
---|
565 | #ifdef THREAD |
---|
566 | pthread_t * threadId_; |
---|
567 | dualColumn0Struct * info_; |
---|
568 | #endif |
---|
569 | //@} |
---|
570 | }; |
---|
571 | typedef struct { |
---|
572 | CoinBigIndex startElements_; // point to data |
---|
573 | int startIndices_; // point to column_ |
---|
574 | int numberInBlock_; |
---|
575 | int numberPrice_; // at beginning |
---|
576 | int numberElements_; // number elements per column |
---|
577 | } blockStruct; |
---|
578 | class ClpPackedMatrix3 { |
---|
579 | |
---|
580 | public: |
---|
581 | /**@name Useful methods */ |
---|
582 | //@{ |
---|
583 | /** Return <code>x * -1 * A in <code>z</code>. |
---|
584 | Note - x packed and z will be packed mode |
---|
585 | Squashes small elements and knows about ClpSimplex */ |
---|
586 | void transposeTimes(const ClpSimplex * model, |
---|
587 | const double * pi, |
---|
588 | CoinIndexedVector * output) const; |
---|
589 | /// Updates two arrays for steepest |
---|
590 | void transposeTimes2(const ClpSimplex * model, |
---|
591 | const double * pi, CoinIndexedVector * dj1, |
---|
592 | const double * piWeight, |
---|
593 | double referenceIn, double devex, |
---|
594 | // Array for exact devex to say what is in reference framework |
---|
595 | unsigned int * reference, |
---|
596 | double * weights, double scaleFactor); |
---|
597 | //@} |
---|
598 | |
---|
599 | |
---|
600 | /**@name Constructors, destructor */ |
---|
601 | //@{ |
---|
602 | /** Default constructor. */ |
---|
603 | ClpPackedMatrix3(); |
---|
604 | /** Constructor from copy. */ |
---|
605 | ClpPackedMatrix3(ClpSimplex * model, const CoinPackedMatrix * columnCopy); |
---|
606 | /** Destructor */ |
---|
607 | virtual ~ClpPackedMatrix3(); |
---|
608 | //@} |
---|
609 | |
---|
610 | /**@name Copy method */ |
---|
611 | //@{ |
---|
612 | /** The copy constructor. */ |
---|
613 | ClpPackedMatrix3(const ClpPackedMatrix3&); |
---|
614 | ClpPackedMatrix3& operator=(const ClpPackedMatrix3&); |
---|
615 | //@} |
---|
616 | /**@name Sort methods */ |
---|
617 | //@{ |
---|
618 | /** Sort blocks */ |
---|
619 | void sortBlocks(const ClpSimplex * model); |
---|
620 | /// Swap one variable |
---|
621 | void swapOne(const ClpSimplex * model, const ClpPackedMatrix * matrix, |
---|
622 | int iColumn); |
---|
623 | //@} |
---|
624 | |
---|
625 | |
---|
626 | protected: |
---|
627 | /**@name Data members |
---|
628 | The data members are protected to allow access for derived classes. */ |
---|
629 | //@{ |
---|
630 | /// Number of blocks |
---|
631 | int numberBlocks_; |
---|
632 | /// Number of columns |
---|
633 | int numberColumns_; |
---|
634 | /// Column indices and reverse lookup (within block) |
---|
635 | int * column_; |
---|
636 | /// Starts for odd/long vectors |
---|
637 | CoinBigIndex * start_; |
---|
638 | /// Rows |
---|
639 | int * row_; |
---|
640 | /// Elements |
---|
641 | double * element_; |
---|
642 | /// Blocks (ordinary start at 0 and go to first block) |
---|
643 | blockStruct * block_; |
---|
644 | //@} |
---|
645 | }; |
---|
646 | |
---|
647 | #endif |
---|