CoinUtils  2.11.4
CoinWarmStartBasis.hpp
Go to the documentation of this file.
1 /* $Id: CoinWarmStartBasis.hpp 2083 2019-01-06 19:38:09Z unxusr $ */
13 #ifndef CoinWarmStartBasis_H
14 #define CoinWarmStartBasis_H
15 
16 #include <vector>
17 
18 #include "CoinSort.hpp"
19 #include "CoinHelperFunctions.hpp"
20 #include "CoinWarmStart.hpp"
21 
22 //#############################################################################
23 
40 class CoinWarmStartBasis : public virtual CoinWarmStart {
41 public:
56  enum Status {
57  isFree = 0x00,
58  basic = 0x01,
59  atUpperBound = 0x02,
60  atLowerBound = 0x03,
61  superBasic = 0x04
62  };
63 
68 
72  typedef std::vector< XferEntry > XferVec;
73 
74 public:
86  inline int getNumStructural() const { return numStructural_; }
87 
89  inline int getNumArtificial() const { return numArtificial_; }
90 
96 
98  inline Status getStructStatus(int i) const
99  {
100  const int st = (structuralStatus_[i >> 2] >> ((i & 3) << 1)) & 3;
101  return static_cast< CoinWarmStartBasis::Status >(st);
102  }
103 
105  inline void setStructStatus(int i, Status st)
106  {
107  char &st_byte = structuralStatus_[i >> 2];
108  st_byte = static_cast< char >(st_byte & ~(3 << ((i & 3) << 1)));
109  st_byte = static_cast< char >(st_byte | (st << ((i & 3) << 1)));
110  }
111 
117  inline char *getStructuralStatus() { return structuralStatus_; }
118 
124  inline const char *getStructuralStatus() const { return structuralStatus_; }
125 
129  inline char *getArtificialStatus() { return artificialStatus_; }
130 
132  inline Status getArtifStatus(int i) const
133  {
134  const int st = (artificialStatus_[i >> 2] >> ((i & 3) << 1)) & 3;
135  return static_cast< CoinWarmStartBasis::Status >(st);
136  }
137 
139  inline void setArtifStatus(int i, Status st)
140  {
141  char &st_byte = artificialStatus_[i >> 2];
142  st_byte = static_cast< char >(st_byte & ~(3 << ((i & 3) << 1)));
143  st_byte = static_cast< char >(st_byte | (st << ((i & 3) << 1)));
144  }
145 
151  inline const char *getArtificialStatus() const { return artificialStatus_; }
153 
156 
164  virtual CoinWarmStartDiff *
165  generateDiff(const CoinWarmStart *const oldCWS) const;
166 
173  virtual void
174  applyDiff(const CoinWarmStartDiff *const cwsdDiff);
175 
177 
180 
186  virtual void setSize(int ns, int na);
187 
196  virtual void resize(int newNumberRows, int newNumberColumns);
197 
214  virtual void compressRows(int tgtCnt, const int *tgts);
215 
227  virtual void deleteRows(int rawTgtCnt, const int *rawTgts);
228 
239  virtual void deleteColumns(int number, const int *which);
240 
253  virtual void mergeBasis(const CoinWarmStartBasis *src,
254  const XferVec *xferRows,
255  const XferVec *xferCols);
256 
258 
262 
269 
279  CoinWarmStartBasis(int ns, int na, const char *sStat, const char *aStat);
280 
283 
285  virtual CoinWarmStart *clone() const
286  {
287  return new CoinWarmStartBasis(*this);
288  }
289 
292 
296 
312  virtual void assignBasisStatus(int ns, int na, char *&sStat, char *&aStat);
314 
317 
319  virtual void print() const;
321  bool fullBasis() const;
323  bool fixFullBasis();
324 
326 
327 protected:
339  int maxSize_;
345 };
346 
351 inline CoinWarmStartBasis::Status getStatus(const char *array, int i)
352 {
353  const int st = (array[i >> 2] >> ((i & 3) << 1)) & 3;
354  return static_cast< CoinWarmStartBasis::Status >(st);
355 }
356 
361 inline void setStatus(char *array, int i, CoinWarmStartBasis::Status st)
362 {
363  char &st_byte = array[i >> 2];
364  st_byte = static_cast< char >(st_byte & ~(3 << ((i & 3) << 1)));
365  st_byte = static_cast< char >(st_byte | (st << ((i & 3) << 1)));
366 }
367 
380 
405 public:
407  virtual CoinWarmStartDiff *clone() const
408  {
410  return (dynamic_cast< CoinWarmStartDiff * >(cwsbd));
411  }
412 
415 
418 
419 protected:
427  : sze_(0)
428  , difference_(0)
429  {
430  }
431 
443 
445  CoinWarmStartBasisDiff(int sze, const unsigned int *const diffNdxs,
446  const unsigned int *const diffVals);
447 
450 
451 private:
452  friend CoinWarmStartDiff *
454  friend void
456 
458  int sze_;
459 
462  unsigned int *difference_;
463 };
464 
465 #endif
466 
467 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
468 */
char statusToChar(CoinWarmStartBasis::Status status)
In an example Aleksandr Kazachkov sent to me, I noticed he was using code as above but with char - it...
CoinWarmStartBasis::Status charToStatus(char status)
Convert character to status.
\legal Copyright (C) 2000 – 2003, International Business Machines Corporation and others.
A ‘diff’ between two CoinWarmStartBasis objects.
unsigned int * difference_
Array of diff indices and diff values.
CoinWarmStartBasisDiff(const CoinWarmStartBasisDiff &cwsbd)
Copy constructor.
CoinWarmStartBasisDiff(const CoinWarmStartBasis *rhs)
Constructor when full is smaller than diff!
virtual ~CoinWarmStartBasisDiff()
Destructor.
CoinWarmStartBasisDiff(int sze, const unsigned int *const diffNdxs, const unsigned int *const diffVals)
Standard constructor.
virtual CoinWarmStartBasisDiff & operator=(const CoinWarmStartBasisDiff &rhs)
Assignment.
virtual CoinWarmStartDiff * clone() const
‘Virtual constructor’
int sze_
Number of entries (and allocated capacity), in units of int.
CoinWarmStartBasisDiff()
Default constructor.
The default COIN simplex (basis-oriented) warm start class.
virtual CoinWarmStartDiff * generateDiff(const CoinWarmStart *const oldCWS) const
Generate a ‘diff’ that can convert the warm start basis passed as a parameter to the warm start basis...
CoinWarmStartBasis(const CoinWarmStartBasis &ws)
Copy constructor.
int numStructural_
The number of structural variables.
virtual void compressRows(int tgtCnt, const int *tgts)
Delete a set of rows from the basis.
bool fullBasis() const
Returns true if full basis (for debug)
int maxSize_
The maximum sise (in ints - actually 4*char) (so resize does not need to do new)
void setArtifStatus(int i, Status st)
Set the status of the specified artificial variable.
virtual void applyDiff(const CoinWarmStartDiff *const cwsdDiff)
Apply diff to this basis.
char * getArtificialStatus()
As for getStructuralStatus , but returns the status array for the artificial variables.
virtual void print() const
Prints in readable format (for debug)
int numberBasicStructurals() const
Return the number of basic structurals.
void setStatus(char *array, int i, CoinWarmStartBasis::Status st)
Set the status of the specified variable in the given status array.
CoinWarmStartBasis()
Default constructor.
Status getArtifStatus(int i) const
Return the status of the specified artificial variable.
virtual void resize(int newNumberRows, int newNumberColumns)
Set basis capacity; existing basis is maintained.
char * getStructuralStatus()
Return the status array for the structural variables.
CoinTriple< int, int, int > XferEntry
Transfer vector entry for mergeBasis(const CoinWarmStartBasis*,const XferVec*,const XferVec*)
CoinWarmStartBasis::Status getStatus(const char *array, int i)
Get the status of the specified variable in the given status array.
int getNumArtificial() const
Return the number of artificial variables.
virtual void deleteColumns(int number, const int *which)
Delete a set of columns from the basis.
virtual CoinWarmStartBasis & operator=(const CoinWarmStartBasis &rhs)
Assignment.
virtual void deleteRows(int rawTgtCnt, const int *rawTgts)
Delete a set of rows from the basis.
char * structuralStatus_
The status of the structural variables.
const char * getStructuralStatus() const
const overload for getStructuralStatus()
int numArtificial_
The number of artificial variables.
int getNumStructural() const
Return the number of structural variables.
virtual void assignBasisStatus(int ns, int na, char *&sStat, char *&aStat)
Assign the status vectors to be the warm start information.
std::vector< XferEntry > XferVec
Transfer vector for mergeBasis(const CoinWarmStartBasis*,const XferVec*,const XferVec*)
void setStructStatus(int i, Status st)
Set the status of the specified structural variable.
const char * statusName(CoinWarmStartBasis::Status status)
Generate a print string for a status code.
virtual CoinWarmStart * clone() const
‘Virtual constructor’
const char * getArtificialStatus() const
const overload for getArtificialStatus()
Status
Enum for status of variables.
@ basic
Basic variable.
@ isFree
Nonbasic free variable.
@ superBasic
Not basic and not at bound.
@ atUpperBound
Nonbasic at upper bound.
@ atLowerBound
Nonbasic at lower bound.
virtual void setSize(int ns, int na)
Set basis capacity; existing basis is discarded.
virtual void mergeBasis(const CoinWarmStartBasis *src, const XferVec *xferRows, const XferVec *xferCols)
Merge entries from a source basis into this basis.
char * artificialStatus_
The status of the artificial variables.
Status getStructStatus(int i) const
Return the status of the specified structural variable.
bool fixFullBasis()
Returns true if full basis and fixes up (for debug)
virtual ~CoinWarmStartBasis()
Destructor.
CoinWarmStartBasis(int ns, int na, const char *sStat, const char *aStat)
Constructs a warm start object with the specified status vectors.
Abstract base class for warm start ‘diff’ objects.
Abstract base class for warm start information.