6#ifndef ClpNonLinearCost_H
7#define ClpNonLinearCost_H
10#include "CoinPragma.hpp"
13class CoinIndexedVector;
38#define CLP_BELOW_LOWER 0
40#define CLP_ABOVE_UPPER 2
52 status =
static_cast<unsigned char>(status & ~15);
53 status =
static_cast<unsigned char>(status | value);
57 status =
static_cast<unsigned char>(status & ~(15 << 4));
58 status =
static_cast<unsigned char>(status | (value << 4));
66 status =
static_cast<unsigned char>(status & ~(15 << 4));
67 status =
static_cast<unsigned char>(status | (
CLP_SAME << 4));
72#define CLP_METHOD1 ((method_&1)!=0)
73#define CLP_METHOD2 ((method_&2)!=0)
75#define CLP_METHOD1 (false)
76#define CLP_METHOD2 (true)
99 const double *
lower,
const double *
cost);
133 void goThru(
int numberInArray,
double multiplier,
134 const int * index,
const double * work,
138 void goBack(
int numberInArray,
const int * index,
157 double setOne(
int sequence,
double solutionValue);
160 void setOne(
int sequence,
double solutionValue,
double lowerValue,
double upperValue,
161 double costValue = 0.0);
167 double nearest(
int sequence,
double solutionValue);
172 double returnValue = 0.0;
174 int iRange = whichRange_[sequence] + offset_[sequence];
176 returnValue = cost_[iRange] - cost_[iRange-1];
178 returnValue = cost_[iRange] - cost_[iRange+1];
181 returnValue = (alpha > 0.0) ? infeasibilityWeight_ : -infeasibilityWeight_;
186 double returnValue = 0.0;
188 int iRange = whichRange_[sequence] + offset_[sequence];
189 if (iRange + 1 != start_[sequence+1] && !
infeasible(iRange + 1))
190 returnValue = cost_[iRange] - cost_[iRange+1];
192 returnValue = -1.0e100;
195 returnValue = -infeasibilityWeight_;
200 double returnValue = 0.0;
202 int iRange = whichRange_[sequence] + offset_[sequence];
203 if (iRange != start_[sequence] && !
infeasible(iRange - 1))
204 returnValue = cost_[iRange] - cost_[iRange-1];
206 returnValue = 1.0e100;
209 returnValue = infeasibilityWeight_;
215 double returnValue = 0.0;
217 double saveRhs = rhs;
220 int iRange = whichRange_[sequence] + offset_[sequence];
222 assert(iRange - 1 >= start_[sequence]);
224 rhs += lower_[iRange] - lower_[iRange-1];
225 returnValue = alpha * (cost_[iRange] - cost_[iRange-1]);
227 assert(iRange + 1 < start_[sequence+1] - 1);
229 rhs += lower_[iRange+2] - lower_[iRange+1];
230 returnValue = alpha * (cost_[iRange] - cost_[iRange+1]);
235 double saveRhs1 = rhs;
238 unsigned char iStatus = status_[sequence];
257 rhs += bound_[sequence] - model_->
upperRegion()[sequence];
262 rhs += model_->
lowerRegion()[sequence] - bound_[sequence];
266 assert(saveRhs1 == rhs);
268 returnValue = fabs(alpha) * infeasibilityWeight_;
273 inline double lower(
int sequence)
const {
274 return lower_[whichRange_[sequence] + offset_[sequence]];
277 inline double upper(
int sequence)
const {
278 return lower_[whichRange_[sequence] + offset_[sequence] + 1];
281 inline double cost(
int sequence)
const {
282 return cost_[whichRange_[sequence] + offset_[sequence]];
291 return numberInfeasibilities_;
299 return feasibleCost_;
305 return sumInfeasibilities_;
309 return largestInfeasibility_;
313 return averageTheta_;
316 averageTheta_ = value;
331 return ((infeasible_[i>>5] >> (i & 31)) & 1) != 0;
334 unsigned int & value = infeasible_[i>>5];
339 value &= ~(1 << bit);
354 double feasibleCost_;
356 double infeasibilityWeight_;
358 double largestInfeasibility_;
360 double sumInfeasibilities_;
362 double averageTheta_;
382 unsigned int * infeasible_;
384 int numberInfeasibilities_;
387 unsigned char * status_;
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)
void setSameStatus(unsigned char &status)
void setInitialStatus(unsigned char &status)
int originalStatus(unsigned char status)
ClpNonLinearCost()
Default constructor.
void refreshCosts(const double *columnCosts)
Refreshes costs always makes row costs zero.
double lower(int sequence) const
Returns current lower bound.
double changeUpInCost(int sequence) const
double sumInfeasibilities() const
Sum of infeasibilities.
double nearest(int sequence, double solutionValue)
Returns nearest bound.
bool infeasible(int i) const
ClpNonLinearCost & operator=(const ClpNonLinearCost &)
ClpNonLinearCost(ClpSimplex *model, int method=1)
Constructor from simplex.
void setChangeInCost(double value)
double feasibleCost() const
Feasible cost.
double changeInCost(int sequence, double alpha, double &rhs)
This also updates next bound.
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 cost(int sequence) const
Returns current cost.
ClpNonLinearCost(ClpSimplex *model, const int *starts, const double *lower, const double *cost)
Constructor from simplex and list of non-linearities (columns only) First lower of each column has to...
bool lookBothWays() const
See if may want to look both ways.
void setInfeasible(int i, bool trueFalse)
void goBackAll(const CoinIndexedVector *update)
Puts back correct infeasible costs for each variable The input indices are row indices and need conve...
ClpNonLinearCost(const ClpNonLinearCost &)
void setAverageTheta(double value)
unsigned char * statusArray() const
void setMethod(int value)
int numberInfeasibilities() const
Number of infeasibilities.
int setOneOutgoing(int sequence, double &solutionValue)
Sets bounds and cost for outgoing variable may change value Returns direction.
void setOne(int sequence, double solutionValue, double lowerValue, double upperValue, double costValue=0.0)
Sets bounds and infeasible cost and true cost for one variable This is for gub and column generation ...
void goBack(int numberInArray, const int *index, double *rhs)
Takes off last iteration (i.e.
void goThru(int numberInArray, double multiplier, const int *index, const double *work, double *rhs)
Goes through one bound for each variable.
void checkInfeasibilities(int numberInArray, const int *index)
Changes infeasible costs for each variable The indices are row indices and need converting to sequenc...
void refresh()
Refresh - assuming regions OK.
void checkChanged(int numberInArray, CoinIndexedVector *update)
Puts back correct infeasible costs for each variable The input indices are row indices and need conve...
void zapCosts()
Temporary zeroing of feasible costs.
double largestInfeasibility() const
Largest infeasibility.
double averageTheta() const
Average theta.
double changeDownInCost(int sequence) const
double changeInCost(int sequence, double alpha) const
Returns change in cost - one down if alpha >0.0, up if <0.0 Value is current - new.
double upper(int sequence) const
Returns current upper bound.
void validate()
For debug.
double changeInCost() const
Change in cost.
~ClpNonLinearCost()
Destructor.
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 feasibleBounds()
Puts feasible bounds into lower and upper.
This solves LPs using the simplex method.
double * lowerRegion(int section) const
double * upperRegion(int section) const