Clp 1.16.9
Loading...
Searching...
No Matches
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
13class AbcSimplex;
14class 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
44inline int originalStatus(unsigned char status)
45{
46 return (status & 15);
47}
48inline int currentStatus(unsigned char status)
49{
50 return (status >> 4);
51}
52inline 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}
57inline 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}
62inline void setInitialStatus(unsigned char &status)
63{
64 status = static_cast<unsigned char>(CLP_FEASIBLE | (CLP_SAME << 4));
65}
66inline 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
74public:
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
207 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
240 inline unsigned char * statusArray() const {
241 return status_;
242 }
243 inline int getCurrentStatus(int sequence)
244 {return (status_[sequence] >> 4);}
246 void validate();
248
249private:
253 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
void setOriginalStatus(unsigned char &status, int value)
#define CLP_BELOW_LOWER
Trivial class to deal with non linear costs.
void setCurrentStatus(unsigned char &status, int value)
int currentStatus(unsigned char status)
#define CLP_FEASIBLE
#define CLP_SAME
void setSameStatus(unsigned char &status)
void setInitialStatus(unsigned char &status)
#define CLP_ABOVE_UPPER
int originalStatus(unsigned char status)
void checkChanged(int numberInArray, CoinIndexedVector *update)
Puts back correct infeasible costs for each variable The input indices are row indices and need conve...
void checkInfeasibilities(int numberInArray, const int *index)
Changes infeasible costs for each variable The indices are row indices and need converting to sequenc...
double feasibleCost() const
Feasible cost.
double changeDownInCost(int) const
AbcNonLinearCost()
Default constructor.
double sumInfeasibilities() const
Sum of infeasibilities.
void refreshCosts(const double *columnCosts)
Refreshes costs always makes row costs zero.
void zapCosts()
Temporary zeroing of feasible costs.
double changeUpInCost(int) const
double feasibleReportCost() const
Feasible cost with offset and direction (i.e. for reporting)
void feasibleBounds()
Puts feasible bounds into lower and upper.
double setOneBasic(int iRow, double solutionValue)
Sets bounds and cost for one variable Returns change in cost May need to be inline for speed.
void setChangeInCost(double value)
double largestInfeasibility() const
Largest infeasibility.
double nearest(int iRow, double solutionValue)
Returns nearest bound.
void checkInfeasibilities(double oldTolerance=0.0)
Changes infeasible costs and computes number and cost of infeas Puts all non-basic (non free) variabl...
void refreshFromPerturbed(double tolerance)
Refresh - from original.
double changeInCost(int, double alpha) const
Returns change in cost - one down if alpha >0.0, up if <0.0 Value is current - new.
int setOneOutgoing(int sequence, double &solutionValue)
Sets bounds and cost for outgoing variable may change value Returns direction.
void validate()
For debug.
AbcNonLinearCost(AbcSimplex *model)
Constructor from simplex.
~AbcNonLinearCost()
Destructor.
double changeInCost(int iRow, double alpha, double &rhs)
This also updates next bound.
double changeInCost() const
Change in cost.
void goBack(int numberInArray, const int *index, double *rhs)
Takes off last iteration (i.e.
int getCurrentStatus(int sequence)
double averageTheta() const
Average theta.
AbcNonLinearCost(const AbcNonLinearCost &)
int numberInfeasibilities() const
Number of infeasibilities.
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 refresh()
Refresh - assuming regions OK.
void goThru(int numberInArray, double multiplier, const int *index, const double *work, double *rhs)
Goes through one bound for each variable.
AbcNonLinearCost & operator=(const AbcNonLinearCost &)
void goBackAll(const CoinIndexedVector *update)
Puts back correct infeasible costs for each variable The input indices are row indices and need conve...
unsigned char * statusArray() const
void setAverageTheta(double value)
double * upperRegion() const
Definition: AbcSimplex.hpp:527
int * pivotVariable() const
Basic variables pivoting on which rows may be same as toExternal but may be as at invert.
Definition: AbcSimplex.hpp:426
double * lowerRegion() const
Definition: AbcSimplex.hpp:524