Clp  1.16.11
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
73 
74 public:
75 
87  // Copy
89  // Assignment
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);
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::goThru
void goThru(int numberInArray, double multiplier, const int *index, const double *work, double *rhs)
Goes through one bound for each variable.
setOriginalStatus
void setOriginalStatus(unsigned char &status, int value)
Definition: AbcNonLinearCost.hpp:52
AbcNonLinearCost::sumInfeasibilities
double sumInfeasibilities() const
Sum of infeasibilities.
Definition: AbcNonLinearCost.hpp:221
AbcSimplex::upperRegion
double * upperRegion() const
Definition: AbcSimplex.hpp:527
setInitialStatus
void setInitialStatus(unsigned char &status)
Definition: AbcNonLinearCost.hpp:62
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::~AbcNonLinearCost
~AbcNonLinearCost()
Destructor.
CLP_FEASIBLE
#define CLP_FEASIBLE
Definition: AbcNonLinearCost.hpp:40
CLP_ABOVE_UPPER
#define CLP_ABOVE_UPPER
Definition: AbcNonLinearCost.hpp:41
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::nearest
double nearest(int iRow, double solutionValue)
Returns nearest bound.
AbcNonLinearCost::changeUpInCost
double changeUpInCost(int) const
Definition: AbcNonLinearCost.hpp:161
setCurrentStatus
void setCurrentStatus(unsigned char &status, int value)
Definition: AbcNonLinearCost.hpp:57
AbcNonLinearCost::changeInCost
double changeInCost() const
Change in cost.
Definition: AbcNonLinearCost.hpp:211
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
Definition: AbcNonLinearCost.hpp:72
AbcNonLinearCost::setChangeInCost
void setChangeInCost(double value)
Definition: AbcNonLinearCost.hpp:235
AbcNonLinearCost::changeInCost
double changeInCost(int, double alpha) const
Returns change in cost - one down if alpha >0.0, up if <0.0 Value is current - new.
Definition: AbcNonLinearCost.hpp:158
AbcNonLinearCost::zapCosts
void zapCosts()
Temporary zeroing of feasible costs.
AbcNonLinearCost::checkInfeasibilities
void checkInfeasibilities(int numberInArray, const int *index)
Changes infeasible costs for each variable The indices are row indices and need converting to sequenc...
AbcNonLinearCost::getCurrentStatus
int getCurrentStatus(int sequence)
Definition: AbcNonLinearCost.hpp:243
AbcNonLinearCost::setOneOutgoing
int setOneOutgoing(int sequence, double &solutionValue)
Sets bounds and cost for outgoing variable may change value Returns direction.
currentStatus
int currentStatus(unsigned char status)
Definition: AbcNonLinearCost.hpp:48
AbcNonLinearCost::AbcNonLinearCost
AbcNonLinearCost(AbcSimplex *model)
Constructor from simplex.
AbcNonLinearCost::validate
void validate()
For debug.
AbcNonLinearCost::goBackAll
void goBackAll(const CoinIndexedVector *update)
Puts back correct infeasible costs for each variable The input indices are row indices and need conve...
CLP_SAME
#define CLP_SAME
Definition: AbcNonLinearCost.hpp:42
AbcNonLinearCost::AbcNonLinearCost
AbcNonLinearCost()
Default constructor.
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
AbcCommon.hpp
AbcNonLinearCost::largestInfeasibility
double largestInfeasibility() const
Largest infeasibility.
Definition: AbcNonLinearCost.hpp:225
AbcNonLinearCost::feasibleCost
double feasibleCost() const
Feasible cost.
Definition: AbcNonLinearCost.hpp:215
AbcSimplex::lowerRegion
double * lowerRegion() const
Definition: AbcSimplex.hpp:524
AbcNonLinearCost::operator=
AbcNonLinearCost & operator=(const AbcNonLinearCost &)
AbcNonLinearCost::changeDownInCost
double changeDownInCost(int) const
Definition: AbcNonLinearCost.hpp:164
AbcNonLinearCost::refresh
void refresh()
Refresh - assuming regions OK.
AbcSimplex
Definition: AbcSimplex.hpp:62
AbcNonLinearCost::changeInCost
double changeInCost(int iRow, double alpha, double &rhs)
This also updates next bound.
Definition: AbcNonLinearCost.hpp:168
AbcNonLinearCost::feasibleBounds
void feasibleBounds()
Puts feasible bounds into lower and upper.
AbcNonLinearCost::setAverageTheta
void setAverageTheta(double value)
Definition: AbcNonLinearCost.hpp:232
originalStatus
int originalStatus(unsigned char status)
Definition: AbcNonLinearCost.hpp:44
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.
setSameStatus
void setSameStatus(unsigned char &status)
Definition: AbcNonLinearCost.hpp:66
AbcNonLinearCost::statusArray
unsigned char * statusArray() const
Definition: AbcNonLinearCost.hpp:240
AbcNonLinearCost::refreshFromPerturbed
void refreshFromPerturbed(double tolerance)
Refresh - from original.
AbcNonLinearCost::numberInfeasibilities
int numberInfeasibilities() const
Number of infeasibilities.
Definition: AbcNonLinearCost.hpp:207
AbcNonLinearCost::AbcNonLinearCost
AbcNonLinearCost(const AbcNonLinearCost &)
AbcNonLinearCost::goBack
void goBack(int numberInArray, const int *index, double *rhs)
Takes off last iteration (i.e.
AbcNonLinearCost::refreshCosts
void refreshCosts(const double *columnCosts)
Refreshes costs always makes row costs zero.
CLP_BELOW_LOWER
#define CLP_BELOW_LOWER
Trivial class to deal with non linear costs.
Definition: AbcNonLinearCost.hpp:39
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