1 /* $Id: CoinWarmStartDual.hpp 2083 2019-01-06 19:38:09Z unxusr $ */
2 // Copyright (C) 2000, 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 CoinWarmStartDual_H
7 #define CoinWarmStartDual_H
8 
9 #include "CoinHelperFunctions.hpp"
10 #include "CoinWarmStart.hpp"
11 #include "CoinWarmStartVector.hpp"
12 
13 //#############################################################################
14 
15 /** WarmStart information that is only a dual vector */
16 
17 class CoinWarmStartDual : public virtual CoinWarmStart {
18 public:
19   /// return the size of the dual vector
size() const20   inline int size() const { return dual_.size(); }
21   /// return a pointer to the array of duals
dual() const22   inline const double *dual() const { return dual_.values(); }
23 
24   /** Assign the dual vector to be the warmstart information. In this method
25        the object assumes ownership of the pointer and upon return "dual" will
26        be a NULL pointer. If copying is desirable use the constructor. */
assignDual(int size,double * & dual)27   inline void assignDual(int size, double *&dual)
28   {
29     dual_.assignVector(size, dual);
30   }
31 
CoinWarmStartDual()32   CoinWarmStartDual() {}
33 
CoinWarmStartDual(int size,const double * dual)34   CoinWarmStartDual(int size, const double *dual)
35     : dual_(size, dual)
36   {
37   }
38 
CoinWarmStartDual(const CoinWarmStartDual & rhs)39   CoinWarmStartDual(const CoinWarmStartDual &rhs)
40     : dual_(rhs.dual_)
41   {
42   }
43 
operator =(const CoinWarmStartDual & rhs)44   CoinWarmStartDual &operator=(const CoinWarmStartDual &rhs)
45   {
46     if (this != &rhs) {
47       dual_ = rhs.dual_;
48     }
49     return *this;
50   }
51 
52   /** `Virtual constructor' */
clone() const53   virtual CoinWarmStart *clone() const
54   {
55     return new CoinWarmStartDual(*this);
56   }
57 
~CoinWarmStartDual()58   virtual ~CoinWarmStartDual() {}
59 
60   /*! \name Dual warm start `diff' methods */
61   //@{
62 
63   /*! \brief Generate a `diff' that can convert the warm start passed as a
64 	     parameter to the warm start specified by \c this.
65 
66     The capabilities are limited: the basis passed as a parameter can be no
67     larger than the basis pointed to by \c this.
68   */
69 
70   virtual CoinWarmStartDiff *
71   generateDiff(const CoinWarmStart *const oldCWS) const;
72 
73   /*! \brief Apply \p diff to this warm start.
74 
75     Update this warm start by applying \p diff. It's assumed that the
76     allocated capacity of the warm start is sufficiently large.
77   */
78 
79   virtual void applyDiff(const CoinWarmStartDiff *const cwsdDiff);
80 
81 #if 0
82 protected:
83   inline const CoinWarmStartVector<double>& warmStartVector() const { return dual_; }
84 #endif
85 
86   //@}
87 
88 private:
89   ///@name Private data members
90   CoinWarmStartVector< double > dual_;
91 };
92 
93 //#############################################################################
94 
95 /*! \class CoinWarmStartDualDiff
96     \brief A `diff' between two CoinWarmStartDual objects
97 
98   This class exists in order to hide from the world the details of
99   calculating and representing a `diff' between two CoinWarmStartDual
100   objects. For convenience, assignment, cloning, and deletion are visible to
101   the world, and default and copy constructors are made available to derived
102   classes.  Knowledge of the rest of this structure, and of generating and
103   applying diffs, is restricted to the friend functions
104   CoinWarmStartDual::generateDiff() and CoinWarmStartDual::applyDiff().
105 
106   The actual data structure is a pair of vectors, #diffNdxs_ and #diffVals_.
107 
108 */
109 
110 class CoinWarmStartDualDiff : public virtual CoinWarmStartDiff {
111 public:
112   /*! \brief `Virtual constructor' */
clone() const113   virtual CoinWarmStartDiff *clone() const
114   {
115     return new CoinWarmStartDualDiff(*this);
116   }
117 
118   /*! \brief Assignment */
operator =(const CoinWarmStartDualDiff & rhs)119   virtual CoinWarmStartDualDiff &operator=(const CoinWarmStartDualDiff &rhs)
120   {
121     if (this != &rhs) {
122       diff_ = rhs.diff_;
123     }
124     return *this;
125   }
126 
127   /*! \brief Destructor */
~CoinWarmStartDualDiff()128   virtual ~CoinWarmStartDualDiff() {}
129 
130 protected:
131   /*! \brief Default constructor
132 
133     This is protected (rather than private) so that derived classes can
134     see it when they make <i>their</i> default constructor protected or
135     private.
136   */
CoinWarmStartDualDiff()137   CoinWarmStartDualDiff()
138     : diff_()
139   {
140   }
141 
142   /*! \brief Copy constructor
143 
144     For convenience when copying objects containing CoinWarmStartDualDiff
145     objects. But consider whether you should be using #clone() to retain
146     polymorphism.
147 
148     This is protected (rather than private) so that derived classes can
149     see it when the make <i>their</i> copy constructor protected or
150     private.
151   */
CoinWarmStartDualDiff(const CoinWarmStartDualDiff & rhs)152   CoinWarmStartDualDiff(const CoinWarmStartDualDiff &rhs)
153     : diff_(rhs.diff_)
154   {
155   }
156 
157 private:
158   friend CoinWarmStartDiff *
159   CoinWarmStartDual::generateDiff(const CoinWarmStart *const oldCWS) const;
160   friend void
161   CoinWarmStartDual::applyDiff(const CoinWarmStartDiff *const diff);
162 
163   /*! \brief Standard constructor */
CoinWarmStartDualDiff(int sze,const unsigned int * const diffNdxs,const double * const diffVals)164   CoinWarmStartDualDiff(int sze, const unsigned int *const diffNdxs,
165     const double *const diffVals)
166     : diff_(sze, diffNdxs, diffVals)
167   {
168   }
169 
170   /*!
171       \brief The difference in the dual vector is simply the difference in a
172       vector.
173   */
174   CoinWarmStartVectorDiff< double > diff_;
175 };
176 
177 #endif
178 
179 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
180 */
181