Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

BCP_problem_core_change Class Reference

#include <BCP_problem_core.hpp>

List of all members.

Public Member Functions

Constructors and destructor
 BCP_problem_core_change (BCP_storage_t store=BCP_Storage_WrtCore)
 BCP_problem_core_change (int bvarnum, BCP_var_set &vars, int bcutnum, BCP_cut_set &cuts)
 BCP_problem_core_change (BCP_storage_t storage, BCP_problem_core_change &ocore, BCP_problem_core_change &ncore)
 ~BCP_problem_core_change ()
Query methods
BCP_storage_t storage () const
size_t varnum () const
size_t cutnum () const
Modifying methods
BCP_problem_core_changeoperator= (const BCP_problem_core &core)
void ensure_explicit (const BCP_problem_core_change &expl_core)
void make_wrtcore_if_shorter (const BCP_problem_core_change &orig_core)
void swap (BCP_problem_core_change &other)
void update (const BCP_problem_core_change &expl_core, const BCP_problem_core_change &core_change)
Packing and unpacking
int pack_size () const
void pack (BCP_buffer &buf) const
void unpack (BCP_buffer &buf)

Public Attributes

Data members
BCP_storage_t _storage
BCP_vec< int > var_pos
BCP_vec< BCP_obj_change > var_ch
BCP_vec< int > cut_pos
BCP_vec< BCP_obj_change > cut_ch

Private Member Functions

Private and disabled methods
void clear ()
 BCP_problem_core_change (const BCP_problem_core_change &)
BCP_problem_core_changeoperator= (const BCP_problem_core_change &x)


Detailed Description

This class describes changes in the core of the problem. While the set of core variables and cuts always remains the same, their bounds and stati may change during processing. An object of this type may store the description of the bounds and stati of the core of three possible ways: This class is internal to the framework, the user shouldn't worry about it.

Definition at line 116 of file BCP_problem_core.hpp.


Constructor & Destructor Documentation

BCP_problem_core_change::BCP_problem_core_change const BCP_problem_core_change  )  [private]
 

The copy constructor is disabled by declaring it private and not defining it.

BCP_problem_core_change::BCP_problem_core_change BCP_storage_t  store = BCP_Storage_WrtCore  )  [inline]
 

This constructor creates a core change with the given storage. The other members are empty, i.e., the created object contains NoData; is Explicit and empty; is WrtCore or WrtParent but there's no change.
Note that the argument defaults to WrtCore, this constructor is the default constructor as well, and as the default constructor it creates a "no change WrtCore" core change.

Definition at line 172 of file BCP_problem_core.hpp.

References _storage, cut_ch, cut_pos, var_ch, and var_pos.

00172                                                                        :
00173        _storage(store), var_pos(), var_ch(), cut_pos(), cut_ch() {}
  

BCP_problem_core_change::BCP_problem_core_change int  bvarnum,
BCP_var_set vars,
int  bcutnum,
BCP_cut_set cuts
 

This constructor creates an Explicit core change description. The first bvarnum variables in vars are the core variables. Similarly for the cuts.

Definition at line 157 of file BCP_problem_core.cpp.

References _storage, BCP_vec< BCP_var * >::begin(), cut_ch, BCP_vec< BCP_var * >::entry(), BCP_var::lb(), BCP_vec< BCP_obj_change >::reserve(), BCP_var::status(), BCP_var::ub(), BCP_vec< BCP_obj_change >::unchecked_push_back(), and var_ch.

00160                                                                     :
00161    _storage(BCP_Storage_Explicit), var_pos(), var_ch(), cut_pos(), cut_ch()
00162 {
00163    _storage = BCP_Storage_Explicit;
00164    var_ch.reserve(bvarnum);
00165 #if 0
00166    BCP_var_set::const_iterator vari;
00167    const BCP_var_set::const_iterator lastvari = vars.entry(bvarnum);
00168    for (vari = vars.begin(); vari != lastvari; ++vari)
00169       var_ch.unchecked_push_back(BCP_obj_change((*vari)->lb(), (*vari)->ub(),
00170                                                 (*vari)->status()));
00171 #else
00172    for (int i = 0; i < bvarnum; ++i) {
00173       const BCP_var* v = vars[i];
00174       var_ch.unchecked_push_back(BCP_obj_change(v->lb(),v->ub(), v->status()));
00175    }
00176 #endif
00177    cut_ch.reserve(bcutnum);
00178    BCP_cut_set::const_iterator cuti;
00179    const BCP_cut_set::const_iterator lastcuti = cuts.entry(bcutnum);
00180    for (cuti = cuts.begin(); cuti != lastcuti; ++cuti)
00181       cut_ch.unchecked_push_back(BCP_obj_change((*cuti)->lb(), (*cuti)->ub(),
00182                                                 (*cuti)->status()));
00183 }

