Changeset 2385 for trunk/Clp/src/ClpPackedMatrix.hpp
 Timestamp:
 Jan 6, 2019 2:43:06 PM (4 months ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

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