Loading...
Searching...
No Matches
AbcNonLinearCost.hpp
Go to the documentation of this file.
/* $Id$ */
// Copyright (C) 2002, International Business Machines
// Corporation and others, Copyright (C) 2012, FasterCoin. All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).
#ifndef AbcNonLinearCost_H
#define AbcNonLinearCost_H
#include "CoinPragma.hpp"
#include "AbcCommon.hpp"
class AbcSimplex;
class CoinIndexedVector;
/* status has original status and current status
0 - below lower so stored is upper
1 - in range
2 - above upper so stored is lower
4 - (for current) - same as original
*/
#define CLP_BELOW_LOWER 0
#define CLP_FEASIBLE 1
#define CLP_ABOVE_UPPER 2
#define CLP_SAME 4
#ifndef ClpNonLinearCost_H
inline int originalStatus(unsigned char status)
{
return (status & 15);
}
inline int currentStatus(unsigned char status)
{
return (status >> 4);
}
inline void setOriginalStatus(unsigned char &status, int value)
{
status = static_cast< unsigned char >(status & ~15);
status = static_cast< unsigned char >(status | value);
}
inline void setCurrentStatus(unsigned char &status, int value)
{
status = static_cast< unsigned char >(status & ~(15 << 4));
status = static_cast< unsigned char >(status | (value << 4));
}
inline void setInitialStatus(unsigned char &status)
{
status = static_cast< unsigned char >(CLP_FEASIBLE | (CLP_SAME << 4));
}
inline void setSameStatus(unsigned char &status)
{
status = static_cast< unsigned char >(status & ~(15 << 4));
status = static_cast< unsigned char >(status | (CLP_SAME << 4));
}
#endif
class AbcNonLinearCost {
public:
AbcNonLinearCost();
AbcNonLinearCost(AbcSimplex *model);
~AbcNonLinearCost();
// Copy
AbcNonLinearCost(const AbcNonLinearCost &);
// Assignment
AbcNonLinearCost &operator=(const AbcNonLinearCost &);
void checkInfeasibilities(double oldTolerance = 0.0);
void checkInfeasibilities(int numberInArray, const int *index);
void checkChanged(int numberInArray, CoinIndexedVector *update);
void goThru(int numberInArray, double multiplier,
const int *index, const double *work,
double *rhs);
void goBack(int numberInArray, const int *index,
double *rhs);
void goBackAll(const CoinIndexedVector *update);
void zapCosts();
void refreshCosts(const double *columnCosts);
void feasibleBounds();
void refresh();
void refreshFromPerturbed(double tolerance);
double setOne(int sequence, double solutionValue);
double setOneBasic(int iRow, double solutionValue);
int setOneOutgoing(int sequence, double &solutionValue);
double nearest(int iRow, double solutionValue);
inline double changeInCost(int /*sequence*/, double alpha) const
{
return (alpha > 0.0) ? infeasibilityWeight_ : -infeasibilityWeight_;
}
inline double changeUpInCost(int /*sequence*/) const
{
return -infeasibilityWeight_;
}
inline double changeDownInCost(int /*sequence*/) const
{
return infeasibilityWeight_;
}
inline double changeInCost(int iRow, double alpha, double &rhs)
{
int sequence = model_->pivotVariable()[iRow];
double returnValue = 0.0;
unsigned char iStatus = status_[sequence];
int iWhere = currentStatus(iStatus);
if (iWhere == CLP_SAME)
iWhere = originalStatus(iStatus);
// rhs always increases
if (iWhere == CLP_FEASIBLE) {
if (alpha > 0.0) {
// going below
iWhere = CLP_BELOW_LOWER;
rhs = COIN_DBL_MAX;
} else {
// going above
iWhere = CLP_ABOVE_UPPER;
rhs = COIN_DBL_MAX;
}
} else if (iWhere == CLP_BELOW_LOWER) {
assert(alpha < 0);
// going feasible
iWhere = CLP_FEASIBLE;
rhs += bound_[sequence] - model_->upperRegion()[sequence];
} else {
assert(iWhere == CLP_ABOVE_UPPER);
// going feasible
iWhere = CLP_FEASIBLE;
rhs += model_->lowerRegion()[sequence] - bound_[sequence];
}
setCurrentStatus(status_[sequence], iWhere);
returnValue = fabs(alpha) * infeasibilityWeight_;
return returnValue;
}
inline int numberInfeasibilities() const
{
return numberInfeasibilities_;
}
inline double changeInCost() const
{
return changeCost_;
}
inline double feasibleCost() const
{
return feasibleCost_;
}
double feasibleReportCost() const;
inline double sumInfeasibilities() const
{
return sumInfeasibilities_;
}
inline double largestInfeasibility() const
{
return largestInfeasibility_;
}
inline double averageTheta() const
{
return averageTheta_;
}
inline void setAverageTheta(double value)
{
averageTheta_ = value;
}
inline void setChangeInCost(double value)
{
changeCost_ = value;
}
inline unsigned char *statusArray() const
{
return status_;
}
inline int getCurrentStatus(int sequence)
{
return (status_[sequence] >> 4);
}
void validate();
private:
double changeCost_;
double feasibleCost_;
double infeasibilityWeight_;
double largestInfeasibility_;
double sumInfeasibilities_;
double averageTheta_;
int numberRows_;
int numberColumns_;
AbcSimplex *model_;
int numberInfeasibilities_;
// new stuff
unsigned char *status_;
double *bound_;
double *cost_;
};
#endif
/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
*/
AbcCommon.hpp
setOriginalStatus
void setOriginalStatus(unsigned char &status, int value)
Definition AbcNonLinearCost.hpp:51
CLP_BELOW_LOWER
#define CLP_BELOW_LOWER
Trivial class to deal with non linear costs.
Definition AbcNonLinearCost.hpp:38
setCurrentStatus
void setCurrentStatus(unsigned char &status, int value)
Definition AbcNonLinearCost.hpp:56
currentStatus
int currentStatus(unsigned char status)
Definition AbcNonLinearCost.hpp:47
CLP_FEASIBLE
#define CLP_FEASIBLE
Definition AbcNonLinearCost.hpp:39
CLP_SAME
#define CLP_SAME
Definition AbcNonLinearCost.hpp:41
setSameStatus
void setSameStatus(unsigned char &status)
Definition AbcNonLinearCost.hpp:65
setInitialStatus
void setInitialStatus(unsigned char &status)
Definition AbcNonLinearCost.hpp:61
CLP_ABOVE_UPPER
#define CLP_ABOVE_UPPER
Definition AbcNonLinearCost.hpp:40
originalStatus
int originalStatus(unsigned char status)
Definition AbcNonLinearCost.hpp:43
AbcSimplex
#define AbcSimplex
Definition AbcWarmStart.hpp:16
AbcNonLinearCost::infeasibilityWeight_
double infeasibilityWeight_
Current infeasibility weight.
Definition AbcNonLinearCost.hpp:268
AbcNonLinearCost::changeCost_
double changeCost_
Change in cost because of infeasibilities.
Definition AbcNonLinearCost.hpp:264
AbcNonLinearCost::checkChanged
void checkChanged(int numberInArray, CoinIndexedVector *update)
Puts back correct infeasible costs for each variable The input indices are row indices and need conve...
AbcNonLinearCost::checkInfeasibilities
void checkInfeasibilities(int numberInArray, const int *index)
Changes infeasible costs for each variable The indices are row indices and need converting to sequenc...
AbcNonLinearCost::feasibleCost
double feasibleCost() const
Feasible cost.
Definition AbcNonLinearCost.hpp:217
AbcNonLinearCost::changeDownInCost
double changeDownInCost(int) const
Definition AbcNonLinearCost.hpp:163
AbcNonLinearCost::AbcNonLinearCost
AbcNonLinearCost()
Default constructor.
AbcNonLinearCost::sumInfeasibilities
double sumInfeasibilities() const
Sum of infeasibilities.
Definition AbcNonLinearCost.hpp:224
AbcNonLinearCost::refreshCosts
void refreshCosts(const double *columnCosts)
Refreshes costs always makes row costs zero.
AbcNonLinearCost::numberInfeasibilities_
int numberInfeasibilities_
Number of infeasibilities found.
Definition AbcNonLinearCost.hpp:282
AbcNonLinearCost::zapCosts
void zapCosts()
Temporary zeroing of feasible costs.
AbcNonLinearCost::changeUpInCost
double changeUpInCost(int) const
Definition AbcNonLinearCost.hpp:159
AbcNonLinearCost::feasibleReportCost
double feasibleReportCost() const
Feasible cost with offset and direction (i.e. for reporting).
AbcNonLinearCost::feasibleBounds
void feasibleBounds()
Puts feasible bounds into lower and upper.
AbcNonLinearCost::setOneBasic
double setOneBasic(int iRow, double solutionValue)
Sets bounds and cost for one variable Returns change in cost May need to be inline for speed.
AbcNonLinearCost::setChangeInCost
void setChangeInCost(double value)
Definition AbcNonLinearCost.hpp:242
AbcNonLinearCost::averageTheta_
double averageTheta_
Average theta - kept here as only for primal.
Definition AbcNonLinearCost.hpp:274
AbcNonLinearCost::largestInfeasibility
double largestInfeasibility() const
Largest infeasibility.
Definition AbcNonLinearCost.hpp:229
AbcNonLinearCost::status_
unsigned char * status_
Contains status at beginning and current.
Definition AbcNonLinearCost.hpp:285
AbcNonLinearCost::nearest
double nearest(int iRow, double solutionValue)
Returns nearest bound.
AbcNonLinearCost::checkInfeasibilities
void checkInfeasibilities(double oldTolerance=0.0)
Changes infeasible costs and computes number and cost of infeas Puts all non-basic (non free) variabl...
AbcNonLinearCost::numberColumns_
int numberColumns_
Number of columns (mainly for checking and copy).
Definition AbcNonLinearCost.hpp:278
AbcNonLinearCost::refreshFromPerturbed
void refreshFromPerturbed(double tolerance)
Refresh - from original.
AbcNonLinearCost::numberRows_
int numberRows_
Number of rows (mainly for checking and copy).
Definition AbcNonLinearCost.hpp:276
AbcNonLinearCost::changeInCost
double changeInCost(int, double alpha) const
Returns change in cost - one down if alpha >0.0, up if <0.0 Value is current - new.
Definition AbcNonLinearCost.hpp:155
AbcNonLinearCost::setOneOutgoing
int setOneOutgoing(int sequence, double &solutionValue)
Sets bounds and cost for outgoing variable may change value Returns direction.
AbcNonLinearCost::validate
void validate()
For debug.
AbcNonLinearCost::cost_
double * cost_
Feasible cost array.
Definition AbcNonLinearCost.hpp:289
AbcNonLinearCost::AbcNonLinearCost
AbcNonLinearCost(AbcSimplex *model)
Constructor from simplex.
AbcNonLinearCost::~AbcNonLinearCost
~AbcNonLinearCost()
Destructor.
AbcNonLinearCost::changeInCost
double changeInCost(int iRow, double alpha, double &rhs)
This also updates next bound.
Definition AbcNonLinearCost.hpp:168
AbcNonLinearCost::bound_
double * bound_
Bound which has been replaced in lower_ or upper_.
Definition AbcNonLinearCost.hpp:287
AbcNonLinearCost::changeInCost
double changeInCost() const
Change in cost.
Definition AbcNonLinearCost.hpp:212
AbcNonLinearCost::goBack
void goBack(int numberInArray, const int *index, double *rhs)
Takes off last iteration (i.e.
AbcNonLinearCost::getCurrentStatus
int getCurrentStatus(int sequence)
Definition AbcNonLinearCost.hpp:252
AbcNonLinearCost::averageTheta
double averageTheta() const
Average theta.
Definition AbcNonLinearCost.hpp:234
AbcNonLinearCost::AbcNonLinearCost
AbcNonLinearCost(const AbcNonLinearCost &)
AbcNonLinearCost::numberInfeasibilities
int numberInfeasibilities() const
Number of infeasibilities.
Definition AbcNonLinearCost.hpp:207
AbcNonLinearCost::sumInfeasibilities_
double sumInfeasibilities_
Sum of infeasibilities.
Definition AbcNonLinearCost.hpp:272
AbcNonLinearCost::setOne
double setOne(int sequence, double solutionValue)
Sets bounds and cost for one variable Returns change in cost May need to be inline for speed.
AbcNonLinearCost::largestInfeasibility_
double largestInfeasibility_
Largest infeasibility.
Definition AbcNonLinearCost.hpp:270
AbcNonLinearCost::feasibleCost_
double feasibleCost_
Feasible cost.
Definition AbcNonLinearCost.hpp:266
AbcNonLinearCost::refresh
void refresh()
Refresh - assuming regions OK.
AbcNonLinearCost::goThru
void goThru(int numberInArray, double multiplier, const int *index, const double *work, double *rhs)
Goes through one bound for each variable.
AbcNonLinearCost::model_
AbcSimplex * model_
Model.
Definition AbcNonLinearCost.hpp:280
AbcNonLinearCost::operator=
AbcNonLinearCost & operator=(const AbcNonLinearCost &)
AbcNonLinearCost::goBackAll
void goBackAll(const CoinIndexedVector *update)
Puts back correct infeasible costs for each variable The input indices are row indices and need conve...
AbcNonLinearCost::statusArray
unsigned char * statusArray() const
Definition AbcNonLinearCost.hpp:248
AbcNonLinearCost::setAverageTheta
void setAverageTheta(double value)
Definition AbcNonLinearCost.hpp:238