BCP_problem_core_change::BCP_problem_core_change BCP_storage_t  storage,
BCP_problem_core_change ocore,
BCP_problem_core_change ncore
 

Create a core change describing the changes from old_bc to new_bc. Both core change arguments must have explicit storage. The only reason for passing storage as an argument (and not setting it automatically to WrtParent) is that old_bc might be the original core in which case storage must be set to WrtCore.

Definition at line 188 of file BCP_problem_core.cpp.

References cut_ch, cut_pos, BCP_vec< BCP_obj_change >::reserve(), BCP_vec< int >::reserve(), storage(), BCP_vec< BCP_obj_change >::unchecked_push_back(), BCP_vec< int >::unchecked_push_back(), var_ch, and var_pos.

00190                                                         :
00191    _storage(storage), var_pos(), var_ch(), cut_pos(), cut_ch()
00192 {
00193    if (storage != BCP_Storage_WrtParent && storage != BCP_Storage_WrtCore) {
00194       throw BCP_fatal_error("\
00195 BCP_problem_core_change() : bad proposed storage\n");
00196    }
00197 
00198    if (ocore.storage() != BCP_Storage_Explicit)
00199      throw BCP_fatal_error("BCP_problem_core_change() : bad ocore storage\n");
00200    if (ncore.storage() != BCP_Storage_Explicit)
00201      throw BCP_fatal_error("BCP_problem_core_change() : bad ncore storage\n");
00202 
00203    int i;
00204 
00205    const int bvarnum = ncore.varnum();
00206    var_pos.reserve(bvarnum);
00207    var_ch.reserve(bvarnum);
00208    for (i = 0; i < bvarnum; ++i) {
00209       if (ocore.var_ch[i] != ncore.var_ch[i]) {
00210          var_pos.unchecked_push_back(i);
00211          var_ch.unchecked_push_back(ncore.var_ch[i]);
00212       }
00213    }
00214 
00215    const int bcutnum = ncore.cutnum();
00216    cut_pos.reserve(bcutnum);
00217    cut_ch.reserve(bcutnum);
00218    for (i = 0; i < bcutnum; ++i) {
00219       if (ocore.cut_ch[i] != ncore.cut_ch[i]) {
00220          cut_pos.unchecked_push_back(i);
00221          cut_ch.unchecked_push_back(ncore.cut_ch[i]);
00222       }
00223    }
00224 }

BCP_problem_core_change::~BCP_problem_core_change  )  [inline]
 

The destructor deletes all data members.

Definition at line 192 of file BCP_problem_core.hpp.

00192 {}


Member Function Documentation

void BCP_problem_core_change::clear  )  [inline, private]
 

Clear all vector data members.

Definition at line 116 of file BCP_problem_core.cpp.

References BCP_vec< BCP_obj_change >::clear(), BCP_vec< int >::clear(), cut_ch, cut_pos, var_ch, and var_pos.

Referenced by operator=().

00116                                            {
00117    var_pos.clear();
00118    var_ch.clear();
00119    cut_pos.clear();
00120    cut_ch.clear();
00121 }

size_t BCP_problem_core_change::cutnum  )  const [inline]
 

Return the number of changed cuts (the length of the array cut_ch).

Definition at line 204 of file BCP_problem_core.hpp.

References cut_ch, and BCP_vec< BCP_obj_change >::size().

Referenced by make_wrtcore_if_shorter().

00204 { return cut_ch.size(); }

void BCP_problem_core_change::ensure_explicit const BCP_problem_core_change expl_core  ) 
 

If the current storage is not already explicit then replace it with an explicit description of the core generated by applying the currently stored changes to expl_core (which of course, must be explicitly stored).
NOTE: An exception is thrown if the currently stored change is not stored as explicit or WrtCore; or the storage of expl_core is not explicit.

Definition at line 229 of file BCP_problem_core.cpp.

References _storage, storage(), swap(), and update().

