Clp 1.17.6

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AbcNonLinearCost.hpp
Go to the documentation of this file.
1 /* $Id: AbcNonLinearCost.hpp 2385 2019-01-06 19:43:06Z unxusr $ */
2 // Copyright (C) 2002, International Business Machines
3 // Corporation and others, Copyright (C) 2012, FasterCoin. All Rights Reserved.
4 // This code is licensed under the terms of the Eclipse Public License (EPL).
5
6 #ifndef AbcNonLinearCost_H
7 #define AbcNonLinearCost_H
8
9 #include "CoinPragma.hpp"
10 #include "AbcCommon.hpp"
11
12 class AbcSimplex;
13 class CoinIndexedVector;
14
32 /* status has original status and current status
33 0 - below lower so stored is upper
34 1 - in range
35 2 - above upper so stored is lower
36 4 - (for current) - same as original
37 */
38 #define CLP_BELOW_LOWER 0
39 #define CLP_FEASIBLE 1
40 #define CLP_ABOVE_UPPER 2
41 #define CLP_SAME 4
42 #ifndef ClpNonLinearCost_H
43 inline int originalStatus(unsigned char status)
44 {
45 return (status & 15);
46 }
47 inline int currentStatus(unsigned char status)
48 {
49 return (status >> 4);
50 }
51 inline void setOriginalStatus(unsigned char &status, int value)
52 {
53 status = static_cast< unsigned char >(status & ~15);
54 status = static_cast< unsigned char >(status | value);
55 }
56 inline void setCurrentStatus(unsigned char &status, int value)
57 {
58 status = static_cast< unsigned char >(status & ~(15 << 4));
59 status = static_cast< unsigned char >(status | (value << 4));
60 }
61 inline void setInitialStatus(unsigned char &status)
62 {
63 status = static_cast< unsigned char >(CLP_FEASIBLE | (CLP_SAME << 4));
64 }
65 inline void setSameStatus(unsigned char &status)
66 {
67 status = static_cast< unsigned char >(status & ~(15 << 4));
68 status = static_cast< unsigned char >(status | (CLP_SAME << 4));
69 }
70 #endif
71 class AbcNonLinearCost {
72
73 public:
76 AbcNonLinearCost();
82 AbcNonLinearCost(AbcSimplex *model);
84 ~AbcNonLinearCost();
85 // Copy
86 AbcNonLinearCost(const AbcNonLinearCost &);
87 // Assignment
88 AbcNonLinearCost &operator=(const AbcNonLinearCost &);
90
97 void checkInfeasibilities(double oldTolerance = 0.0);
101 void checkInfeasibilities(int numberInArray, const int *index);
108 void checkChanged(int numberInArray, CoinIndexedVector *update);
115 void goThru(int numberInArray, double multiplier,
116 const int *index, const double *work,
117 double *rhs);
120 void goBack(int numberInArray, const int *index,
121 double *rhs);
127 void goBackAll(const CoinIndexedVector *update);
129 void zapCosts();
131 void refreshCosts(const double *columnCosts);
133 void feasibleBounds();
135 void refresh();
137 void refreshFromPerturbed(double tolerance);
141 double setOne(int sequence, double solutionValue);
145 double setOneBasic(int iRow, double solutionValue);
149 int setOneOutgoing(int sequence, double &solutionValue);
151 double nearest(int iRow, double solutionValue);
155 inline double changeInCost(int /*sequence*/, double alpha) const
156 {
157 return (alpha > 0.0) ? infeasibilityWeight_ : -infeasibilityWeight_;
158 }
159 inline double changeUpInCost(int /*sequence*/) const
160 {
161 return -infeasibilityWeight_;
162 }
163 inline double changeDownInCost(int /*sequence*/) const
164 {
165 return infeasibilityWeight_;
166 }
168 inline double changeInCost(int iRow, double alpha, double &rhs)
169 {
170 int sequence = model_->pivotVariable()[iRow];
171 double returnValue = 0.0;
172 unsigned char iStatus = status_[sequence];
173 int iWhere = currentStatus(iStatus);
174 if (iWhere == CLP_SAME)
175 iWhere = originalStatus(iStatus);
176 // rhs always increases
177 if (iWhere == CLP_FEASIBLE) {
178 if (alpha > 0.0) {
179 // going below
180 iWhere = CLP_BELOW_LOWER;
181 rhs = COIN_DBL_MAX;
182 } else {
183 // going above
184 iWhere = CLP_ABOVE_UPPER;
185 rhs = COIN_DBL_MAX;
186 }
187 } else if (iWhere == CLP_BELOW_LOWER) {
188 assert(alpha < 0);
189 // going feasible
190 iWhere = CLP_FEASIBLE;
191 rhs += bound_[sequence] - model_->upperRegion()[sequence];
192 } else {
193 assert(iWhere == CLP_ABOVE_UPPER);
194 // going feasible
195 iWhere = CLP_FEASIBLE;
196 rhs += model_->lowerRegion()[sequence] - bound_[sequence];
197 }
198 setCurrentStatus(status_[sequence], iWhere);
199 returnValue = fabs(alpha) * infeasibilityWeight_;
200 return returnValue;
201 }
203
206 inline int numberInfeasibilities() const
208 {
209 return numberInfeasibilities_;
210 }
212 inline double changeInCost() const
213 {
214 return changeCost_;
215 }
217 inline double feasibleCost() const
218 {
219 return feasibleCost_;
220 }
222 double feasibleReportCost() const;
224 inline double sumInfeasibilities() const
225 {
226 return sumInfeasibilities_;
227 }
229 inline double largestInfeasibility() const
230 {
231 return largestInfeasibility_;
232 }
234 inline double averageTheta() const
235 {
236 return averageTheta_;
237 }
238 inline void setAverageTheta(double value)
239 {
240 averageTheta_ = value;
241 }
242 inline void setChangeInCost(double value)
243 {
244 changeCost_ = value;
245 }
247 inline unsigned char *statusArray() const
249 {
250 return status_;
251 }
252 inline int getCurrentStatus(int sequence)
253 {
254 return (status_[sequence] >> 4);
255 }
257 void validate();
259
260 private:
263 double changeCost_;
266 double feasibleCost_;
268 double infeasibilityWeight_;
270 double largestInfeasibility_;
272 double sumInfeasibilities_;
274 double averageTheta_;
276 int numberRows_;
278 int numberColumns_;
280 AbcSimplex *model_;
282 int numberInfeasibilities_;
283 // new stuff
285 unsigned char *status_;
287 double *bound_;
289 double *cost_;
291 };
292
293 #endif
294
295 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
296 */
AbcNonLinearCost::setAverageTheta
void setAverageTheta(double value)
Definition: AbcNonLinearCost.hpp:238
AbcNonLinearCost::validate
void validate()
For debug.
AbcNonLinearCost::changeInCost
double changeInCost() const
Change in cost.
Definition: AbcNonLinearCost.hpp:212
AbcNonLinearCost::changeUpInCost
double changeUpInCost(int) const
Definition: AbcNonLinearCost.hpp:159
AbcNonLinearCost::averageTheta_
double averageTheta_
Average theta - kept here as only for primal.
Definition: AbcNonLinearCost.hpp:274
AbcNonLinearCost::changeDownInCost
double changeDownInCost(int) const
Definition: AbcNonLinearCost.hpp:163
CLP_ABOVE_UPPER
#define CLP_ABOVE_UPPER
Definition: AbcNonLinearCost.hpp:40
AbcNonLinearCost::feasibleCost
double feasibleCost() const
Feasible cost.
Definition: AbcNonLinearCost.hpp:217
AbcNonLinearCost::bound_
double * bound_
Bound which has been replaced in lower_ or upper_.
Definition: AbcNonLinearCost.hpp:287
AbcSimplex
Definition: AbcSimplex.hpp:62
AbcNonLinearCost::model_
AbcSimplex * model_
Model.
Definition: AbcNonLinearCost.hpp:280
AbcNonLinearCost::AbcNonLinearCost
AbcNonLinearCost()
Default constructor.
AbcNonLinearCost::operator=
AbcNonLinearCost & operator=(const AbcNonLinearCost &)
AbcNonLinearCost::numberInfeasibilities_
int numberInfeasibilities_
Number of infeasibilities found.
Definition: AbcNonLinearCost.hpp:282
CLP_FEASIBLE
#define CLP_FEASIBLE
Definition: AbcNonLinearCost.hpp:39
AbcNonLinearCost::goBack
void goBack(int numberInArray, const int *index, double *rhs)
Takes off last iteration (i.e.
AbcNonLinearCost::sumInfeasibilities
double sumInfeasibilities() const
Sum of infeasibilities.
Definition: AbcNonLinearCost.hpp:224
AbcNonLinearCost::refresh
void refresh()
Refresh - assuming regions OK.
setCurrentStatus
void setCurrentStatus(unsigned char &status, int value)
Definition: AbcNonLinearCost.hpp:56
AbcNonLinearCost::numberColumns_
int numberColumns_
Number of columns (mainly for checking and copy)
Definition: AbcNonLinearCost.hpp:278
AbcSimplex::lowerRegion
double * lowerRegion() const
Definition: AbcSimplex.hpp:598
AbcNonLinearCost::feasibleBounds
void feasibleBounds()
Puts feasible bounds into lower and upper.
AbcSimplex::upperRegion
double * upperRegion() const
Definition: AbcSimplex.hpp:602
AbcNonLinearCost::largestInfeasibility
double largestInfeasibility() const
Largest infeasibility.
Definition: AbcNonLinearCost.hpp:229
AbcNonLinearCost::infeasibilityWeight_
double infeasibilityWeight_
Current infeasibility weight.
Definition: AbcNonLinearCost.hpp:268
AbcNonLinearCost::goThru
void goThru(int numberInArray, double multiplier, const int *index, const double *work, double *rhs)
Goes through one bound for each variable.
CLP_SAME
#define CLP_SAME
Definition: AbcNonLinearCost.hpp:41
AbcNonLinearCost::changeCost_
double changeCost_
Change in cost because of infeasibilities.
Definition: AbcNonLinearCost.hpp:264
AbcNonLinearCost::~AbcNonLinearCost
~AbcNonLinearCost()
Destructor.
AbcNonLinearCost::numberInfeasibilities
int numberInfeasibilities() const
Number of infeasibilities.
Definition: AbcNonLinearCost.hpp:207
AbcNonLinearCost::refreshFromPerturbed
void refreshFromPerturbed(double tolerance)
Refresh - from original.
AbcCommon.hpp
AbcNonLinearCost::statusArray
unsigned char * statusArray() const
Definition: AbcNonLinearCost.hpp:248
CoinIndexedVector
Indexed Vector.
Definition: CoinIndexedVector.hpp:104
CoinPragma.hpp
AbcNonLinearCost::setOneBasic
double setOneBasic(int iRow, double solutionValue)
Sets bounds and cost for one variable Returns change in cost May need to be inline for speed...
AbcNonLinearCost::sumInfeasibilities_
double sumInfeasibilities_
Sum of infeasibilities.
Definition: AbcNonLinearCost.hpp:272
AbcNonLinearCost::feasibleCost_
double feasibleCost_
Feasible cost.
Definition: AbcNonLinearCost.hpp:266
AbcNonLinearCost::changeInCost
double changeInCost(int, double alpha) const
Returns change in cost - one down if alpha &gt;0.0, up if &lt;0.0 Value is current - new.
Definition: AbcNonLinearCost.hpp:155
AbcNonLinearCost::setOne
double setOne(int sequence, double solutionValue)
Sets bounds and cost for one variable Returns change in cost May need to be inline for speed...
AbcNonLinearCost::zapCosts
void zapCosts()
Temporary zeroing of feasible costs.
AbcNonLinearCost::setChangeInCost
void setChangeInCost(double value)
Definition: AbcNonLinearCost.hpp:242
currentStatus
int currentStatus(unsigned char status)
Definition: AbcNonLinearCost.hpp:47
AbcNonLinearCost::setOneOutgoing
int setOneOutgoing(int sequence, double &solutionValue)
Sets bounds and cost for outgoing variable may change value Returns direction.
originalStatus
int originalStatus(unsigned char status)
Definition: AbcNonLinearCost.hpp:43
AbcNonLinearCost::refreshCosts
void refreshCosts(const double *columnCosts)
Refreshes costs always makes row costs zero.
AbcNonLinearCost::cost_
double * cost_
Feasible cost array.
Definition: AbcNonLinearCost.hpp:289
setSameStatus
void setSameStatus(unsigned char &status)
Definition: AbcNonLinearCost.hpp:65
AbcNonLinearCost::largestInfeasibility_
double largestInfeasibility_
Largest infeasibility.
Definition: AbcNonLinearCost.hpp:270
AbcNonLinearCost::getCurrentStatus
int getCurrentStatus(int sequence)
Definition: AbcNonLinearCost.hpp:252
setOriginalStatus
void setOriginalStatus(unsigned char &status, int value)
Definition: AbcNonLinearCost.hpp:51
AbcNonLinearCost::status_
unsigned char * status_
Contains status at beginning and current.
Definition: AbcNonLinearCost.hpp:285
AbcNonLinearCost::goBackAll
void goBackAll(const CoinIndexedVector *update)
Puts back correct infeasible costs for each variable The input indices are row indices and need conve...
AbcNonLinearCost::numberRows_
int numberRows_
Number of rows (mainly for checking and copy)
Definition: AbcNonLinearCost.hpp:276
setInitialStatus
void setInitialStatus(unsigned char &status)
Definition: AbcNonLinearCost.hpp:61
COIN_DBL_MAX
const double COIN_DBL_MAX
Definition: CoinFinite.hpp:18
AbcNonLinearCost::checkInfeasibilities
void checkInfeasibilities(double oldTolerance=0.0)
Changes infeasible costs and computes number and cost of infeas Puts all non-basic (non free) variabl...
AbcNonLinearCost::feasibleReportCost
double feasibleReportCost() const
Feasible cost with offset and direction (i.e. for reporting)
AbcNonLinearCost::averageTheta
double averageTheta() const
Average theta.
Definition: AbcNonLinearCost.hpp:234
AbcNonLinearCost::checkChanged
void checkChanged(int numberInArray, CoinIndexedVector *update)
Puts back correct infeasible costs for each variable The input indices are row indices and need conve...
AbcNonLinearCost::changeInCost
double changeInCost(int iRow, double alpha, double &rhs)
This also updates next bound.
Definition: AbcNonLinearCost.hpp:168
CLP_BELOW_LOWER
#define CLP_BELOW_LOWER
Trivial class to deal with non linear costs.
Definition: AbcNonLinearCost.hpp:38
AbcNonLinearCost
Definition: AbcNonLinearCost.hpp:71
AbcNonLinearCost::nearest
double nearest(int iRow, double solutionValue)
Returns nearest bound.
AbcSimplex::pivotVariable
int * pivotVariable() const
Basic variables pivoting on which rows may be same as toExternal but may be as at invert...
Definition: AbcSimplex.hpp:465