Clp 1.17.5
Loading...
Searching...
No Matches
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
12class AbcSimplex;
13class 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
43inline int originalStatus(unsigned char status)
44{
45 return (status & 15);
46}
47inline int currentStatus(unsigned char status)
48{
49 return (status >> 4);
50}
51inline 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}
56inline 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}
61inline void setInitialStatus(unsigned char &status)
62{
63 status = static_cast< unsigned char >(CLP_FEASIBLE | (CLP_SAME << 4));
64}
65inline 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
73public:
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);
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 {
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
207 inline int numberInfeasibilities() const
208 {
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 {
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
248 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
260private:
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 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)
double infeasibilityWeight_
Current infeasibility weight.
double changeCost_
Change in cost because of infeasibilities.
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.
int numberInfeasibilities_
Number of infeasibilities found.
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 averageTheta_
Average theta - kept here as only for primal.
double largestInfeasibility() const
Largest infeasibility.
unsigned char * status_
Contains status at beginning and current.
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...
int numberColumns_
Number of columns (mainly for checking and copy)
void refreshFromPerturbed(double tolerance)
Refresh - from original.
int numberRows_
Number of rows (mainly for checking and copy)
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.
double * cost_
Feasible cost array.
AbcNonLinearCost(AbcSimplex *model)
Constructor from simplex.
~AbcNonLinearCost()
Destructor.
double changeInCost(int iRow, double alpha, double &rhs)
This also updates next bound.
double * bound_
Bound which has been replaced in lower_ or upper_.
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 sumInfeasibilities_
Sum 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.
double largestInfeasibility_
Largest infeasibility.
double feasibleCost_
Feasible cost.
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.
AbcSimplex * model_
Model.
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
int * pivotVariable() const
Basic variables pivoting on which rows may be same as toExternal but may be as at invert.
double * lowerRegion() const