00230 {
00231    if (_storage == BCP_Storage_Explicit)
00232       return;
00233    if (_storage != BCP_Storage_WrtCore)
00234       throw BCP_fatal_error("\
00235 BCP_problem_core_change::ensure_explicit() : bad current storage\n");
00236    if (ecore.storage() != BCP_Storage_Explicit)
00237       throw BCP_fatal_error("\
00238 BCP_problem_core_change::ensure_explicit() : bad ecore storage\n");
00239 
00240    BCP_problem_core_change new_core;
00241    new_core.update(ecore, *this);
00242    swap(new_core);
00243 }

void BCP_problem_core_change::make_wrtcore_if_shorter const BCP_problem_core_change orig_core  ) 
 

Replace the current explicitly stored core change with one stored with respect to the explicitly stored original core change in orig_core if the WrtCore description is shorter (requires less space to pack into a buffer).
NOTE: An exception is thrown if either the current storage or that of expl_core is not explicit.

Definition at line 249 of file BCP_problem_core.cpp.

References _storage, cut_ch, cut_pos, cutnum(), BCP_vec< BCP_obj_change >::keep_by_index(), BCP_vec< T >::reserve(), BCP_vec< T >::size(), BCP_vec< BCP_obj_change >::size(), storage(), BCP_vec< int >::swap(), BCP_vec< T >::unchecked_push_back(), var_ch, var_pos, and varnum().

00250 {
00251    if (_storage != BCP_Storage_Explicit)
00252       throw BCP_fatal_error("\
00253 BCP_problem_core_change::make_wrtcore_if_shorter() : bad storage\n");
00254    if (ecore.storage() != BCP_Storage_Explicit)
00255       throw BCP_fatal_error("\
00256 BCP_problem_core_change::make_wrtcore_if_shorter() : bad ecore storage\n");
00257    if (varnum() != ecore.varnum())
00258       throw BCP_fatal_error("\
00259 BCP_problem_core_change::make_wrtcore_if_shorter() : nonequal sizes\n");
00260 
00261    int i;
00262 
00263    // save the positions of the changed vars / cuts
00264    BCP_vec<int> chvar;
00265    chvar.reserve(ecore.varnum());
00266 
00267    const int bvarnum = var_ch.size();
00268    for (i = 0; i < bvarnum; ++i)
00269       if (var_ch[i] != ecore.var_ch[i])
00270          chvar.unchecked_push_back(i);
00271 
00272    BCP_vec<int> chcut;
00273    chcut.reserve(ecore.cutnum());
00274 
00275    const int bcutnum = cut_ch.size();
00276    for (i = 0; i < bcutnum; ++i)
00277       if (cut_ch[i] != ecore.cut_ch[i])
00278          chcut.unchecked_push_back(i);
00279 
00280    if ((chvar.size() + chcut.size()) * sizeof(int) <
00281        (ecore.varnum() - chvar.size() + ecore.cutnum() - chcut.size()) *
00282        BCP_obj_change::pack_size()) {
00283       // wrt core is shorter
00284       _storage = BCP_Storage_WrtCore;
00285       var_pos.swap(chvar);
00286       var_ch.keep_by_index(var_pos);
00287       cut_pos.swap(chcut);
00288       cut_ch.keep_by_index(cut_pos);
00289    }
00290 }

BCP_problem_core_change & BCP_problem_core_change::operator= const BCP_problem_core core  ) 
 

Set the core change description to be an explicit description (in the form of a change) of the given core.

Definition at line 136 of file BCP_problem_core.cpp.

References _storage, BCP_vec< BCP_cut_core * >::begin(), BCP_vec< BCP_var_core * >::begin(), clear(), cut_ch, BCP_problem_core::cutnum(), BCP_problem_core::cuts, BCP_vec< BCP_cut_core * >::end(), BCP_vec< BCP_var_core * >::end(), BCP_vec< BCP_obj_change >::reserve(), BCP_vec< BCP_obj_change >::unchecked_push_back(), var_ch, BCP_problem_core::varnum(), and BCP_problem_core::vars.

