1/* $Id: ClpConstraint.hpp 1665 2011-01-04 17:55:54Z lou $ */
2// Copyright (C) 2007, 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 ClpConstraint_H
7#define ClpConstraint_H
8
9
10//#############################################################################
11class ClpSimplex;
12class ClpModel;
13
14/** Constraint Abstract Base Class
15
16Abstract Base Class for describing a constraint or objective function
17
18*/
19class ClpConstraint {
20
21public:
22
23 ///@name Stuff
24 //@{
25
26 /** Fills gradient. If Linear then solution may be NULL,
27 also returns true value of function and offset so we can use x not deltaX in constraint
28 If refresh is false then uses last solution
29 Uses model for scaling
30 Returns non-zero if gradient undefined at current solution
31 */
32 virtual int gradient(const ClpSimplex * model,
33 const double * solution,
34 double * gradient,
35 double & functionValue ,
36 double & offset,
37 bool useScaling = false,
38 bool refresh = true) const = 0;
39 /// Constraint function value
40 virtual double functionValue (const ClpSimplex * model,
41 const double * solution,
42 bool useScaling = false,
43 bool refresh = true) const ;
44 /// Resize constraint
45 virtual void resize(int newNumberColumns) = 0;
46 /// Delete columns in constraint
47 virtual void deleteSome(int numberToDelete, const int * which) = 0;
48 /// Scale constraint
49 virtual void reallyScale(const double * columnScale) = 0;
50 /** Given a zeroed array sets nonlinear columns to 1.
51 Returns number of nonlinear columns
52 */
53 virtual int markNonlinear(char * which) const = 0;
54 /** Given a zeroed array sets possible nonzero coefficients to 1.
55 Returns number of nonzeros
56 */
57 virtual int markNonzero(char * which) const = 0;
58 //@}
59
60
61 ///@name Constructors and destructors
62 //@{
63 /// Default Constructor
64 ClpConstraint();
65
66 /// Copy constructor
67 ClpConstraint(const ClpConstraint &);
68
69 /// Assignment operator
70 ClpConstraint & operator=(const ClpConstraint& rhs);
71
72 /// Destructor
73 virtual ~ClpConstraint ();
74
75 /// Clone
76 virtual ClpConstraint * clone() const = 0;
77
78 //@}
79
80 ///@name Other
81 //@{
82 /// Returns type, 0 linear, 1 nonlinear
83 inline int type() {
84 return type_;
85 }
86 /// Row number (-1 is objective)
87 inline int rowNumber() const {
88 return rowNumber_;
89 }
90
91 /// Number of possible coefficients in gradient
92 virtual int numberCoefficients() const = 0;
93
94 /// Stored constraint function value
95 inline double functionValue () const {
96 return functionValue_;
97 }
98
99 /// Constraint offset
100 inline double offset () const {
101 return offset_;
102 }
103 /// Say we have new primal solution - so may need to recompute
104 virtual void newXValues() {}
105 //@}
106
107 //---------------------------------------------------------------------------
108
109protected:
110 ///@name Protected member data
111 //@{
112 /// Gradient at last evaluation
113 mutable double * lastGradient_;
114 /// Value of non-linear part of constraint
115 mutable double functionValue_;
116 /// Value of offset for constraint
117 mutable double offset_;
118 /// Type of constraint - linear is 1
119 int type_;
120 /// Row number (-1 is objective)
121 int rowNumber_;
122 //@}
123};
124
125#endif
126