Clp  1.15.5
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
AbcNonLinearCost.hpp
Go to the documentation of this file.
1 /* $Id: AbcNonLinearCost.hpp 1910 2013-01-27 02:00:13Z stefan $ */
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 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 }
71 
72 public:
73 
85  // Copy
87  // Assignment
90 
91 
98  void checkInfeasibilities(double oldTolerance = 0.0);
102  void checkInfeasibilities(int numberInArray, const int * index);
109  void checkChanged(int numberInArray, CoinIndexedVector * update);
116  void goThru(int numberInArray, double multiplier,
117  const int * index, const double * work,
118  double * rhs);
121  void goBack(int numberInArray, const int * index,
122  double * rhs);
128  void goBackAll(const CoinIndexedVector * update);
130  void zapCosts();
132  void refreshCosts(const double * columnCosts);
134  void feasibleBounds();
136  void refresh();
138  void refreshFromPerturbed(double tolerance);
142  double setOne(int sequence, double solutionValue);
146  double setOneBasic(int iRow, double solutionValue);
150  int setOneOutgoing(int sequence, double &solutionValue);
152  double nearest(int iRow, double solutionValue);
156  inline double changeInCost(int /*sequence*/, double alpha) const {
157  return (alpha > 0.0) ? infeasibilityWeight_ : -infeasibilityWeight_;
158  }
159  inline double changeUpInCost(int /*sequence*/) const {
160  return -infeasibilityWeight_;
161  }
162  inline double changeDownInCost(int /*sequence*/) const {
163  return infeasibilityWeight_;
164  }
166  inline double changeInCost(int iRow, double alpha, double &rhs) {
167  int sequence=model_->pivotVariable()[iRow];
168  double returnValue = 0.0;
169  unsigned char iStatus = status_[sequence];
170  int iWhere = currentStatus(iStatus);
171  if (iWhere == CLP_SAME)
172  iWhere = originalStatus(iStatus);
173  // rhs always increases
174  if (iWhere == CLP_FEASIBLE) {
175  if (alpha > 0.0) {
176  // going below
177  iWhere = CLP_BELOW_LOWER;
178  rhs = COIN_DBL_MAX;
179  } else {
180  // going above
181  iWhere = CLP_ABOVE_UPPER;
182  rhs = COIN_DBL_MAX;
183  }
184  } else if (iWhere == CLP_BELOW_LOWER) {
185  assert (alpha < 0);
186  // going feasible
187  iWhere = CLP_FEASIBLE;
188  rhs += bound_[sequence] - model_->upperRegion()[sequence];
189  } else {
190  assert (iWhere == CLP_ABOVE_UPPER);
191  // going feasible
192  iWhere = CLP_FEASIBLE;
193  rhs += model_->lowerRegion()[sequence] - bound_[sequence];
194  }
195  setCurrentStatus(status_[sequence], iWhere);
196  returnValue = fabs(alpha) * infeasibilityWeight_;
197  return returnValue;
198  }
200 
201 
204  inline int numberInfeasibilities() const {
206  return numberInfeasibilities_;
207  }
209  inline double changeInCost() const {
210  return changeCost_;
211  }
213  inline double feasibleCost() const {
214  return feasibleCost_;
215  }
217  double feasibleReportCost() const;
219  inline double sumInfeasibilities() const {
220  return sumInfeasibilities_;
221  }
223  inline double largestInfeasibility() const {
224  return largestInfeasibility_;
225  }
227  inline double averageTheta() const {
228  return averageTheta_;
229  }
230  inline void setAverageTheta(double value) {
231  averageTheta_ = value;
232  }
233  inline void setChangeInCost(double value) {
234  changeCost_ = value;
235  }
237  inline unsigned char * statusArray() const {
239  return status_;
240  }
241  inline int getCurrentStatus(int sequence)
242  {return (status_[sequence] >> 4);}
244  void validate();
246 
247 private:
250  double changeCost_;
253  double feasibleCost_;
255  double infeasibilityWeight_;
257  double largestInfeasibility_;
259  double sumInfeasibilities_;
261  double averageTheta_;
263  int numberRows_;
265  int numberColumns_;
267  AbcSimplex * model_;
269  int numberInfeasibilities_;
270  // new stuff
272  unsigned char * status_;
274  double * bound_;
276  double * cost_;
278 };
279 
280 #endif
void setAverageTheta(double value)
void validate()
For debug.
double changeInCost() const
Change in cost.
double changeUpInCost(int) const
double changeDownInCost(int) const
#define CLP_ABOVE_UPPER
double feasibleCost() const
Feasible cost.
AbcNonLinearCost()
Default constructor.
AbcNonLinearCost & operator=(const AbcNonLinearCost &)
#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)
double * lowerRegion() const
Definition: AbcSimplex.hpp:532
void feasibleBounds()
Puts feasible bounds into lower and upper.
double * upperRegion() const
Definition: AbcSimplex.hpp:535
double largestInfeasibility() const
Largest infeasibility.
void goThru(int numberInArray, double multiplier, const int *index, const double *work, double *rhs)
Goes through one bound for each variable.
#define CLP_SAME
~AbcNonLinearCost()
Destructor.
int numberInfeasibilities() const
Number of infeasibilities.
void refreshFromPerturbed(double tolerance)
Refresh - from original.
unsigned char * statusArray() const
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 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.
void setSameStatus(unsigned char &status)
int getCurrentStatus(int sequence)
void setOriginalStatus(unsigned char &status, int value)
void goBackAll(const CoinIndexedVector *update)
Puts back correct infeasible costs for each variable The input indices are row indices and need conve...
void setInitialStatus(unsigned char &status)
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:434