Cgl 0.59.7

- 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 2024 2014-03-07 17:18:15Z forrest $ */
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
10 #include "CoinPragma.hpp"
11 #include "AbcCommon.hpp"
12
13 class AbcSimplex;
14 class CoinIndexedVector;
15
33 /* status has original status and current status
34 0 - below lower so stored is upper
35 1 - in range
36 2 - above upper so stored is lower
37 4 - (for current) - same as original
38 */
39 #define CLP_BELOW_LOWER 0
40 #define CLP_FEASIBLE 1
41 #define CLP_ABOVE_UPPER 2
42 #define CLP_SAME 4
43 #ifndef ClpNonLinearCost_H
44 inline int originalStatus(unsigned char status)
45 {
46 return (status & 15);
47 }
48 inline int currentStatus(unsigned char status)
49 {
50 return (status >> 4);
51 }
52 inline void setOriginalStatus(unsigned char & status, int value)
53 {
54 status = static_cast<unsigned char>(status & ~15);
55 status = static_cast<unsigned char>(status | value);
56 }
57 inline void setCurrentStatus(unsigned char &status, int value)
58 {
59 status = static_cast<unsigned char>(status & ~(15 << 4));
60 status = static_cast<unsigned char>(status | (value << 4));
61 }
62 inline void setInitialStatus(unsigned char &status)
63 {
64 status = static_cast<unsigned char>(CLP_FEASIBLE | (CLP_SAME << 4));
65 }
66 inline void setSameStatus(unsigned char &status)
67 {
68 status = static_cast<unsigned char>(status & ~(15 << 4));
69 status = static_cast<unsigned char>(status | (CLP_SAME << 4));
70 }
71 #endif
72 class AbcNonLinearCost {
73
74 public:
75
78 AbcNonLinearCost();
84 AbcNonLinearCost(AbcSimplex * model);
86 ~AbcNonLinearCost();
87 // Copy
88 AbcNonLinearCost(const AbcNonLinearCost&);
89 // Assignment
90 AbcNonLinearCost& operator=(const AbcNonLinearCost&);
92
93
100 void checkInfeasibilities(double oldTolerance = 0.0);
104 void checkInfeasibilities(int numberInArray, const int * index);
111 void checkChanged(int numberInArray, CoinIndexedVector * update);
118 void goThru(int numberInArray, double multiplier,
119 const int * index, const double * work,
120 double * rhs);
123 void goBack(int numberInArray, const int * index,
124 double * rhs);
130 void goBackAll(const CoinIndexedVector * update);
132 void zapCosts();
134 void refreshCosts(const double * columnCosts);
136 void feasibleBounds();
138 void refresh();
140 void refreshFromPerturbed(double tolerance);
144 double setOne(int sequence, double solutionValue);
148 double setOneBasic(int iRow, double solutionValue);
152 int setOneOutgoing(int sequence, double &solutionValue);
154 double nearest(int iRow, double solutionValue);
158 inline double changeInCost(int /*sequence*/, double alpha) const {
159 return (alpha > 0.0) ? infeasibilityWeight_ : -infeasibilityWeight_;
160 }
161 inline double changeUpInCost(int /*sequence*/) const {
162 return -infeasibilityWeight_;
163 }
164 inline double changeDownInCost(int /*sequence*/) const {
165 return infeasibilityWeight_;
166 }
168 inline double changeInCost(int iRow, double alpha, double &rhs) {
169 int sequence=model_->pivotVariable()[iRow];
170 double returnValue = 0.0;
171 unsigned char iStatus = status_[sequence];
172 int iWhere = currentStatus(iStatus);
173 if (iWhere == CLP_SAME)
174 iWhere = originalStatus(iStatus);
175 // rhs always increases
176 if (iWhere == CLP_FEASIBLE) {
177 if (alpha > 0.0) {
178 // going below
179 iWhere = CLP_BELOW_LOWER;
180 rhs = COIN_DBL_MAX;
181 } else {
182 // going above
183 iWhere = CLP_ABOVE_UPPER;
184 rhs = COIN_DBL_MAX;
185 }
186 } else if (iWhere == CLP_BELOW_LOWER) {
187 assert (alpha < 0);
188 // going feasible
189 iWhere = CLP_FEASIBLE;
190 rhs += bound_[sequence] - model_->upperRegion()[sequence];
191 } else {
192 assert (iWhere == CLP_ABOVE_UPPER);
193 // going feasible
194 iWhere = CLP_FEASIBLE;
195 rhs += model_->lowerRegion()[sequence] - bound_[sequence];
196 }
197 setCurrentStatus(status_[sequence], iWhere);
198 returnValue = fabs(alpha) * infeasibilityWeight_;
199 return returnValue;
200 }
202
203
206 inline int numberInfeasibilities() const {
208 return numberInfeasibilities_;
209 }
211 inline double changeInCost() const {
212 return changeCost_;
213 }
215 inline double feasibleCost() const {
216 return feasibleCost_;
217 }
219 double feasibleReportCost() const;
221 inline double sumInfeasibilities() const {
222 return sumInfeasibilities_;
223 }
225 inline double largestInfeasibility() const {
226 return largestInfeasibility_;
227 }
229 inline double averageTheta() const {
230 return averageTheta_;
231 }
232 inline void setAverageTheta(double value) {
233 averageTheta_ = value;
234 }
235 inline void setChangeInCost(double value) {
236 changeCost_ = value;
237 }
239 inline unsigned char * statusArray() const {
241 return status_;
242 }
243 inline int getCurrentStatus(int sequence)
244 {return (status_[sequence] >> 4);}
246 void validate();
248
249 private:
252 double changeCost_;
255 double feasibleCost_;
257 double infeasibilityWeight_;
259 double largestInfeasibility_;
261 double sumInfeasibilities_;
263 double averageTheta_;
265 int numberRows_;
267 int numberColumns_;
269 AbcSimplex * model_;
271 int numberInfeasibilities_;
272 // new stuff
274 unsigned char * status_;
276 double * bound_;
278 double * cost_;
280 };
281
282 #endif
AbcNonLinearCost::setAverageTheta
void setAverageTheta(double value)
Definition: AbcNonLinearCost.hpp:232
AbcNonLinearCost::validate
void validate()
For debug.
AbcNonLinearCost::changeInCost
double changeInCost() const
Change in cost.
Definition: AbcNonLinearCost.hpp:211
AbcNonLinearCost::changeUpInCost
double changeUpInCost(int) const
Definition: AbcNonLinearCost.hpp:161
AbcNonLinearCost::averageTheta_
double averageTheta_
Average theta - kept here as only for primal.
Definition: AbcNonLinearCost.hpp:263
AbcNonLinearCost::changeDownInCost
double changeDownInCost(int) const
Definition: AbcNonLinearCost.hpp:164
CLP_ABOVE_UPPER
#define CLP_ABOVE_UPPER
Definition: AbcNonLinearCost.hpp:41
AbcNonLinearCost::feasibleCost
double feasibleCost() const
Feasible cost.
Definition: AbcNonLinearCost.hpp:215
AbcNonLinearCost::bound_
double * bound_
Bound which has been replaced in lower_ or upper_.
Definition: AbcNonLinearCost.hpp:276
AbcSimplex
Definition: AbcSimplex.hpp:62
AbcNonLinearCost::model_
AbcSimplex * model_
Model.
Definition: AbcNonLinearCost.hpp:269
AbcNonLinearCost::AbcNonLinearCost
AbcNonLinearCost()
Default constructor.
AbcNonLinearCost::operator=
AbcNonLinearCost & operator=(const AbcNonLinearCost &)
AbcNonLinearCost::numberInfeasibilities_
int numberInfeasibilities_
Number of infeasibilities found.
Definition: AbcNonLinearCost.hpp:271
CLP_FEASIBLE
#define CLP_FEASIBLE
Definition: AbcNonLinearCost.hpp:40
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:221
AbcNonLinearCost::refresh
void refresh()
Refresh - assuming regions OK.
setCurrentStatus
void setCurrentStatus(unsigned char &status, int value)
Definition: AbcNonLinearCost.hpp:57
AbcNonLinearCost::numberColumns_
int numberColumns_
Number of columns (mainly for checking and copy)
Definition: AbcNonLinearCost.hpp:267
AbcSimplex::lowerRegion
double * lowerRegion() const
Definition: AbcSimplex.hpp:524
AbcNonLinearCost::feasibleBounds
void feasibleBounds()
Puts feasible bounds into lower and upper.
AbcSimplex::upperRegion
double * upperRegion() const
Definition: AbcSimplex.hpp:527
AbcNonLinearCost::largestInfeasibility
double largestInfeasibility() const
Largest infeasibility.
Definition: AbcNonLinearCost.hpp:225
AbcNonLinearCost::infeasibilityWeight_
double infeasibilityWeight_
Current infeasibility weight.
Definition: AbcNonLinearCost.hpp:257
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:42
AbcNonLinearCost::changeCost_
double changeCost_
Change in cost because of infeasibilities.
Definition: AbcNonLinearCost.hpp:253
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:240
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:261
AbcNonLinearCost::feasibleCost_
double feasibleCost_
Feasible cost.
Definition: AbcNonLinearCost.hpp:255
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:158
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:235
currentStatus
int currentStatus(unsigned char status)
Definition: AbcNonLinearCost.hpp:48
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:44
AbcNonLinearCost::refreshCosts
void refreshCosts(const double *columnCosts)
Refreshes costs always makes row costs zero.
AbcNonLinearCost::cost_
double * cost_
Feasible cost array.
Definition: AbcNonLinearCost.hpp:278
setSameStatus
void setSameStatus(unsigned char &status)
Definition: AbcNonLinearCost.hpp:66
AbcNonLinearCost::largestInfeasibility_
double largestInfeasibility_
Largest infeasibility.
Definition: AbcNonLinearCost.hpp:259
AbcNonLinearCost::getCurrentStatus
int getCurrentStatus(int sequence)
Definition: AbcNonLinearCost.hpp:243
setOriginalStatus
void setOriginalStatus(unsigned char &status, int value)
Definition: AbcNonLinearCost.hpp:52
AbcNonLinearCost::status_
unsigned char * status_
Contains status at beginning and current.
Definition: AbcNonLinearCost.hpp:274
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:265
setInitialStatus
void setInitialStatus(unsigned char &status)
Definition: AbcNonLinearCost.hpp:62
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:229
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:39
AbcNonLinearCost
Definition: AbcNonLinearCost.hpp:72
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:426