/home/coin/SVN-release/CoinAll-1.1.0/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 "BCP_error.hpp"
00011 #include "BCP_enum.hpp"
00012 #include "BCP_vector.hpp"
00013 #include "BCP_obj_change.hpp"
00014 
00015 //#############################################################################
00016 
00017 // Generic variable definition.
00018 
00027 class BCP_var{
00028 private:
00033     BCP_var();
00035     BCP_var(const BCP_var&);
00037     BCP_var& operator=(const BCP_var&);
00040 private:
00045     int  _bcpind;
00047     BCP_obj_status _status;
00050 protected:
00054     BCP_var_t _var_type;
00056     double    _obj;
00058     double    _lb;
00060     double    _ub;
00063 public:
00070     BCP_var(const BCP_var_t var_type,
00071             const double obj, const double lb, const double ub) :
00072        _bcpind(0), _status(BCP_ObjNoInfo),
00073        _var_type(var_type), _obj(obj), _lb(lb), _ub(ub) {}
00076     virtual ~BCP_var() {}
00082     virtual BCP_object_t obj_type() const = 0;
00084     inline BCP_var_t var_type() const   { return _var_type; }
00086     inline double obj() const           { return _obj; }
00088     inline double lb() const            { return _lb; }
00090     inline double ub() const            { return _ub; }
00092     inline int bcpind() const { return _bcpind; }
00093 
00097       inline BCP_obj_status status() const   { return _status; }
00101       inline bool dont_send_to_pool() const {
00102         return _status & BCP_ObjDoNotSendToPool ? true : false;
00103       }
00105       inline bool is_fixed() const {
00106         return (_status & BCP_ObjInactive) != 0;
00107       }
00109       inline bool is_fixed_to_zero() const {
00110         return (_status & BCP_ObjInactive) && _lb == 0;
00111       }
00114       inline bool is_non_removable() const {
00115         return (_status & BCP_ObjNotRemovable) ? true : false;
00116       }
00120       inline bool is_removable() const {
00121         return (_status & BCP_ObjNotRemovable) ? false : is_fixed_to_zero();
00122       }
00126       inline bool is_to_be_removed() const {
00127         return (_status & BCP_ObjToBeRemoved) != 0;
00128       }
00131 
00135     inline void test_inactive() {
00136       if (_ub - _lb < 1e-8)
00137         _status = static_cast<BCP_obj_status>(_status | BCP_ObjInactive);
00138     }
00140     inline void set_var_type(const BCP_var_t type) { _var_type = type; }
00142     inline void set_obj(const double obj)          { _obj = obj; }
00144     inline void set_lb(const double lb)            {
00145       _lb = lb;
00146       test_inactive();
00147     }
00149     inline void set_ub(const double ub)            {
00150       _ub = ub;
00151       test_inactive();
00152     }
00156     inline void change_lb_ub_st(const BCP_obj_change& change) {
00157        _lb = change.lb;
00158        _ub = change.ub;
00159        _status = change.stat;
00160        test_inactive();
00161     }
00163     inline void change_bounds(const double lb, const double ub) {
00164        _lb = lb;
00165        _ub = ub;
00166        test_inactive();
00167     }
00169     inline void set_bcpind(const int bcpind)  { _bcpind = bcpind; }
00170 
00174       inline void set_status(const BCP_obj_status status) { _status = status; }
00177       inline void dont_send_to_pool(bool flag) {
00178          _status =
00179            static_cast<BCP_obj_status>(flag ?
00180                                        _status | BCP_ObjDoNotSendToPool :
00181                                        _status & ~BCP_ObjDoNotSendToPool);
00182       }
00186       inline void make_active() {
00187          _status = static_cast<BCP_obj_status>(_status & ~BCP_ObjInactive);
00188       }
00190       inline void make_non_removable() {
00191          _status =
00192            static_cast<BCP_obj_status>((_status & ~BCP_ObjToBeRemoved) |
00193                                        BCP_ObjNotRemovable);
00194       }
00198       inline void make_to_be_removed() {
00199          _status = BCP_ObjToBeRemoved;
00200       }
00208     void display(const double val) const;
00210 };
00211 
00212 //#############################################################################
00213 //#############################################################################
00214 
00221 class BCP_var_core : public BCP_var {
00222 private:
00226    BCP_var_core();
00228    BCP_var_core& operator=(const BCP_var_core&);
00231 public:
00235    BCP_var_core(const BCP_var_core& x) :
00236       BCP_var(x._var_type, x._obj, x._lb, x._ub) {
00237       set_bcpind(x.bcpind());
00238       set_status(x.status());
00239    }
00242    BCP_var_core(const BCP_var_t var_type,
00243                 const double obj, const double lb, const double ub) :
00244       BCP_var(var_type, obj, lb, ub) {}
00246    ~BCP_var_core() {}
00252    inline BCP_object_t obj_type() const  { return BCP_CoreObj; }
00254 };
00255 
00256 //#############################################################################
00257 
00263 class BCP_var_indexed : public BCP_var {
00264 private:
00269    int _index;  
00271 private:
00275    BCP_var_indexed();
00277    BCP_var_indexed(const BCP_var_indexed&);
00279    BCP_var_indexed& operator=(const BCP_var_indexed&);
00282 public:
00287    BCP_var_indexed(const int index, const BCP_var_t var_type,
00288                    const double obj, const double lb, const double ub) :
00289       BCP_var(var_type, obj, lb, ub), _index(index) {}
00291    ~BCP_var_indexed() {}
00297    inline int index() const               { return _index; }
00300    inline BCP_object_t obj_type() const   { return BCP_IndexedObj; }
00302 };
00303 
00304 //#############################################################################
00305 
00306 // This is the class the user should derive his/her own algorithmic vars
00307 
00316 class BCP_var_algo : public BCP_var {
00317 private:
00321    BCP_var_algo();
00323    BCP_var_algo(const BCP_var_algo&);
00325    BCP_var_algo& operator=(const BCP_var_algo&);
00328 public:
00333    BCP_var_algo(const BCP_var_t var_type,
00334                 const double obj, const double lb, const double ub) :
00335       BCP_var(var_type, obj, lb, ub) {}
00337    virtual ~BCP_var_algo() = 0;
00344    inline BCP_object_t obj_type() const   { return BCP_AlgoObj; }
00346 };
00347 
00348 //#############################################################################
00349 //#############################################################################
00350 
00355 class BCP_var_set : public BCP_vec<BCP_var*> {
00356 private:
00360    BCP_var_set(const BCP_var_set&);
00362    BCP_var_set& operator=(const BCP_var_set&);
00365 public:
00370    BCP_var_set() {}
00374    ~BCP_var_set() {}
00381    inline void append(const BCP_vec<BCP_var*>& x) {
00382       BCP_vec<BCP_var*>::append(x);
00383    }
00386    inline void append(BCP_var_set::const_iterator first,
00387                       BCP_var_set::const_iterator last){
00388       BCP_vec<BCP_var*>::append(first, last);
00389    }
00390 
00394    void set_lb_ub(const BCP_vec<int>& pos,
00395                   BCP_vec<double>::const_iterator bounds);
00402    void set_lb_ub_st(const BCP_vec<BCP_obj_change>& vc);
00406    void set_lb_ub_st(BCP_vec<int>::const_iterator pos,
00407                      const BCP_vec<BCP_obj_change>& vc);
00409    //--------------------------------------------------------------------------
00415    void deletable(const int bvarnum, BCP_vec<int>& collection);
00416    // *FIXME* shouldn't we keep a local var pool in the lp process and move
00417    // deletables to this pool? compare w/ cuts...
00419    //--------------------------------------------------------------------------
00420 };
00421 
00422 #endif

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