Cgl 0.60.2

- 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
ClpNonLinearCost.hpp
Go to the documentation of this file.
1 /* $Id: ClpNonLinearCost.hpp 2385 2019-01-06 19:43:06Z unxusr $ */
2 // Copyright (C) 2002, 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 ClpNonLinearCost_H
7 #define ClpNonLinearCost_H
8
9 #include "CoinPragma.hpp"
10
11 class ClpSimplex;
12 class CoinIndexedVector;
13
31 /* status has original status and current status
32 0 - below lower so stored is upper
33 1 - in range
34 2 - above upper so stored is lower
35 4 - (for current) - same as original
36 */
37 #define CLP_BELOW_LOWER 0
38 #define CLP_FEASIBLE 1
39 #define CLP_ABOVE_UPPER 2
40 #define CLP_SAME 4
41 inline int originalStatus(unsigned char status)
42 {
43 return (status & 15);
44 }
45 inline int currentStatus(unsigned char status)
46 {
47 return (status >> 4);
48 }
49 inline void setOriginalStatus(unsigned char &status, int value)
50 {
51 status = static_cast< unsigned char >(status & ~15);
52 status = static_cast< unsigned char >(status | value);
53 }
54 inline void setCurrentStatus(unsigned char &status, int value)
55 {
56 status = static_cast< unsigned char >(status & ~(15 << 4));
57 status = static_cast< unsigned char >(status | (value << 4));
58 }
59 inline void setInitialStatus(unsigned char &status)
60 {
61 status = static_cast< unsigned char >(CLP_FEASIBLE | (CLP_SAME << 4));
62 }
63 inline void setSameStatus(unsigned char &status)
64 {
65 status = static_cast< unsigned char >(status & ~(15 << 4));
66 status = static_cast< unsigned char >(status | (CLP_SAME << 4));
67 }
68 // Use second version to get more speed
69 //#define FAST_CLPNON
70 #ifndef FAST_CLPNON
71 #define CLP_METHOD1 ((method_ & 1) != 0)
72 #define CLP_METHOD2 ((method_ & 2) != 0)
73 #else
74 #define CLP_METHOD1 (false)
75 #define CLP_METHOD2 (true)
76 #endif
77 class ClpNonLinearCost {
78
79 public:
80 public:
83 ClpNonLinearCost();
89 ClpNonLinearCost(ClpSimplex *model, int method = 1);
95 ClpNonLinearCost(ClpSimplex *model, const int *starts,
96 const double *lower, const double *cost);
98 ~ClpNonLinearCost();
99 // Copy
100 ClpNonLinearCost(const ClpNonLinearCost &);
101 // Assignment
102 ClpNonLinearCost &operator=(const ClpNonLinearCost &);
104
111 void checkInfeasibilities(double oldTolerance = 0.0);
115 void checkInfeasibilities(int numberInArray, const int *index);
122 void checkChanged(int numberInArray, CoinIndexedVector *update);
129 void goThru(int numberInArray, double multiplier,
130 const int *index, const double *work,
131 double *rhs);
134 void goBack(int numberInArray, const int *index,
135 double *rhs);
141 void goBackAll(const CoinIndexedVector *update);
143 void zapCosts();
145 void refreshCosts(const double *columnCosts);
147 void feasibleBounds();
149 void refresh();
151 void refresh(int iSequence);
155 double setOne(int sequence, double solutionValue);
158 void setOne(int sequence, double solutionValue, double lowerValue, double upperValue,
159 double costValue = 0.0);
163 int setOneOutgoing(int sequence, double &solutionValue);
165 double nearest(int sequence, double solutionValue);
169 inline double changeInCost(int sequence, double alpha) const
170 {
171 double returnValue = 0.0;
172 if (CLP_METHOD1) {
173 int iRange = whichRange_[sequence] + offset_[sequence];
174 if (alpha > 0.0)
175 returnValue = cost_[iRange] - cost_[iRange - 1];
176 else
177 returnValue = cost_[iRange] - cost_[iRange + 1];
178 }
179 if (CLP_METHOD2) {
180 returnValue = (alpha > 0.0) ? infeasibilityWeight_ : -infeasibilityWeight_;
181 }
182 return returnValue;
183 }
184 inline double changeUpInCost(int sequence) const
185 {
186 double returnValue = 0.0;
187 if (CLP_METHOD1) {
188 int iRange = whichRange_[sequence] + offset_[sequence];
189 if (iRange + 1 != start_[sequence + 1] && !infeasible(iRange + 1))
190 returnValue = cost_[iRange] - cost_[iRange + 1];
191 else
192 returnValue = -1.0e100;
193 }
194 if (CLP_METHOD2) {
195 returnValue = -infeasibilityWeight_;
196 }
197 return returnValue;
198 }
199 inline double changeDownInCost(int sequence) const
200 {
201 double returnValue = 0.0;
202 if (CLP_METHOD1) {
203 int iRange = whichRange_[sequence] + offset_[sequence];
204 if (iRange != start_[sequence] && !infeasible(iRange - 1))
205 returnValue = cost_[iRange] - cost_[iRange - 1];
206 else
207 returnValue = 1.0e100;
208 }
209 if (CLP_METHOD2) {
210 returnValue = infeasibilityWeight_;
211 }
212 return returnValue;
213 }
215 inline double changeInCost(int sequence, double alpha, double &rhs)
216 {
217 double returnValue = 0.0;
218 #ifdef NONLIN_DEBUG
219 double saveRhs = rhs;
220 #endif
221 if (CLP_METHOD1) {
222 int iRange = whichRange_[sequence] + offset_[sequence];
223 if (alpha > 0.0) {
224 assert(iRange - 1 >= start_[sequence]);
225 offset_[sequence]--;
226 rhs += lower_[iRange] - lower_[iRange - 1];
227 returnValue = alpha * (cost_[iRange] - cost_[iRange - 1]);
228 } else {
229 assert(iRange + 1 < start_[sequence + 1] - 1);
230 offset_[sequence]++;
231 rhs += lower_[iRange + 2] - lower_[iRange + 1];
232 returnValue = alpha * (cost_[iRange] - cost_[iRange + 1]);
233 }
234 }
235 if (CLP_METHOD2) {
236 #ifdef NONLIN_DEBUG
237 double saveRhs1 = rhs;
238 rhs = saveRhs;
239 #endif
240 unsigned char iStatus = status_[sequence];
241 int iWhere = currentStatus(iStatus);
242 if (iWhere == CLP_SAME)
243 iWhere = originalStatus(iStatus);
244 // rhs always increases
245 if (iWhere == CLP_FEASIBLE) {
246 if (alpha > 0.0) {
247 // going below
248 iWhere = CLP_BELOW_LOWER;
249 rhs = COIN_DBL_MAX;
250 } else {
251 // going above
252 iWhere = CLP_ABOVE_UPPER;
253 rhs = COIN_DBL_MAX;
254 }
255 } else if (iWhere == CLP_BELOW_LOWER) {
256 assert(alpha < 0);
257 // going feasible
258 iWhere = CLP_FEASIBLE;
259 rhs += bound_[sequence] - model_->upperRegion()[sequence];
260 } else {
261 assert(iWhere == CLP_ABOVE_UPPER);
262 // going feasible
263 iWhere = CLP_FEASIBLE;
264 rhs += model_->lowerRegion()[sequence] - bound_[sequence];
265 }
266 setCurrentStatus(status_[sequence], iWhere);
267 #ifdef NONLIN_DEBUG
268 assert(saveRhs1 == rhs);
269 #endif
270 returnValue = fabs(alpha) * infeasibilityWeight_;
271 }
272 return returnValue;
273 }
275 inline double lower(int sequence) const
276 {
277 return lower_[whichRange_[sequence] + offset_[sequence]];
278 }
280 inline double upper(int sequence) const
281 {
282 return lower_[whichRange_[sequence] + offset_[sequence] + 1];
283 }
285 inline double cost(int sequence) const
286 {
287 return cost_[whichRange_[sequence] + offset_[sequence]];
288 }
290 inline int fullStatus(int sequence) const
291 {
292 return status_[sequence];
293 }
295 inline bool changed(int sequence) const
296 {
297 return (status_[sequence] & 64) == 0;
298 }
299
301
304 inline int numberInfeasibilities() const
306 {
307 return numberInfeasibilities_;
308 }
310 inline double changeInCost() const
311 {
312 return changeCost_;
313 }
315 inline double feasibleCost() const
316 {
317 return feasibleCost_;
318 }
320 double feasibleReportCost() const;
322 inline double sumInfeasibilities() const
323 {
324 return sumInfeasibilities_;
325 }
327 inline double largestInfeasibility() const
328 {
329 return largestInfeasibility_;
330 }
332 inline double averageTheta() const
333 {
334 return averageTheta_;
335 }
336 inline void setAverageTheta(double value)
337 {
338 averageTheta_ = value;
339 }
340 inline void setChangeInCost(double value)
341 {
342 changeCost_ = value;
343 }
344 inline void setMethod(int value)
345 {
346 method_ = value;
347 }
349 inline bool lookBothWays() const
350 {
351 return bothWays_;
352 }
354 inline bool infeasible(int i) const
356 {
357 return ((infeasible_[i >> 5] >> (i & 31)) & 1) != 0;
358 }
359 inline void setInfeasible(int i, bool trueFalse)
360 {
361 unsigned int &value = infeasible_[i >> 5];
362 int bit = i & 31;
363 if (trueFalse)
364 value |= (1 << bit);
365 else
366 value &= ~(1 << bit);
367 }
368 inline unsigned char *statusArray() const
369 {
370 return status_;
371 }
373 void validate();
375
376 private:
379 double changeCost_;
382 double feasibleCost_;
384 double infeasibilityWeight_;
386 double largestInfeasibility_;
388 double sumInfeasibilities_;
390 double averageTheta_;
392 int numberRows_;
394 int numberColumns_;
396 int *start_;
398 int *whichRange_;
400 int *offset_;
404 double *lower_;
406 double *cost_;
408 ClpSimplex *model_;
409 // Array to say which regions are infeasible
410 unsigned int *infeasible_;
412 int numberInfeasibilities_;
413 // new stuff
415 unsigned char *status_;
417 double *bound_;
419 double *cost2_;
421 int method_;
423 bool convex_;
425 bool bothWays_;
427 };
428
429 #endif
430
431 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
432 */
ClpNonLinearCost::model_
ClpSimplex * model_
Model.
Definition: ClpNonLinearCost.hpp:408
ClpNonLinearCost::ClpNonLinearCost
ClpNonLinearCost()
Default constructor.
ClpNonLinearCost::cost2_
double * cost2_
Feasible cost array.
Definition: ClpNonLinearCost.hpp:419
ClpNonLinearCost::refreshCosts
void refreshCosts(const double *columnCosts)
Refreshes costs always makes row costs zero.
ClpNonLinearCost::sumInfeasibilities_
double sumInfeasibilities_
Sum of infeasibilities.
Definition: ClpNonLinearCost.hpp:388
ClpNonLinearCost::~ClpNonLinearCost
~ClpNonLinearCost()
Destructor.
ClpNonLinearCost::setMethod
void setMethod(int value)
Definition: ClpNonLinearCost.hpp:344
ClpNonLinearCost::operator=
ClpNonLinearCost & operator=(const ClpNonLinearCost &)
ClpNonLinearCost::status_
unsigned char * status_
Contains status at beginning and current.
Definition: ClpNonLinearCost.hpp:415
ClpNonLinearCost::cost_
double * cost_
Cost for each range.
Definition: ClpNonLinearCost.hpp:406
ClpNonLinearCost::refresh
void refresh()
Refresh - assuming regions OK.
ClpNonLinearCost::cost
double cost(int sequence) const
Returns current cost.
Definition: ClpNonLinearCost.hpp:285
ClpNonLinearCost::setOneOutgoing
int setOneOutgoing(int sequence, double &solutionValue)
Sets bounds and cost for outgoing variable may change value Returns direction.
ClpNonLinearCost::checkInfeasibilities
void checkInfeasibilities(double oldTolerance=0.0)
Changes infeasible costs and computes number and cost of infeas Puts all non-basic (non free) variabl...
ClpNonLinearCost::changeCost_
double changeCost_
Change in cost because of infeasibilities.
Definition: ClpNonLinearCost.hpp:380
ClpNonLinearCost::numberColumns_
int numberColumns_
Number of columns (mainly for checking and copy)
Definition: ClpNonLinearCost.hpp:394
ClpNonLinearCost::largestInfeasibility_
double largestInfeasibility_
Largest infeasibility.
Definition: ClpNonLinearCost.hpp:386
setCurrentStatus
void setCurrentStatus(unsigned char &status, int value)
Definition: AbcNonLinearCost.hpp:56
ClpNonLinearCost::largestInfeasibility
double largestInfeasibility() const
Largest infeasibility.
Definition: ClpNonLinearCost.hpp:327
ClpNonLinearCost::changeInCost
double changeInCost(int sequence, double alpha) const
Returns change in cost - one down if alpha &gt;0.0, up if &lt;0.0 Value is current - new.
Definition: ClpNonLinearCost.hpp:169
ClpNonLinearCost
Definition: ClpNonLinearCost.hpp:77
ClpNonLinearCost::changeDownInCost
double changeDownInCost(int sequence) const
Definition: ClpNonLinearCost.hpp:199
ClpNonLinearCost::lower_
double * lower_
Lower bound for each range (upper bound is next lower).
Definition: ClpNonLinearCost.hpp:404
ClpNonLinearCost::changeInCost
double changeInCost(int sequence, double alpha, double &rhs)
This also updates next bound.
Definition: ClpNonLinearCost.hpp:215
ClpNonLinearCost::upper
double upper(int sequence) const
Returns current upper bound.
Definition: ClpNonLinearCost.hpp:280
ClpNonLinearCost::statusArray
unsigned char * statusArray() const
Definition: ClpNonLinearCost.hpp:368
ClpNonLinearCost::changed
bool changed(int sequence) const
Returns if changed from beginning of iteration.
Definition: ClpNonLinearCost.hpp:295
ClpNonLinearCost::goThru
void goThru(int numberInArray, double multiplier, const int *index, const double *work, double *rhs)
Goes through one bound for each variable.
CLP_METHOD1
#define CLP_METHOD1
Definition: ClpNonLinearCost.hpp:71
ClpNonLinearCost::changeUpInCost
double changeUpInCost(int sequence) const
Definition: ClpNonLinearCost.hpp:184
ClpNonLinearCost::goBackAll
void goBackAll(const CoinIndexedVector *update)
Puts back correct infeasible costs for each variable The input indices are row indices and need conve...
ClpNonLinearCost::changeInCost
double changeInCost() const
Change in cost.
Definition: ClpNonLinearCost.hpp:310
ClpNonLinearCost::method_
int method_
Method 1 old, 2 new, 3 both!
Definition: ClpNonLinearCost.hpp:421
ClpNonLinearCost::start_
int * start_
Starts for each entry (columns then rows)
Definition: ClpNonLinearCost.hpp:396
ClpNonLinearCost::numberInfeasibilities
int numberInfeasibilities() const
Number of infeasibilities.
Definition: ClpNonLinearCost.hpp:305
ClpNonLinearCost::averageTheta_
double averageTheta_
Average theta - kept here as only for primal.
Definition: ClpNonLinearCost.hpp:390
ClpSimplex
This solves LPs using the simplex method.
Definition: ClpSimplex.hpp:106
ClpNonLinearCost::bothWays_
bool bothWays_
If we should look both ways for djs.
Definition: ClpNonLinearCost.hpp:425
ClpNonLinearCost::setChangeInCost
void setChangeInCost(double value)
Definition: ClpNonLinearCost.hpp:340
CoinIndexedVector
Indexed Vector.
Definition: CoinIndexedVector.hpp:104
CoinPragma.hpp
CLP_BELOW_LOWER
#define CLP_BELOW_LOWER
Trivial class to deal with non linear costs.
Definition: ClpNonLinearCost.hpp:37
CLP_FEASIBLE
#define CLP_FEASIBLE
Definition: ClpNonLinearCost.hpp:38
ClpNonLinearCost::sumInfeasibilities
double sumInfeasibilities() const
Sum of infeasibilities.
Definition: ClpNonLinearCost.hpp:322
ClpNonLinearCost::feasibleReportCost
double feasibleReportCost() const
Feasible cost with offset and direction (i.e. for reporting)
ClpNonLinearCost::goBack
void goBack(int numberInArray, const int *index, double *rhs)
Takes off last iteration (i.e.
CLP_ABOVE_UPPER
#define CLP_ABOVE_UPPER
Definition: ClpNonLinearCost.hpp:39
currentStatus
int currentStatus(unsigned char status)
Definition: AbcNonLinearCost.hpp:47
originalStatus
int originalStatus(unsigned char status)
Definition: AbcNonLinearCost.hpp:43
ClpNonLinearCost::validate
void validate()
For debug.
ClpNonLinearCost::fullStatus
int fullStatus(int sequence) const
Returns full status.
Definition: ClpNonLinearCost.hpp:290
ClpNonLinearCost::whichRange_
int * whichRange_
Range for each entry (columns then rows)
Definition: ClpNonLinearCost.hpp:398
ClpNonLinearCost::zapCosts
void zapCosts()
Temporary zeroing of feasible costs.
ClpNonLinearCost::infeasibilityWeight_
double infeasibilityWeight_
Current infeasibility weight.
Definition: ClpNonLinearCost.hpp:384
setSameStatus
void setSameStatus(unsigned char &status)
Definition: AbcNonLinearCost.hpp:65
ClpNonLinearCost::feasibleBounds
void feasibleBounds()
Puts feasible bounds into lower and upper.
ClpNonLinearCost::setAverageTheta
void setAverageTheta(double value)
Definition: ClpNonLinearCost.hpp:336
ClpNonLinearCost::infeasible
bool infeasible(int i) const
Definition: ClpNonLinearCost.hpp:355
setOriginalStatus
void setOriginalStatus(unsigned char &status, int value)
Definition: AbcNonLinearCost.hpp:51
ClpSimplex::lowerRegion
double * lowerRegion(int section) const
Definition: ClpSimplex.hpp:1152
ClpNonLinearCost::lower
double lower(int sequence) const
Returns current lower bound.
Definition: ClpNonLinearCost.hpp:275
ClpNonLinearCost::nearest
double nearest(int sequence, double solutionValue)
Returns nearest bound.
ClpNonLinearCost::setInfeasible
void setInfeasible(int i, bool trueFalse)
Definition: ClpNonLinearCost.hpp:359
CLP_METHOD2
#define CLP_METHOD2
Definition: ClpNonLinearCost.hpp:72
ClpNonLinearCost::lookBothWays
bool lookBothWays() const
See if may want to look both ways.
Definition: ClpNonLinearCost.hpp:349
ClpSimplex::upperRegion
double * upperRegion(int section) const
Definition: ClpSimplex.hpp:1159
ClpNonLinearCost::numberInfeasibilities_
int numberInfeasibilities_
Number of infeasibilities found.
Definition: ClpNonLinearCost.hpp:412
setInitialStatus
void setInitialStatus(unsigned char &status)
Definition: AbcNonLinearCost.hpp:61
COIN_DBL_MAX
const double COIN_DBL_MAX
Definition: CoinFinite.hpp:18
ClpNonLinearCost::feasibleCost
double feasibleCost() const
Feasible cost.
Definition: ClpNonLinearCost.hpp:315
CLP_SAME
#define CLP_SAME
Definition: ClpNonLinearCost.hpp:40
ClpNonLinearCost::bound_
double * bound_
Bound which has been replaced in lower_ or upper_.
Definition: ClpNonLinearCost.hpp:417
ClpNonLinearCost::numberRows_
int numberRows_
Number of rows (mainly for checking and copy)
Definition: ClpNonLinearCost.hpp:392
ClpNonLinearCost::feasibleCost_
double feasibleCost_
Feasible cost.
Definition: ClpNonLinearCost.hpp:382
ClpNonLinearCost::averageTheta
double averageTheta() const
Average theta.
Definition: ClpNonLinearCost.hpp:332
ClpNonLinearCost::offset_
int * offset_
Temporary range offset for each entry (columns then rows)
Definition: ClpNonLinearCost.hpp:400
ClpNonLinearCost::checkChanged
void checkChanged(int numberInArray, CoinIndexedVector *update)
Puts back correct infeasible costs for each variable The input indices are row indices and need conve...
ClpNonLinearCost::infeasible_
unsigned int * infeasible_
Definition: ClpNonLinearCost.hpp:410
ClpNonLinearCost::convex_
bool convex_
If all non-linear costs convex.
Definition: ClpNonLinearCost.hpp:423
ClpNonLinearCost::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...