Cgl  0.60.3
 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 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 */
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:598
void feasibleBounds()
Puts feasible bounds into lower and upper.
double * upperRegion() const
Definition: AbcSimplex.hpp:602
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:465