OsiCut.hpp
Go to the documentation of this file.
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 // This code is licensed under the terms of the Eclipse Public License (EPL).
4 
5 #ifndef OsiCut_H
6 #define OsiCut_H
7 
8 #include "OsiCollections.hpp"
9 #include "OsiSolverInterface.hpp"
10 
19 /*
20  COIN_NOTEST_DUPLICATE is rooted in CoinUtils. Check there before you
21  meddle here.
22 */
23 #ifdef COIN_FAST_CODE
24 #ifndef COIN_NOTEST_DUPLICATE
25 #define COIN_NOTEST_DUPLICATE
26 #endif
27 #endif
28 
29 #ifndef COIN_NOTEST_DUPLICATE
30 #define COIN_DEFAULT_VALUE_FOR_DUPLICATE true
31 #else
32 #define COIN_DEFAULT_VALUE_FOR_DUPLICATE false
33 #endif
34 
35 
36 class OsiCut {
37 
38 public:
39 
40  //-------------------------------------------------------------------
43  inline void setEffectiveness( double e );
46  inline double effectiveness() const;
48 
51  inline void setGloballyValid( bool trueFalse )
53  { globallyValid_=trueFalse ? 1 : 0;}
54  inline void setGloballyValid( )
55  { globallyValid_=1;}
56  inline void setNotGloballyValid( )
57  { globallyValid_=0;}
59  inline bool globallyValid() const
60  { return globallyValid_!=0;}
62  inline void setGloballyValidAsInteger( int trueFalse )
63  { globallyValid_=trueFalse;}
65  inline int globallyValidAsInteger() const
66  { return globallyValid_;}
68 
71  virtual void print() const {}
74 
75 #if 0
76  / **@name Times used */
77  / /@{
78  / // Set times used
79  inline void setTimesUsed( int t );
80  / // Increment times used
81  inline void incrementTimesUsed();
82  / // Get times used
83  inline int timesUsed() const;
84  / /@}
85 
86  / **@name Times tested */
87  / /@{
88  / // Set times tested
89  inline void setTimesTested( int t );
90  / // Increment times tested
91  inline void incrementTimesTested();
92  / // Get times tested
93  inline int timesTested() const;
94  / /@}
95 #endif
96 
97  //----------------------------------------------------------------
98 
101  inline virtual bool operator==(const OsiCut& rhs) const;
104  inline virtual bool operator!=(const OsiCut& rhs) const;
106  inline virtual bool operator< (const OsiCut& rhs) const;
108  inline virtual bool operator> (const OsiCut& rhs) const;
110 
111  //----------------------------------------------------------------
112  // consistent() - returns true if the cut is consistent with repect to itself.
113  // This might include checks to ensure that a packed vector
114  // itself does not have a negative index.
115  // consistent(const OsiSolverInterface& si) - returns true if cut is consistent with
116  // respect to the solver interface's model. This might include a check to
117  // make sure a column index is not greater than the number
118  // of columns in the problem.
119  // infeasible(const OsiSolverInterface& si) - returns true if the cut is infeasible
120  // "with respect to itself". This might include a check to ensure
121  // the lower bound is greater than the upper bound, or if the
122  // cut simply replaces bounds that the new bounds are feasible with
123  // respect to the old bounds.
124  //-----------------------------------------------------------------
132  inline virtual bool consistent() const=0;
133 
139  inline virtual bool consistent(const OsiSolverInterface& si) const=0;
140 
162  inline virtual bool infeasible(const OsiSolverInterface &si) const=0;
163 
168  virtual double violated(const double * solution) const=0;
170 
171 protected:
172 
175  OsiCut ();
177 
179  OsiCut ( const OsiCut &);
180 
182  OsiCut & operator=( const OsiCut& rhs);
183 
185  virtual ~OsiCut ();
187 
188 private:
189 
192  double effectiveness_;
196 #if 0
197  int timesUsed_;
200  int timesTested_;
201 #endif
202 
203 };
204 
205 
206 //-------------------------------------------------------------------
207 // Set/Get member data
208 //-------------------------------------------------------------------
210 double OsiCut::effectiveness() const { return effectiveness_; }
211 
212 #if 0
213 void OsiCut::setTimesUsed( int t ) { timesUsed_=t; }
214 void OsiCut::incrementTimesUsed() { timesUsed_++; }
215 int OsiCut::timesUsed() const { return timesUsed_; }
216 
217 void OsiCut::setTimesTested( int t ) { timesTested_=t; }
218 void OsiCut::incrementTimesTested() { timesTested_++; }
219 int OsiCut::timesTested() const{ return timesTested_; }
220 #endif
221 
222 //----------------------------------------------------------------
223 // == operator
224 //-------------------------------------------------------------------
225 bool
226 OsiCut::operator==(const OsiCut& rhs) const
227 {
228  return effectiveness()==rhs.effectiveness();
229 }
230 bool
231 OsiCut::operator!=(const OsiCut& rhs) const
232 {
233  return !( (*this)==rhs );
234 }
235 bool
236 OsiCut::operator< (const OsiCut& rhs) const
237 {
238  return effectiveness()<rhs.effectiveness();
239 }
240 bool
241 OsiCut::operator> (const OsiCut& rhs) const
242 {
243  return effectiveness()>rhs.effectiveness();
244 }
245 #endif
virtual bool consistent() const =0
Returns true if the cut is consistent with respect to itself, without considering any data in the mod...
void setEffectiveness(double e)
Set effectiveness.
Definition: OsiCut.hpp:209
bool globallyValid() const
Get globallyValid.
Definition: OsiCut.hpp:59
virtual void print() const
Print cuts in collection.
Definition: OsiCut.hpp:72
virtual bool infeasible(const OsiSolverInterface &si) const =0
Returns true if the cut is infeasible &quot;with respect to itself&quot; and cannot be satisfied.
virtual ~OsiCut()
Destructor.
void setGloballyValidAsInteger(int trueFalse)
Set globallyValid as integer (nonzero true)
Definition: OsiCut.hpp:62
OsiCut()
Default Constructor.
OsiCut & operator=(const OsiCut &rhs)
Assignment operator.
double effectiveness() const
Get effectiveness.
Definition: OsiCut.hpp:210
int globallyValid_
If cut has global validity i.e. can be used anywhere in tree.
Definition: OsiCut.hpp:195
double effectiveness_
Effectiveness.
Definition: OsiCut.hpp:193
virtual double violated(const double *solution) const =0
Returns infeasibility of the cut with respect to solution passed in i.e.
virtual bool operator!=(const OsiCut &rhs) const
not equal
Definition: OsiCut.hpp:231
Abstract Base Class for describing an interface to a solver.
virtual bool operator<(const OsiCut &rhs) const
less than. True if this.effectiveness &lt; rhs.effectiveness
Definition: OsiCut.hpp:236
virtual bool operator==(const OsiCut &rhs) const
equal. 2 cuts are equal if there effectiveness are equal
Definition: OsiCut.hpp:226
void setNotGloballyValid()
Set globallyValid (nonzero true)
Definition: OsiCut.hpp:56
void setGloballyValid()
Set globallyValid (nonzero true)
Definition: OsiCut.hpp:54
virtual bool operator>(const OsiCut &rhs) const
less than. True if this.effectiveness &gt; rhs.effectiveness
Definition: OsiCut.hpp:241
int globallyValidAsInteger() const
Get globallyValid.
Definition: OsiCut.hpp:65