coin-Bcp
BCP_lp_pool.hpp
Go to the documentation of this file.
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 #ifndef _BCP_LP_POOL_H
4 #define _BCP_LP_POOL_H
5 
6 #include "BCP_error.hpp"
7 #include "BCP_vector.hpp"
8 #include "BCP_lp_result.hpp"
9 #include "BCP_matrix.hpp"
10 #include "BCP_var.hpp"
11 #include "BCP_cut.hpp"
12 
13 //#############################################################################
14 
16 private:
19 private:
22  double _violation;
23 public:
24  BCP_lp_waiting_row(BCP_cut* cut, BCP_row* row=0, double viol=-1) :
25  _cut(cut), _row(row), _violation(viol) {}
27  delete _row;
28  delete _cut;
29  }
30 
31  inline BCP_cut* cut() { return _cut; }
32  inline BCP_row* row() { return _row; }
33  inline const BCP_cut* cut() const { return _cut; }
34  inline const BCP_row* row() const { return _row; }
35 
36  inline void clear_cut() { _cut = 0; }
37  inline void delete_row() { delete _row; _row = 0; _violation = -1;}
38  inline void set_row(BCP_row*& row) { _row = row; row = 0; }
39 
40  inline double violation() const { return _violation; }
41  inline void set_violation(double v) { _violation = v; }
42  void compute_violation(const BCP_lp_result& lpres);
43 };
44 
45 //-----------------------------------------------------------------------------
46 
47 class BCP_lp_cut_pool : public BCP_vec<BCP_lp_waiting_row*> {
48 private:
49  static bool _rows_are_valid;
50  // disable the default copy constructor and assignment operator
53 public:
56  purge_ptr_vector(dynamic_cast< BCP_vec<BCP_lp_waiting_row*>& >(*this));
57  }
58 
59  inline bool rows_are_valid() const { return _rows_are_valid; }
60  inline void rows_are_valid(bool status) { _rows_are_valid = status; }
61 
62  inline void compute_violations(const BCP_lp_result& lpres,
65  if (! _rows_are_valid)
66  throw BCP_fatal_error("\
67 BCP_lp_cut_pool::compute_violations() : rows are not valid\n");
68  while (first != last) {
69  (*first)->compute_violation(lpres);
70  ++first;
71  }
72  }
73  int remove_nonviolated(const double etol);
74 };
75 
76 //#############################################################################
77 
79 private:
82 private:
85  double _red_cost;
86 public:
87  BCP_lp_waiting_col(BCP_var* var, BCP_col* col=0, double rc=0) :
88  _var(var), _col(col), _red_cost(rc) {}
90  delete _col;
91  delete _var;
92  }
93 
94  inline BCP_var* var() { return _var; }
95  inline BCP_col* col() { return _col; }
96  inline const BCP_var* var() const { return _var; }
97  inline const BCP_col* col() const { return _col; }
98 
99  inline void clear_var() { _var = 0; }
100  inline void delete_col() { delete _col; _col = 0; _red_cost = 0; }
101  inline void set_col(BCP_col*& col) { _col = col; col = 0; }
102 
103  inline double red_cost() const { return _red_cost; }
104  void compute_red_cost(const BCP_lp_result& lpres);
105 };
106 
107 //-----------------------------------------------------------------------------
108 
109 class BCP_lp_var_pool : public BCP_vec<BCP_lp_waiting_col*> {
110 private:
111  static bool _cols_are_valid;
112  // disable the default copy constructor and assignment operator
115 public:
118  purge_ptr_vector(*(dynamic_cast<BCP_vec<BCP_lp_waiting_col*>*>(this)));
119  }
120 
121  inline bool cols_are_valid() const { return _cols_are_valid; }
122  inline void cols_are_valid(bool status) { _cols_are_valid = status; }
123 
124  inline void compute_red_costs(const BCP_lp_result& lpres,
127  if (! _cols_are_valid)
128  throw BCP_fatal_error("\
129 BCP_lp_var_pool::compute_red_costs() : cols are not valid\n");
130  while (first != last) {
131  (*first)->compute_red_cost(lpres);
132  ++first;
133  }
134  }
135  int remove_positives(const double etol);
136 };
137 
138 #endif
const BCP_row * row() const
Definition: BCP_lp_pool.hpp:34
This class holds a column in a compressed form.
Definition: BCP_matrix.hpp:26
BCP_lp_waiting_row(BCP_cut *cut, BCP_row *row=0, double viol=-1)
Definition: BCP_lp_pool.hpp:24
void set_col(BCP_col *&col)
void cols_are_valid(bool status)
void rows_are_valid(bool status)
Definition: BCP_lp_pool.hpp:60
Abstract base class that defines members common to all types of cuts.
Definition: BCP_cut.hpp:29
BCP_lp_waiting_col(const BCP_lp_waiting_col &)
int remove_nonviolated(const double etol)
const BCP_var * var() const
Definition: BCP_lp_pool.hpp:96
static bool _rows_are_valid
Definition: BCP_lp_pool.hpp:49
void set_row(BCP_row *&row)
Definition: BCP_lp_pool.hpp:38
static bool _cols_are_valid
BCP_lp_waiting_row(const BCP_lp_waiting_row &)
void compute_red_cost(const BCP_lp_result &lpres)
void compute_violation(const BCP_lp_result &lpres)
int remove_positives(const double etol)
BCP_lp_waiting_col & operator=(const BCP_lp_waiting_col &)
bool rows_are_valid() const
Definition: BCP_lp_pool.hpp:59
double red_cost() const
void compute_violations(const BCP_lp_result &lpres, BCP_lp_cut_pool::iterator first, BCP_lp_cut_pool::iterator last)
Definition: BCP_lp_pool.hpp:62
double violation() const
Definition: BCP_lp_pool.hpp:40
const BCP_col * col() const
Definition: BCP_lp_pool.hpp:97
BCP_lp_waiting_col(BCP_var *var, BCP_col *col=0, double rc=0)
Definition: BCP_lp_pool.hpp:87
Abstract base class that defines members common to all types of variables.
Definition: BCP_var.hpp:28
Currently there isn&#39;t any error handling in BCP.
Definition: BCP_error.hpp:20
void set_violation(double v)
Definition: BCP_lp_pool.hpp:41
The class BCP_vec serves the same purpose as the vector class in the standard template library...
Definition: BCP_vector.hpp:24
BCP_lp_var_pool & operator=(const BCP_lp_var_pool &)
void purge_ptr_vector(BCP_vec< T * > &pvec, typename BCP_vec< T * >::iterator first, typename BCP_vec< T * >::iterator last)
This function purges the entries [first,last) from the vector of pointers pvec.
Definition: BCP_vector.hpp:266
const BCP_cut * cut() const
Definition: BCP_lp_pool.hpp:33
BCP_lp_cut_pool & operator=(const BCP_lp_cut_pool &)
This class holds the results after solving an LP relaxation.
bool cols_are_valid() const
void compute_red_costs(const BCP_lp_result &lpres, BCP_lp_var_pool::iterator first, BCP_lp_var_pool::iterator last)
This class holds a row in a compressed form.
Definition: BCP_matrix.hpp:152
BCP_lp_waiting_row & operator=(const BCP_lp_waiting_row &)