| 1 | /* $Id: ClpQuadraticObjective.hpp 1665 2011-01-04 17:55:54Z lou $ */ |
| 2 | // Copyright (C) 2003, International Business Machines |
| 3 | // Corporation and others. All Rights Reserved. |
| 4 | // This code is licensed under the terms of the Eclipse Public License (EPL). |
| 5 | |
| 6 | #ifndef ClpQuadraticObjective_H |
| 7 | #define ClpQuadraticObjective_H |
| 8 | |
| 9 | #include "ClpObjective.hpp" |
| 10 | #include "CoinPackedMatrix.hpp" |
| 11 | |
| 12 | //############################################################################# |
| 13 | |
| 14 | /** Quadratic Objective Class |
| 15 | |
| 16 | */ |
| 17 | |
| 18 | class ClpQuadraticObjective : public ClpObjective { |
| 19 | |
| 20 | public: |
| 21 | |
| 22 | ///@name Stuff |
| 23 | //@{ |
| 24 | |
| 25 | /** Returns gradient. If Quadratic then solution may be NULL, |
| 26 | also returns an offset (to be added to current one) |
| 27 | If refresh is false then uses last solution |
| 28 | Uses model for scaling |
| 29 | includeLinear 0 - no, 1 as is, 2 as feasible |
| 30 | */ |
| 31 | virtual double * gradient(const ClpSimplex * model, |
| 32 | const double * solution, double & offset, bool refresh, |
| 33 | int includeLinear = 2) override; |
| 34 | /// Resize objective |
| 35 | /** Returns reduced gradient.Returns an offset (to be added to current one). |
| 36 | */ |
| 37 | virtual double reducedGradient(ClpSimplex * model, double * region, |
| 38 | bool useFeasibleCosts) override; |
| 39 | /** Returns step length which gives minimum of objective for |
| 40 | solution + theta * change vector up to maximum theta. |
| 41 | |
| 42 | arrays are numberColumns+numberRows |
| 43 | Also sets current objective, predicted and at maximumTheta |
| 44 | */ |
| 45 | virtual double stepLength(ClpSimplex * model, |
| 46 | const double * solution, |
| 47 | const double * change, |
| 48 | double maximumTheta, |
| 49 | double & currentObj, |
| 50 | double & predictedObj, |
| 51 | double & thetaObj) override; |
| 52 | /// Return objective value (without any ClpModel offset) (model may be NULL) |
| 53 | virtual double objectiveValue(const ClpSimplex * model, const double * solution) const override ; |
| 54 | virtual void resize(int newNumberColumns) override ; |
| 55 | /// Delete columns in objective |
| 56 | virtual void deleteSome(int numberToDelete, const int * which) override ; |
| 57 | /// Scale objective |
| 58 | virtual void reallyScale(const double * columnScale) override ; |
| 59 | /** Given a zeroed array sets nonlinear columns to 1. |
| 60 | Returns number of nonlinear columns |
| 61 | */ |
| 62 | virtual int markNonlinear(char * which) override; |
| 63 | |
| 64 | //@} |
| 65 | |
| 66 | |
| 67 | ///@name Constructors and destructors |
| 68 | //@{ |
| 69 | /// Default Constructor |
| 70 | ClpQuadraticObjective(); |
| 71 | |
| 72 | /// Constructor from objective |
| 73 | ClpQuadraticObjective(const double * linearObjective, int numberColumns, |
| 74 | const CoinBigIndex * start, |
| 75 | const int * column, const double * element, |
| 76 | int numberExtendedColumns_ = -1); |
| 77 | |
| 78 | /** Copy constructor . |
| 79 | If type is -1 then make sure half symmetric, |
| 80 | if +1 then make sure full |
| 81 | */ |
| 82 | ClpQuadraticObjective(const ClpQuadraticObjective & rhs, int type = 0); |
| 83 | /** Subset constructor. Duplicates are allowed |
| 84 | and order is as given. |
| 85 | */ |
| 86 | ClpQuadraticObjective (const ClpQuadraticObjective &rhs, int numberColumns, |
| 87 | const int * whichColumns) ; |
| 88 | |
| 89 | /// Assignment operator |
| 90 | ClpQuadraticObjective & operator=(const ClpQuadraticObjective& rhs); |
| 91 | |
| 92 | /// Destructor |
| 93 | virtual ~ClpQuadraticObjective (); |
| 94 | |
| 95 | /// Clone |
| 96 | virtual ClpObjective * clone() const override; |
| 97 | /** Subset clone. Duplicates are allowed |
| 98 | and order is as given. |
| 99 | */ |
| 100 | virtual ClpObjective * subsetClone (int numberColumns, |
| 101 | const int * whichColumns) const override; |
| 102 | |
| 103 | /** Load up quadratic objective. This is stored as a CoinPackedMatrix */ |
| 104 | void loadQuadraticObjective(const int numberColumns, |
| 105 | const CoinBigIndex * start, |
| 106 | const int * column, const double * element, |
| 107 | int numberExtendedColumns = -1); |
| 108 | void loadQuadraticObjective ( const CoinPackedMatrix& matrix); |
| 109 | /// Get rid of quadratic objective |
| 110 | void deleteQuadraticObjective(); |
| 111 | //@} |
| 112 | ///@name Gets and sets |
| 113 | //@{ |
| 114 | /// Quadratic objective |
| 115 | inline CoinPackedMatrix * quadraticObjective() const { |
| 116 | return quadraticObjective_; |
| 117 | } |
| 118 | /// Linear objective |
| 119 | inline double * linearObjective() const { |
| 120 | return objective_; |
| 121 | } |
| 122 | /// Length of linear objective which could be bigger |
| 123 | inline int numberExtendedColumns() const { |
| 124 | return numberExtendedColumns_; |
| 125 | } |
| 126 | /// Number of columns in quadratic objective |
| 127 | inline int numberColumns() const { |
| 128 | return numberColumns_; |
| 129 | } |
| 130 | /// If a full or half matrix |
| 131 | inline bool fullMatrix() const { |
| 132 | return fullMatrix_; |
| 133 | } |
| 134 | //@} |
| 135 | |
| 136 | //--------------------------------------------------------------------------- |
| 137 | |
| 138 | private: |
| 139 | ///@name Private member data |
| 140 | /// Quadratic objective |
| 141 | CoinPackedMatrix * quadraticObjective_; |
| 142 | /// Objective |
| 143 | double * objective_; |
| 144 | /// Gradient |
| 145 | double * gradient_; |
| 146 | /// Useful to have number of columns about |
| 147 | int numberColumns_; |
| 148 | /// Also length of linear objective which could be bigger |
| 149 | int numberExtendedColumns_; |
| 150 | /// True if full symmetric matrix, false if half |
| 151 | bool fullMatrix_; |
| 152 | //@} |
| 153 | }; |
| 154 | |
| 155 | #endif |
| 156 | |