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