Cbc  2.10.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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:
85  inline int getNumStructural() const { return numStructural_; }
87 
89  inline int getNumArtificial() const { return numArtificial_; }
90 
95  int numberBasicStructurals() const;
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 
291  virtual ~CoinWarmStartBasis();
292 
295  virtual CoinWarmStartBasis &operator=(const CoinWarmStartBasis &rhs);
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:
334  int numStructural_;
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 
371 const char *statusName(CoinWarmStartBasis::Status status);
380 
405 public:
407  virtual CoinWarmStartDiff *clone() const
408  {
410  return (dynamic_cast< CoinWarmStartDiff * >(cwsbd));
411  }
412 
415 
417  virtual ~CoinWarmStartBasisDiff();
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 *
453  CoinWarmStartBasis::generateDiff(const CoinWarmStart *const oldCWS) const;
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 */
virtual void assignBasisStatus(int ns, int na, char *&sStat, char *&aStat)
Assign the status vectors to be the warm start information.
virtual void resize(int newNumberRows, int newNumberColumns)
Set basis capacity; existing basis is maintained.
virtual void deleteColumns(int number, const int *which)
Delete a set of columns from the basis.
unsigned int * difference_
Array of diff indices and diff values.
CoinTriple< int, int, int > XferEntry
Transfer vector entry for mergeBasis(const CoinWarmStartBasis*,const XferVec*,const XferVec*) ...
bool fixFullBasis()
Returns true if full basis and fixes up (for debug)
CoinWarmStartBasis::Status charToStatus(char status)
Convert character to status.
virtual void setSize(int ns, int na)
Set basis capacity; existing basis is discarded.
virtual ~CoinWarmStartBasisDiff()
Destructor.
void setStatus(char *array, int i, CoinWarmStartBasis::Status st)
Set the status of the specified variable in the given status array.
virtual CoinWarmStart * clone() const
`Virtual constructor&#39;
Status getStructStatus(int i) const
Return the status of the specified structural variable.
void setStructStatus(int i, Status st)
Set the status of the specified structural variable.
int numStructural_
The number of structural variables.
CoinWarmStartBasis::Status getStatus(const char *array, int i)
Get the status of the specified variable in the given status array.
Not basic and not at bound.
CoinWarmStartBasisDiff()
Default constructor.
CoinWarmStartBasis()
Default constructor.
virtual void compressRows(int tgtCnt, const int *tgts)
Delete a set of rows from the basis.
The default COIN simplex (basis-oriented) warm start class.
void setArtifStatus(int i, Status st)
Set the status of the specified artificial variable.
const char * statusName(CoinPrePostsolveMatrix::Status status)
Generate a print string for a status code.
virtual void mergeBasis(const CoinWarmStartBasis *src, const XferVec *xferRows, const XferVec *xferCols)
Merge entries from a source basis into this basis.
char * getStructuralStatus()
Return the status array for the structural variables.
int numberBasicStructurals() const
Return the number of basic structurals.
int numArtificial_
The number of artificial variables.
A `diff&#39; between two CoinWarmStartBasis objects.
const char * getArtificialStatus() const
const overload for getArtificialStatus()
virtual void print() const
Prints in readable format (for debug)
bool fullBasis() const
Returns true if full basis (for debug)
virtual CoinWarmStartDiff * clone() const
`Virtual constructor&#39;
Nonbasic free variable.
Status getArtifStatus(int i) const
Return the status of the specified artificial variable.
int sze_
Number of entries (and allocated capacity), in units of int.
char * artificialStatus_
The status of the artificial variables.
char * structuralStatus_
The status of the structural variables.
int getNumStructural() const
Return the number of structural variables.
virtual CoinWarmStartDiff * generateDiff(const CoinWarmStart *const oldCWS) const
Generate a `diff&#39; that can convert the warm start basis passed as a parameter to the warm start basis...
int maxSize_
The maximum sise (in ints - actually 4*char) (so resize does not need to do new)
Copyright (C) 2000 – 2003, International Business Machines Corporation and others.
const char * getStructuralStatus() const
const overload for getStructuralStatus()
virtual CoinWarmStartBasisDiff & operator=(const CoinWarmStartBasisDiff &rhs)
Assignment.
Abstract base class for warm start `diff&#39; objects.
virtual ~CoinWarmStartBasis()
Destructor.
std::vector< XferEntry > XferVec
Transfer vector for mergeBasis(const CoinWarmStartBasis*,const XferVec*,const XferVec*) ...
Status
Enum for status of variables.
int getNumArtificial() const
Return the number of artificial variables.
virtual CoinWarmStartBasis & operator=(const CoinWarmStartBasis &rhs)
Assignment.
char * getArtificialStatus()
As for getStructuralStatus , but returns the status array for the artificial variables.
virtual void deleteRows(int rawTgtCnt, const int *rawTgts)
Delete a set of rows from the basis.
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...
virtual void applyDiff(const CoinWarmStartDiff *const cwsdDiff)
Apply diff to this basis.
Abstract base class for warm start information.