/home/coin/SVN-release/CoinAll-1.1.0/Bcp/src/include/BCP_lp_pool.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2000, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #ifndef _BCP_LP_POOL_H
00004 #define _BCP_LP_POOL_H
00005 
00006 #include "BCP_error.hpp"
00007 #include "BCP_vector.hpp"
00008 #include "BCP_lp_result.hpp"
00009 #include "BCP_matrix.hpp"
00010 #include "BCP_var.hpp"
00011 #include "BCP_cut.hpp"
00012 
00013 //#############################################################################
00014 
00015 class BCP_lp_waiting_row {
00016 private:
00017    BCP_lp_waiting_row(const BCP_lp_waiting_row&);
00018    BCP_lp_waiting_row& operator=(const BCP_lp_waiting_row&);
00019 private:
00020    BCP_cut* _cut;
00021    BCP_row* _row;
00022    double _violation;
00023 public:
00024    BCP_lp_waiting_row(BCP_cut* cut, BCP_row* row=0, double viol=-1) :
00025       _cut(cut), _row(row), _violation(viol) {}
00026    ~BCP_lp_waiting_row() {
00027       delete _row;
00028       delete _cut;
00029    }
00030 
00031    inline BCP_cut* cut() { return _cut; }
00032    inline BCP_row* row() { return _row; }
00033    inline const BCP_cut* cut() const { return _cut; }
00034    inline const BCP_row* row() const { return _row; }
00035 
00036    inline void clear_cut() { _cut = 0; }
00037    inline void delete_row() { delete _row;  _row = 0; _violation = -1;}
00038    inline void set_row(BCP_row*& row) { _row = row; row = 0; }
00039 
00040    inline double violation() const { return _violation; }
00041    inline void set_violation(double v) { _violation = v; }
00042    void compute_violation(const BCP_lp_result& lpres);
00043 };
00044 
00045 //-----------------------------------------------------------------------------
00046 
00047 class BCP_lp_cut_pool : public BCP_vec<BCP_lp_waiting_row*> {
00048 private:
00049    static bool _rows_are_valid;
00050    // disable the default copy constructor and assignment operator
00051    BCP_lp_cut_pool(const BCP_lp_cut_pool&);
00052    BCP_lp_cut_pool& operator=(const BCP_lp_cut_pool&);
00053 public:
00054    BCP_lp_cut_pool() {}
00055    ~BCP_lp_cut_pool() { 
00056       purge_ptr_vector(dynamic_cast< BCP_vec<BCP_lp_waiting_row*>& >(*this)); 
00057    }
00058 
00059    inline bool rows_are_valid() const { return _rows_are_valid; }
00060    inline void rows_are_valid(bool status) { _rows_are_valid = status; }
00061 
00062    inline void compute_violations(const BCP_lp_result& lpres,
00063                                   BCP_lp_cut_pool::iterator first, 
00064                                   BCP_lp_cut_pool::iterator last) {
00065       if (! _rows_are_valid)
00066          throw BCP_fatal_error("\
00067 BCP_lp_cut_pool::compute_violations() : rows are not valid\n");
00068       while (first != last) {
00069          (*first)->compute_violation(lpres);
00070          ++first;
00071       }
00072    }
00073    int remove_nonviolated(const double etol);
00074 };
00075 
00076 //#############################################################################
00077 
00078 class BCP_lp_waiting_col {
00079 private:
00080    BCP_lp_waiting_col(const BCP_lp_waiting_col&);
00081    BCP_lp_waiting_col& operator=(const BCP_lp_waiting_col&);
00082 private:
00083    BCP_var* _var;
00084    BCP_col* _col;
00085    double _red_cost;
00086 public:
00087    BCP_lp_waiting_col(BCP_var* var, BCP_col* col=0, double rc=0) :
00088       _var(var), _col(col), _red_cost(rc) {}
00089    ~BCP_lp_waiting_col() {
00090       delete _col;
00091       delete _var;
00092    }
00093 
00094    inline BCP_var* var() { return _var; }
00095    inline BCP_col* col() { return _col; }
00096    inline const BCP_var* var() const { return _var; }
00097    inline const BCP_col* col() const { return _col; }
00098 
00099    inline void clear_var() { _var = 0; }
00100    inline void delete_col() { delete _col;   _col = 0; _red_cost = 0; }
00101    inline void set_col(BCP_col*& col) { _col = col; col = 0; }
00102 
00103    inline double red_cost() const { return _red_cost; }
00104    void compute_red_cost(const BCP_lp_result& lpres);
00105 };
00106 
00107 //-----------------------------------------------------------------------------
00108 
00109 class BCP_lp_var_pool : public BCP_vec<BCP_lp_waiting_col*> {
00110 private:
00111    static bool _cols_are_valid;
00112    // disable the default copy constructor and assignment operator
00113    BCP_lp_var_pool(const BCP_lp_var_pool&);
00114    BCP_lp_var_pool& operator=(const BCP_lp_var_pool&);
00115 public:
00116    BCP_lp_var_pool() {}
00117    ~BCP_lp_var_pool() { 
00118       purge_ptr_vector(*(dynamic_cast<BCP_vec<BCP_lp_waiting_col*>*>(this))); 
00119    }
00120 
00121    inline bool cols_are_valid() const { return _cols_are_valid; }
00122    inline void cols_are_valid(bool status) { _cols_are_valid = status; }
00123 
00124    inline void compute_red_costs(const BCP_lp_result& lpres,
00125                                  BCP_lp_var_pool::iterator first, 
00126                                  BCP_lp_var_pool::iterator last) {
00127       if (! _cols_are_valid)
00128          throw BCP_fatal_error("\
00129 BCP_lp_var_pool::compute_red_costs() : cols are not valid\n");
00130       while (first != last) {
00131          (*first)->compute_red_cost(lpres);
00132          ++first;
00133       }
00134    }
00135    int remove_positives(const double etol);
00136 };
00137 
00138 #endif

Generated on Sun Nov 14 14:06:29 2010 for Coin-All by  doxygen 1.4.7