00001 00037 #ifndef ABA_OPENSUB_H 00038 #define ABA_OPENSUB_H 00039 00040 00041 #include "abacus/dlist.h" 00042 00043 #ifdef ABACUS_PARALLEL 00044 #include <ace/Synch.h> 00045 #endif 00046 00047 class ABA_MASTER; 00048 class ABA_SUB; 00049 00050 class ABA_OPENSUB : public ABA_ABACUSROOT { 00051 friend class ABA_SUB; 00052 friend class ABA_MASTER; 00053 #ifdef ABACUS_PARALLEL 00054 friend class ABA_SUBSERVER; 00055 friend class ABA_PARMASTER; 00056 #endif 00057 public: 00058 00067 ABA_OPENSUB(ABA_MASTER *master); 00068 00071 int number() const; 00072 00076 bool empty() const; 00077 00080 double dualBound() const; 00081 #ifdef ABACUS_PARALLEL 00082 00085 void terminate(); 00086 00095 ABA_SUB *getSubproblemWithBound(double bound); 00096 void triggerSelect(); 00097 #endif 00098 00099 private: 00100 00112 ABA_SUB *select(); 00113 00118 void insert(ABA_SUB *sub); 00119 00124 void remove(ABA_SUB *sub); 00125 00128 void prune(); 00129 00133 void updateDualBound(); 00134 00137 ABA_MASTER *master_; 00138 #ifdef ABACUS_PARALLEL 00139 00142 ABA_DLIST<ABA_SUB*> list_; 00143 00146 volatile int n_; 00147 00150 double dualBound_; 00151 mutable ACE_Thread_Mutex mutex_; 00152 ACE_Condition<ACE_Thread_Mutex> cond_; 00153 volatile bool terminate_; 00154 volatile bool hasTerminated_; 00155 #else 00156 00159 ABA_DLIST<ABA_SUB*> list_; 00160 00163 int n_; 00164 00167 double dualBound_; 00168 #endif 00169 ABA_OPENSUB(const ABA_OPENSUB &rhs); 00170 const ABA_OPENSUB &operator=(const ABA_OPENSUB &rhs); 00171 }; 00172 00173 00174 inline int ABA_OPENSUB::number() const 00175 { 00176 return n_; 00177 } 00178 00179 inline bool ABA_OPENSUB::empty() const 00180 { 00181 return list_.empty(); 00182 } 00183 00184 #ifdef ABACUS_PARALLEL 00185 inline void ABA_OPENSUB::triggerSelect() 00186 { 00187 cond_.signal(); 00188 } 00189 #endif 00190 00191 #endif // ABA_OPENSUB_H 00192