coin-Bcp
AbcNonLinearCost.hpp
Go to the documentation of this file.
1 /* $Id: AbcNonLinearCost.hpp 2385 2019-01-06 19:43:06Z unxusr $ */
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 #include "CoinPragma.hpp"
10 #include "AbcCommon.hpp"
11 
12 class AbcSimplex;
13 class CoinIndexedVector;
14 
32 /* status has original status and current status
33  0 - below lower so stored is upper
34  1 - in range
35  2 - above upper so stored is lower
36  4 - (for current) - same as original
37 */
38 #define CLP_BELOW_LOWER 0
39 #define CLP_FEASIBLE 1
40 #define CLP_ABOVE_UPPER 2
41 #define CLP_SAME 4
42 #ifndef ClpNonLinearCost_H
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 }
70 #endif
72 
73 public:
85  // Copy
87  // Assignment
90 
97  void checkInfeasibilities(double oldTolerance = 0.0);
101  void checkInfeasibilities(int numberInArray, const int *index);
108  void checkChanged(int numberInArray, CoinIndexedVector *update);
115  void goThru(int numberInArray, double multiplier,
116  const int *index, const double *work,
117  double *rhs);
120  void goBack(int numberInArray, const int *index,
121  double *rhs);
127  void goBackAll(const CoinIndexedVector *update);
129  void zapCosts();
131  void refreshCosts(const double *columnCosts);
133  void feasibleBounds();
135  void refresh();
137  void refreshFromPerturbed(double tolerance);
141  double setOne(int sequence, double solutionValue);
145  double setOneBasic(int iRow, double solutionValue);
149  int setOneOutgoing(int sequence, double &solutionValue);
151  double nearest(int iRow, double solutionValue);
155  inline double changeInCost(int /*sequence*/, double alpha) const
156  {
157  return (alpha > 0.0) ? infeasibilityWeight_ : -infeasibilityWeight_;
158  }
159  inline double changeUpInCost(int /*sequence*/) const
160  {
161  return -infeasibilityWeight_;
162  }
163  inline double changeDownInCost(int /*sequence*/) const
164  {
165  return infeasibilityWeight_;
166  }
168  inline double changeInCost(int iRow, double alpha, double &rhs)
169  {
170  int sequence = model_->pivotVariable()[iRow];
171  double returnValue = 0.0;
172  unsigned char iStatus = status_[sequence];
173  int iWhere = currentStatus(iStatus);
174  if (iWhere == CLP_SAME)
175  iWhere = originalStatus(iStatus);
176  // rhs always increases
177  if (iWhere == CLP_FEASIBLE) {
178  if (alpha > 0.0) {
179  // going below
180  iWhere = CLP_BELOW_LOWER;
181  rhs = COIN_DBL_MAX;
182  } else {
183  // going above
184  iWhere = CLP_ABOVE_UPPER;
185  rhs = COIN_DBL_MAX;
186  }
187  } else if (iWhere == CLP_BELOW_LOWER) {
188  assert(alpha < 0);
189  // going feasible
190  iWhere = CLP_FEASIBLE;
191  rhs += bound_[sequence] - model_->upperRegion()[sequence];
192  } else {
193  assert(iWhere == CLP_ABOVE_UPPER);
194  // going feasible
195  iWhere = CLP_FEASIBLE;
196  rhs += model_->lowerRegion()[sequence] - bound_[sequence];
197  }
198  setCurrentStatus(status_[sequence], iWhere);
199  returnValue = fabs(alpha) * infeasibilityWeight_;
200  return returnValue;
201  }
203 
206  inline int numberInfeasibilities() const
208  {
209  return numberInfeasibilities_;
210  }
212  inline double changeInCost() const
213  {
214  return changeCost_;
215  }
217  inline double feasibleCost() const
218  {
219  return feasibleCost_;
220  }
222  double feasibleReportCost() const;
224  inline double sumInfeasibilities() const
225  {
226  return sumInfeasibilities_;
227  }
229  inline double largestInfeasibility() const
230  {
231  return largestInfeasibility_;
232  }
234  inline double averageTheta() const
235  {
236  return averageTheta_;
237  }
238  inline void setAverageTheta(double value)
239  {
240  averageTheta_ = value;
241  }
242  inline void setChangeInCost(double value)
243  {
244  changeCost_ = value;
245  }
247  inline unsigned char *statusArray() const
249  {
250  return status_;
251  }
252  inline int getCurrentStatus(int sequence)
253  {
254  return (status_[sequence] >> 4);
255  }
257  void validate();
259 
260 private:
263  double changeCost_;
283  // new stuff
285  unsigned char *status_;
287  double *bound_;
289  double *cost_;
291 };
292 
293 #endif
294 
295 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
296 */
double infeasibilityWeight_
Current infeasibility weight.
double sumInfeasibilities() const
Sum of infeasibilities.
void checkInfeasibilities(double oldTolerance=0.0)
Changes infeasible costs and computes number and cost of infeas Puts all non-basic (non free) variabl...
AbcNonLinearCost()
Default constructor.
#define CLP_SAME
#define CLP_ABOVE_UPPER
void goBack(int numberInArray, const int *index, double *rhs)
Takes off last iteration (i.e.
double largestInfeasibility_
Largest infeasibility.
void refreshFromPerturbed(double tolerance)
Refresh - from original.
void checkChanged(int numberInArray, CoinIndexedVector *update)
Puts back correct infeasible costs for each variable The input indices are row indices and need conve...
AbcNonLinearCost & operator=(const AbcNonLinearCost &)
Default constructor.
void goBackAll(const CoinIndexedVector *update)
Puts back correct infeasible costs for each variable The input indices are row indices and need conve...
double nearest(int iRow, double solutionValue)
Returns nearest bound.
AbcSimplex * model_
Model.
void setCurrentStatus(unsigned char &status, int value)
void goThru(int numberInArray, double multiplier, const int *index, const double *work, double *rhs)
Goes through one bound for each variable.
double changeCost_
Change in cost because of infeasibilities.
double averageTheta_
Average theta - kept here as only for primal.
int numberColumns_
Number of columns (mainly for checking and copy)
#define CLP_FEASIBLE
double setOneBasic(int iRow, double solutionValue)
Sets bounds and cost for one variable Returns change in cost May need to be inline for speed...
int setOneOutgoing(int sequence, double &solutionValue)
Sets bounds and cost for outgoing variable may change value Returns direction.
double setOne(int sequence, double solutionValue)
Sets bounds and cost for one variable Returns change in cost May need to be inline for speed...
double feasibleCost_
Feasible cost.
int numberInfeasibilities() const
Number of infeasibilities.
double changeInCost(int iRow, double alpha, double &rhs)
This also updates next bound.
void setOriginalStatus(unsigned char &status, int value)
unsigned char * status_
Contains status at beginning and current.
double feasibleReportCost() const
Feasible cost with offset and direction (i.e. for reporting)
#define CLP_BELOW_LOWER
Trivial class to deal with non linear costs.
Indexed Vector.
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 changeUpInCost(int) const
Changes infeasible costs and computes number and cost of infeas Puts all non-basic (non free) variabl...
int getCurrentStatus(int sequence)
For debug.
void setAverageTheta(double value)
Number of infeasibilities.
double largestInfeasibility() const
Largest infeasibility.
const double COIN_DBL_MAX
Definition: CoinFinite.hpp:18
void setInitialStatus(unsigned char &status)
int originalStatus(unsigned char status)
double changeInCost() const
Change in cost.
double feasibleCost() const
Feasible cost.
void setSameStatus(unsigned char &status)
void setChangeInCost(double value)
Number of infeasibilities.
double changeDownInCost(int) const
Changes infeasible costs and computes number and cost of infeas Puts all non-basic (non free) variabl...
~AbcNonLinearCost()
Destructor.
double * upperRegion() const
Return region.
Definition: AbcSimplex.hpp:602
void validate()
For debug.
int numberInfeasibilities_
Number of infeasibilities found.
void feasibleBounds()
Puts feasible bounds into lower and upper.
double * cost_
Feasible cost array.
int * pivotVariable() const
Basic variables pivoting on which rows may be same as toExternal but may be as at invert...
Definition: AbcSimplex.hpp:465
double averageTheta() const
Average theta.
void refreshCosts(const double *columnCosts)
Refreshes costs always makes row costs zero.
unsigned char * statusArray() const
For debug.
double * bound_
Bound which has been replaced in lower_ or upper_.
double * lowerRegion() const
Return region.
Definition: AbcSimplex.hpp:598
void refresh()
Refresh - assuming regions OK.
double sumInfeasibilities_
Sum of infeasibilities.
int currentStatus(unsigned char status)
int numberRows_
Number of rows (mainly for checking and copy)
void zapCosts()
Temporary zeroing of feasible costs.