Cbc  2.9.9
 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
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);
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_;
272  // new stuff
274  unsigned char * status_;
276  double * bound_;
278  double * cost_;
280 };
281 
282 #endif
void setAverageTheta(double value)
void validate()
For debug.
double changeInCost() const
Change in cost.
double changeUpInCost(int) const
double averageTheta_
Average theta - kept here as only for primal.
double changeDownInCost(int) const
#define CLP_ABOVE_UPPER
double feasibleCost() const
Feasible cost.
double * bound_
Bound which has been replaced in lower_ or upper_.
AbcSimplex * model_
Model.
AbcNonLinearCost()
Default constructor.
AbcNonLinearCost & operator=(const AbcNonLinearCost &)
int numberInfeasibilities_
Number of infeasibilities found.
#define CLP_FEASIBLE
void goBack(int numberInArray, const int *index, double *rhs)
Takes off last iteration (i.e.
double sumInfeasibilities() const
Sum of infeasibilities.
void refresh()
Refresh - assuming regions OK.
void setCurrentStatus(unsigned char &status, int value)
int numberColumns_
Number of columns (mainly for checking and copy)
double * lowerRegion() const
Definition: AbcSimplex.hpp:524
void feasibleBounds()
Puts feasible bounds into lower and upper.
double * upperRegion() const
Definition: AbcSimplex.hpp:527
double largestInfeasibility() const
Largest infeasibility.
double infeasibilityWeight_
Current infeasibility weight.
void goThru(int numberInArray, double multiplier, const int *index, const double *work, double *rhs)
Goes through one bound for each variable.
#define CLP_SAME
double changeCost_
Change in cost because of infeasibilities.
~AbcNonLinearCost()
Destructor.
int numberInfeasibilities() const
Number of infeasibilities.
void refreshFromPerturbed(double tolerance)
Refresh - from original.
unsigned char * statusArray() const
Indexed Vector.
double setOneBasic(int iRow, double solutionValue)
Sets bounds and cost for one variable Returns change in cost May need to be inline for speed...
double sumInfeasibilities_
Sum of infeasibilities.
double feasibleCost_
Feasible cost.
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.
double setOne(int sequence, double solutionValue)
Sets bounds and cost for one variable Returns change in cost May need to be inline for speed...
void zapCosts()
Temporary zeroing of feasible costs.
void setChangeInCost(double value)
int currentStatus(unsigned char status)
int setOneOutgoing(int sequence, double &solutionValue)
Sets bounds and cost for outgoing variable may change value Returns direction.
int originalStatus(unsigned char status)
void refreshCosts(const double *columnCosts)
Refreshes costs always makes row costs zero.
double * cost_
Feasible cost array.
void setSameStatus(unsigned char &status)
double largestInfeasibility_
Largest infeasibility.
int getCurrentStatus(int sequence)
void setOriginalStatus(unsigned char &status, int value)
unsigned char * status_
Contains status at beginning and current.
void goBackAll(const CoinIndexedVector *update)
Puts back correct infeasible costs for each variable The input indices are row indices and need conve...
int numberRows_
Number of rows (mainly for checking and copy)
void setInitialStatus(unsigned char &status)
const double COIN_DBL_MAX
Definition: CoinFinite.hpp:18
void checkInfeasibilities(double oldTolerance=0.0)
Changes infeasible costs and computes number and cost of infeas Puts all non-basic (non free) variabl...
double feasibleReportCost() const
Feasible cost with offset and direction (i.e. for reporting)
double averageTheta() const
Average theta.
void checkChanged(int numberInArray, CoinIndexedVector *update)
Puts back correct infeasible costs for each variable The input indices are row indices and need conve...
double changeInCost(int iRow, double alpha, double &rhs)
This also updates next bound.
#define CLP_BELOW_LOWER
Trivial class to deal with non linear costs.
double nearest(int iRow, double solutionValue)
Returns nearest bound.
int * pivotVariable() const
Basic variables pivoting on which rows may be same as toExternal but may be as at invert...
Definition: AbcSimplex.hpp:426