/home/coin/SVN-release/Bcp-1.2.1/Bcp/src/include/BCP_var.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_VAR_H
00004 #define _BCP_VAR_H
00005 
00006 // This file is fully docified.
00007 
00008 //#############################################################################
00009 
00010 #include "CoinSmartPtr.hpp"
00011 #include "BCP_error.hpp"
00012 #include "BCP_enum.hpp"
00013 #include "BCP_vector.hpp"
00014 #include "BCP_obj_change.hpp"
00015 
00016 //#############################################################################
00017 
00018 // Generic variable definition.
00019 
00028 class BCP_var : public Coin::ReferencedObject {
00029 private:
00034     BCP_var();
00036     BCP_var(const BCP_var&);
00038     BCP_var& operator=(const BCP_var&);
00041 private:
00046     int  _bcpind;
00048     BCP_obj_status _status;
00051 protected:
00055     BCP_var_t _var_type;
00057     double    _obj;
00059     double    _lb;
00061     double    _ub;
00064 public:
00071     BCP_var(const BCP_var_t var_type,
00072             const double obj, const double lb, const double ub) :
00073        _bcpind(0), _status(BCP_ObjNoInfo),
00074        _var_type(var_type), _obj(obj), _lb(lb), _ub(ub) {}
00077     virtual ~BCP_var() {}
00083     virtual BCP_object_t obj_type() const = 0;
00085     inline BCP_var_t var_type() const   { return _var_type; }
00087     inline double obj() const           { return _obj; }
00089     inline double lb() const            { return _lb; }
00091     inline double ub() const            { return _ub; }
00093     inline int bcpind() const { return _bcpind; }
00094 
00098       inline BCP_obj_status status() const   { return _status; }
00102       inline bool dont_send_to_pool() const {
00103         return _status & BCP_ObjDoNotSendToPool ? true : false;
00104       }
00106       inline bool is_fixed() const {
00107         return (_status & BCP_ObjInactive) != 0;
00108       }
00110       inline bool is_fixed_to_zero() const {
00111         return (_status & BCP_ObjInactive) && _lb == 0;
00112       }
00115       inline bool is_non_removable() const {
00116         return (_status & BCP_ObjNotRemovable) ? true : false;
00117       }
00121       inline bool is_removable() const {
00122         return (_status & BCP_ObjNotRemovable) ? false : is_fixed_to_zero();
00123       }
00127       inline bool is_to_be_removed() const {
00128         return (_status & BCP_ObjToBeRemoved) != 0;
00129       }
00132 
00136     inline void test_inactive() {
00137       if (_ub - _lb < 1e-8)
00138         _status = static_cast<BCP_obj_status>(_status | BCP_ObjInactive);
00139     }
00141     inline void set_var_type(const BCP_var_t type) { _var_type = type; }
00143     inline void set_obj(const double obj)          { _obj = obj; }
00145     inline void set_lb(const double lb)            {
00146       _lb = lb;
00147       test_inactive();
00148     }
00150     inline void set_ub(const double ub)            {
00151       _ub = ub;
00152       test_inactive();
00153     }
00155     inline void set_lb_ub(const double lb, const double ub) {
00156       _lb = lb;
00157       _ub = ub;
00158       test_inactive();
00159     }
00163     inline void change_lb_ub_st(const BCP_obj_change& change) {
00164        _lb = change.lb;
00165        _ub = change.ub;
00166        _status = change.stat;
00167        test_inactive();
00168     }
00170     inline void change_bounds(const double lb, const double ub) {
00171        _lb = lb;
00172        _ub = ub;
00173        test_inactive();
00174     }
00176     inline void set_bcpind(const int bcpind)  { _bcpind = bcpind; }
00178     inline void set_bcpind_flip()  { _bcpind = -_bcpind; }
00179 
00183       inline void set_status(const BCP_obj_status status) { _status = status; }
00186       inline void dont_send_to_pool(bool flag) {
00187          _status =
00188            static_cast<BCP_obj_status>(flag ?
00189                                        _status | BCP_ObjDoNotSendToPool :
00190                                        _status & ~BCP_ObjDoNotSendToPool);
00191       }
00195       inline void make_active() {
00196          _status = static_cast<BCP_obj_status>(_status & ~BCP_ObjInactive);
00197       }
00199       inline void make_non_removable() {
00200          _status =
00201            static_cast<BCP_obj_status>((_status & ~BCP_ObjToBeRemoved) |
00202                                        BCP_ObjNotRemovable);
00203       }
00207       inline void make_to_be_removed() {
00208          _status = BCP_ObjToBeRemoved;
00209       }
00217     void display(const double val) const;
00219 };
00220 
00221 //#############################################################################
00222 //#############################################################################
00223 
00230 class BCP_var_core : public BCP_var {
00231 private:
00235    BCP_var_core();
00237    BCP_var_core& operator=(const BCP_var_core&);
00240 public:
00244    BCP_var_core(const BCP_var_core& x) :
00245       BCP_var(x._var_type, x._obj, x._lb, x._ub) {
00246       set_bcpind(x.bcpind());
00247       set_status(x.status());
00248    }
00251    BCP_var_core(const BCP_var_t var_type,
00252                 const double obj, const double lb, const double ub) :
00253       BCP_var(var_type, obj, lb, ub) {}
00255    ~BCP_var_core() {}
00261    inline BCP_object_t obj_type() const  { return BCP_CoreObj; }
00263 };
00264 
00265 //#############################################################################
00266 
00267 // This is the class the user should derive his/her own algorithmic vars
00268 
00277 class BCP_var_algo : public BCP_var {
00278 private:
00282    BCP_var_algo();
00284    BCP_var_algo(const BCP_var_algo&);
00286    BCP_var_algo& operator=(const BCP_var_algo&);
00289 public:
00294    BCP_var_algo(const BCP_var_t var_type,
00295                 const double obj, const double lb, const double ub) :
00296       BCP_var(var_type, obj, lb, ub) {}
00298    virtual ~BCP_var_algo() = 0;
00305    inline BCP_object_t obj_type() const   { return BCP_AlgoObj; }
00307 };
00308 
00309 //#############################################################################
00310 //#############################################################################
00311 
00316 class BCP_var_set : public BCP_vec<BCP_var*> {
00317 private:
00321    BCP_var_set(const BCP_var_set&);
00323    BCP_var_set& operator=(const BCP_var_set&);
00326 public:
00331    BCP_var_set() {}
00335    ~BCP_var_set() {}
00342    inline void append(const BCP_vec<BCP_var*>& x) {
00343       BCP_vec<BCP_var*>::append(x);
00344    }
00347    inline void append(BCP_var_set::const_iterator first,
00348                       BCP_var_set::const_iterator last){
00349       BCP_vec<BCP_var*>::append(first, last);
00350    }
00351 
00355    void set_lb_ub(const BCP_vec<int>& pos,
00356                   BCP_vec<double>::const_iterator bounds);
00363    void set_lb_ub_st(const BCP_vec<BCP_obj_change>& vc);
00367    void set_lb_ub_st(BCP_vec<int>::const_iterator pos,
00368                      const BCP_vec<BCP_obj_change>& vc);
00370    //--------------------------------------------------------------------------
00376    void deletable(const int bvarnum, BCP_vec<int>& collection);
00377    // *FIXME* shouldn't we keep a local var pool in the lp process and move
00378    // deletables to this pool? compare w/ cuts...
00380    //--------------------------------------------------------------------------
00381 };
00382 
00383 #endif

Generated on Thu Jan 15 03:00:59 2009 for coin-Bcp by  doxygen 1.4.7