00136                                                                {
00137    clear();
00138    _storage = BCP_Storage_Explicit;
00139 
00140    var_ch.reserve(core.varnum());
00141    BCP_vec<BCP_var_core*>::const_iterator vi = core.vars.begin();
00142    const BCP_vec<BCP_var_core*>::const_iterator lastvi = core.vars.end();
00143    for ( ; vi != lastvi; ++vi)
00144       var_ch.unchecked_push_back(BCP_obj_change((*vi)->lb(), (*vi)->ub(),
00145                                                 BCP_ObjNotRemovable));
00146    cut_ch.reserve(core.cutnum());
00147    BCP_vec<BCP_cut_core*>::const_iterator ci = core.cuts.begin();
00148    const BCP_vec<BCP_cut_core*>::const_iterator lastci = core.cuts.end();
00149    for ( ; ci != lastci; ++ci)
00150       cut_ch.unchecked_push_back(BCP_obj_change((*ci)->lb(), (*ci)->ub(),
00151                                                 BCP_ObjNotRemovable));
00152    return *this;
00153 }

BCP_problem_core_change & BCP_problem_core_change::operator= const BCP_problem_core_change x  )  [private]
 

The assignment operator is disabled by declaring it private and not defining it.

Definition at line 124 of file BCP_problem_core.cpp.

References _storage, cut_ch, cut_pos, var_ch, and var_pos.

Referenced by update().

00124                                                                    {
00125    _storage = x._storage;
00126    var_pos = x.var_pos;
00127    var_ch = x.var_ch;
00128    cut_pos = x.cut_pos;
00129    cut_ch = x.cut_ch;
00130    return *this;
00131 }

void BCP_problem_core_change::pack BCP_buffer buf  )  const
 

Pack the core change into the buffer.

Definition at line 353 of file BCP_problem_core.cpp.

References _storage, cut_ch, cut_pos, BCP_buffer::pack(), var_ch, and var_pos.

00353                                                         {
00354    buf.pack(_storage);
00355    if (_storage != BCP_Storage_NoData)
00356       buf.pack(var_pos).pack(cut_pos).pack(var_ch).pack(cut_ch);
00357 }

int BCP_problem_core_change::pack_size  )  const
 

Return the buffer size needed to pack the data in the core change.

Definition at line 342 of file BCP_problem_core.cpp.

References cut_ch, cut_pos, BCP_vec< BCP_obj_change >::size(), BCP_vec< int >::size(), var_ch, and var_pos.

00342                                              {
00343    int siz = sizeof(BCP_storage_t);
00344    siz += sizeof(int) + sizeof(int) * var_pos.size();
00345    siz += sizeof(int) + BCP_obj_change::pack_size() * var_ch.size();
00346    siz += sizeof(int) + sizeof(int) * cut_pos.size();
00347    siz += sizeof(int) + BCP_obj_change::pack_size() * cut_ch.size();
00348    return siz;
00349 }

BCP_storage_t BCP_problem_core_change::storage  )  const [inline]
 

Return the storage type.

Definition at line 198 of file BCP_problem_core.hpp.

References _storage.

Referenced by BCP_problem_core_change(), ensure_explicit(), make_wrtcore_if_shorter(), and update().

00198 { return _storage; }

void BCP_problem_core_change::swap BCP_problem_core_change other  ) 
 

Swap the contents of the current core change with that of other.

Definition at line 294 of file BCP_problem_core.cpp.

References _storage, cut_ch, cut_pos, BCP_vec< BCP_obj_change >::swap(), BCP_vec< int >::swap(), var_ch, and var_pos.

Referenced by ensure_explicit().

00295 {
00296    std::swap(_storage, other._storage);
00297 
00298    var_pos.swap(other.var_pos);
00299    var_ch.swap(other.var_ch);
00300    cut_pos.swap(other.cut_pos);
00301    cut_ch.swap(other.cut_ch);
00302 }

void BCP_problem_core_change::unpack BCP_buffer buf  ) 
 

Unpack the core change data from the buffer.

Definition at line 361 of file BCP_problem_core.cpp.

References _storage, cut_ch, cut_pos, BCP_buffer::unpack(), var_ch, and var_pos.

00361                                                     {
00362    buf.unpack(_storage);
00363    if (_storage != BCP_Storage_NoData)
00364       buf.unpack(var_pos).unpack(cut_pos).unpack(var_ch).unpack(cut_ch);
00365 }

void BCP_problem_core_change::update const BCP_problem_core_change expl_core,
const BCP_problem_core_change core_change
 

Update the current change according to core_change. If the storage type of core_change is

  • NoData or Explicit then it is simply copied over into this change.
  • WrtParent then the current change is supposed to be the parent and this explicitly stored core change will be updated with the changes in core_change (an exception is thrown if the current change is not explicitly stored).
  • WrtCore storage then the current change will be replaced by expl_core updated with core_change (the storage of expl_core must be explicit or an exception is thrown).
