Space* RBS::next(void) { if (restart) { restart = false; sslr++; NoGoods& ng = e->nogoods(); // Reset number of no-goods found ng.ng(0); MetaInfo mi(stop->m_stat.restart,sslr,e->statistics().fail,last,ng); bool r = master->master(mi); stop->m_stat.nogood += ng.ng(); if (master->status(stop->m_stat) == SS_FAILED) { stop->update(e->statistics()); delete master; master = NULL; e->reset(NULL); return NULL; } else if (r) { stop->update(e->statistics()); Space* slave = master; master = master->clone(shared_data,shared_info); complete = slave->slave(mi); e->reset(slave); sslr = 0; stop->m_stat.restart++; } } while (true) { Space* n = e->next(); if (n != NULL) { // The engine found a solution restart = true; delete last; last = n->clone(); return n; } else if ( (!complete && !e->stopped()) || (e->stopped() && stop->enginestopped()) ) { // The engine must perform a true restart // The number of the restart has been incremented in the stop object sslr = 0; NoGoods& ng = e->nogoods(); ng.ng(0); MetaInfo mi(stop->m_stat.restart,sslr,e->statistics().fail,last,ng); (void) master->master(mi); stop->m_stat.nogood += ng.ng(); long unsigned int nl = ++(*co); stop->limit(e->statistics(),nl); if (master->status(stop->m_stat) == SS_FAILED) return NULL; Space* slave = master; master = master->clone(shared_data,shared_info); complete = slave->slave(mi); e->reset(slave); } else { return NULL; } } GECODE_NEVER; return NULL; }
forceinline RBS<E,T>::RBS(T* s, const Search::Options& m_opt) { if (m_opt.cutoff == NULL) throw Search::UninitializedCutoff("RBS::RBS"); Search::Options e_opt(m_opt.expand()); e_opt.clone = false; Search::Meta::RestartStop* rs = new Search::Meta::RestartStop(m_opt.stop); e_opt.stop = rs; Space* master; Space* slave; if (s->status(rs->m_stat) == SS_FAILED) { rs->m_stat.fail++; master = NULL; slave = NULL; } else { if (m_opt.clone) master = s->clone(); else master = s; slave = master->clone(); CRI cri(0,0,0,NULL,NoGoods::eng); slave->slave(cri); } E<T> engine(dynamic_cast<T*>(slave),e_opt); Search::EngineBase<T>* eb = &engine; Search::Engine* ee = eb->e; eb->e = NULL; e = new Search::Meta::RBS(master,rs,ee,m_opt); }
Space* RBS::next(void) { while (true) { Space* n = e->next(); unsigned long int i = stop->m_stat.restart; if (n != NULL) { NoGoods& ng = e->nogoods(); ng.ng(0); master->constrain(*n); master->master(i,n,ng); stop->m_stat.nogood += ng.ng(); stop->update(e->statistics()); if (master->status(stop->m_stat) == SS_FAILED) { delete master; master = NULL; e->reset(NULL); } else { Space* slave = master; master = master->clone(shared); slave->slave(i,n); e->reset(slave); } return n; } else if (e->stopped() && stop->enginestopped()) { NoGoods& ng = e->nogoods(); ng.ng(0); master->master(i,NULL,ng); stop->m_stat.nogood += ng.ng(); long unsigned int nl = (*co)(); stop->limit(e->statistics(),nl); if (master->status(stop->m_stat) == SS_FAILED) return NULL; Space* slave = master; master = master->clone(shared); slave->slave(i,n); e->reset(slave); } else { return NULL; } } GECODE_NEVER; return NULL; }