41 template<
class BaseType,
class CoType>
47 Pool<BaseType, CoType>(master),
49 autoRealloc_(autoRealloc)
51 for (
int i = 0; i <
size; i++) {
52 pool_[i] =
new PoolSlot<BaseType, CoType>(master,
this);
53 freeSlots_.pushBack(pool_[i]);
58 template<
class BaseType,
class CoType>
59 StandardPool<BaseType, CoType>::~StandardPool()
63 for (
int i = 0; i < s; i++)
68 template<
class BaseType,
class CoType>
69 std::ostream &
operator<<(std::ostream &out,
const StandardPool<BaseType, CoType> &rhs)
71 const int s = rhs.size();
73 for (
int i = 0; i < s; i++) {
74 if (rhs.pool_[i]->conVar()) {
76 rhs.pool_[i]->conVar()->print(out);
85 template<
class BaseType,
class CoType>
86 PoolSlot<BaseType, CoType> * StandardPool<BaseType, CoType>::insert(
89 PoolSlot<BaseType, CoType>* slot = getSlot();
90 if (slot ==
nullptr) {
93 increase((
int) (
size()*1.1 + 1));
95 if (removeNonActive(
size()/10 + 1) == 0)
103 ++Pool<BaseType, CoType>::number_;
108 template<
class BaseType,
class CoType>
109 void StandardPool<BaseType, CoType>::increase(
int size)
111 int oldSize = pool_.size();
113 if (size < oldSize) {
114 Logger::ifout() <<
"StandardPool::increase(): the pool size cannot be decreased.\n";
120 for(
int i = oldSize; i <
size; i++) {
121 pool_[i] =
new PoolSlot<BaseType, CoType>(Pool<BaseType, CoType>::master_,
this);
122 freeSlots_.pushBack(pool_[i]);
127 template<
class BaseType,
class CoType>
128 int StandardPool<BaseType, CoType>::cleanup()
132 for(
int i = 0; i < Pool<BaseType, CoType>::number(); i++)
134 if(this->softDeleteConVar(pool_[i]) == 0)
139 if (i != Pool<BaseType, CoType>::number())
142 PoolSlot<BaseType, CoType> *CMslot = pool_[i];
143 pool_[i] = pool_[Pool<BaseType, CoType>::number()];
144 pool_[Pool<BaseType, CoType>::number()] = CMslot;
150 Logger::ilout(Logger::Level::Minor) <<
"StandardPool::cleanup(): " << nDeleted <<
" items removed." << std::endl;
155 template<
class BaseType,
class CoType>
156 int StandardPool<BaseType, CoType>::removeNonActive(
int maxRemove)
159 ArrayBuffer<int> elems(
size(),
false);
160 ArrayBuffer<int> keys(
size(),
false);
162 const int s =
size();
164 for (
int i = 0; i < s; i++) {
165 BaseType *cv = pool_[i]->conVar();
166 if (cv && !cv->active() && !cv->locked()) {
168 keys.push(cv->nReferences());
172 AbaBHeap<int, int> candidates(elems, keys);
180 while(nRemoved < maxRemove && !candidates.empty()) {
181 int c = candidates.extractMin();
182 this->hardDeleteConVar(pool_[c]);
186 Logger::ilout(Logger::Level::Minor) << nRemoved <<
" inactive items removed from pool." << std::endl;
192 template<
class BaseType,
class CoType>
193 int StandardPool<BaseType, CoType>::separate(
195 Active<CoType, BaseType> *active,
197 CutBuffer<BaseType, CoType> *cutBuffer,
198 double minAbsViolation,
202 int oldSep = cutBuffer->number();
204 Logger::ilout(Logger::Level::Minor) <<
"StandardPool::separate(): " <<
"size = " <<
size() <<
" n = " << Pool<BaseType, CoType>::number_;
206 PoolSlot<BaseType, CoType> *slot;
207 const int s =
size();
209 for (
int i = 0; i < s; i++) {
211 BaseType *cv = slot->conVar();
212 if (cv && !cv->active() && (cv->global() || cv->valid(sub)))
213 if (cv->violated(active, z, &violation) && fabs(violation) > minAbsViolation) {
215 if (cutBuffer->insert(slot,
true))
218 else if (ranking == 1) {
219 if (cutBuffer->insert(slot,
true, violation))
222 else if (ranking == 2) {
223 if (cutBuffer->insert(slot,
true, fabs(violation)))
226 else if (ranking == 3) {
227 if (cutBuffer->insert(slot,
true, cv->rank()))
233 Logger::ilout(Logger::Level::Minor) <<
" generated = " << cutBuffer->number() - oldSep << std::endl;
234 return cutBuffer->number() - oldSep;