NOTE: When this function exits the stored change will have either explicit or NoData storage.

Definition at line 306 of file BCP_problem_core.cpp.

References _storage, cut_ch, cut_pos, operator=(), storage(), BCP_vec< BCP_obj_change >::update(), var_ch, and var_pos.

Referenced by ensure_explicit().

00308 {
00309    switch (ch_core._storage){
00310     case BCP_Storage_Explicit:
00311       operator=(ch_core); // _storage becomes Explicit
00312       break;
00313 
00314     case BCP_Storage_NoData:
00315       _storage = BCP_Storage_NoData;
00316       break;
00317 
00318     case BCP_Storage_WrtCore:
00319       if (expl_core.storage() != BCP_Storage_Explicit)
00320          throw BCP_fatal_error("BCP_problem_core_change::update():\n\
00321    ch_core's WrtCore, but expl_core's not Explicit\n");
00322       operator=(expl_core); // _storage becomes Explicit
00323       // deliberate fall-through
00324 
00325     case BCP_Storage_WrtParent:
00326       if (_storage != BCP_Storage_Explicit)
00327          throw BCP_fatal_error("BCP_problem_core_change::update():\n\
00328    _storage isn't Explicit && ch_core's WrtParent\n");
00329       var_ch.update(ch_core.var_pos, ch_core.var_ch);
00330       cut_ch.update(ch_core.cut_pos, ch_core.cut_ch);
00331       break;
00332 
00333     default:
00334       throw BCP_fatal_error("\
00335 BCP_problem_core_change::update(): bad ch_core storage!\n");
00336       break;
00337    }
00338 }

size_t BCP_problem_core_change::varnum  )  const [inline]
 

Return the number of changed variables (the length of the array var_ch).

Definition at line 201 of file BCP_problem_core.hpp.

References BCP_vec< BCP_obj_change >::size(), and var_ch.

Referenced by make_wrtcore_if_shorter().

00201 { return var_ch.size(); }


Member Data Documentation

BCP_storage_t BCP_problem_core_change::_storage
 

Describes how the change is stored. The interpretation of the other data members depends on the storage type.

  • BCP_Storage_NoData: when no data is stored (i.e., the change is not described yet) the other members are undefined.
  • BCP_Storage_WrtCore: with respect to core storage (as explained in the class description).
  • BCP_Storage_WrtParent: with respect to parent storage (as explained in the class description).
  • BCP_Storage_Explicit: Explicit storage (as explained in the class description).

Definition at line 146 of file BCP_problem_core.hpp.

Referenced by BCP_problem_core_change(), ensure_explicit(), make_wrtcore_if_shorter(), operator=(), pack(), storage(), swap(), unpack(), and update().

BCP_vec<BCP_obj_change> BCP_problem_core_change::cut_ch
 

The new lb/ub/status triplet for each cut for which any of those three have changed.

Definition at line 160 of file BCP_problem_core.hpp.

Referenced by BCP_problem_core_change(), clear(), cutnum(), make_wrtcore_if_shorter(), operator=(), pack(), pack_size(), swap(), unpack(), and update().

BCP_vec<int> BCP_problem_core_change::cut_pos
 

The positions of the core cuts (in the cuts member of [BCP_problem_core]{BCP_problem_core.html}) whose bounds and/or stati have changed.

Definition at line 157 of file BCP_problem_core.hpp.

Referenced by BCP_problem_core_change(), clear(), make_wrtcore_if_shorter(), operator=(), pack(), pack_size(), swap(), unpack(), and update().

BCP_vec<BCP_obj_change> BCP_problem_core_change::var_ch
 

The new lb/ub/status triplet for each variable for which any of those three have changed.

Definition at line 153 of file BCP_problem_core.hpp.

Referenced by BCP_problem_core_change(), clear(), make_wrtcore_if_shorter(), operator=(), pack(), pack_size(), swap(), unpack(), update(), and varnum().

BCP_vec<int> BCP_problem_core_change::var_pos
 

The positions of the core variables (in the vars member of [BCP_problem_core]{BCP_problem_core.html}) whose bounds and/or stati have changed.

Definition at line 150 of file BCP_problem_core.hpp.

Referenced by BCP_problem_core_change(), clear(), make_wrtcore_if_shorter(), operator=(), pack(), pack_size(), swap(), unpack(), and update().


The documentation for this class was generated from the following files:
Generated on Wed Dec 3 14:32:41 2003 for BCP by doxygen 1.3.5