rbs.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <gecode/search.hh>
00040
00041 namespace Gecode { namespace Search { namespace Meta {
00042
00043
00044
00045
00046
00047
00048 bool
00049 RestartStop::stop(const Statistics& s, const Options& o) {
00050
00051 if (e_stop->stop(s,o)) {
00052 e_stopped = true;
00053 m_stat.restart++;
00054 return true;
00055 }
00056
00057 if ((m_stop != NULL) && m_stop->stop(m_stat+s,o)) {
00058 e_stopped = false;
00059 return true;
00060 }
00061 return false;
00062 }
00063
00064
00065 Space*
00066 RBS::next(void) {
00067 if (restart) {
00068 restart = false;
00069 sslr++;
00070 NoGoods& ng = e->nogoods();
00071
00072 ng.ng(0);
00073 CRI cri(stop->m_stat.restart,sslr,e->statistics().fail,last,ng);
00074 bool r = master->master(cri);
00075 stop->m_stat.nogood += ng.ng();
00076 if (master->status(stop->m_stat) == SS_FAILED) {
00077 stop->update(e->statistics());
00078 delete master;
00079 master = NULL;
00080 e->reset(NULL);
00081 return NULL;
00082 } else if (r) {
00083 stop->update(e->statistics());
00084 Space* slave = master;
00085 master = master->clone(shared);
00086 complete = slave->slave(cri);
00087 e->reset(slave);
00088 sslr = 0;
00089 stop->m_stat.restart++;
00090 }
00091 }
00092 while (true) {
00093 Space* n = e->next();
00094 if (n != NULL) {
00095
00096 restart = true;
00097 delete last;
00098 last = n->clone();
00099 return n;
00100 } else if ( (!complete && !e->stopped()) ||
00101 (e->stopped() && stop->enginestopped()) ) {
00102
00103
00104 sslr = 0;
00105 NoGoods& ng = e->nogoods();
00106 ng.ng(0);
00107 CRI cri(stop->m_stat.restart,sslr,e->statistics().fail,last,ng);
00108 (void) master->master(cri);
00109 stop->m_stat.nogood += ng.ng();
00110 long unsigned int nl = ++(*co);
00111 stop->limit(e->statistics(),nl);
00112 if (master->status(stop->m_stat) == SS_FAILED)
00113 return NULL;
00114 Space* slave = master;
00115 master = master->clone(shared);
00116 complete = slave->slave(cri);
00117 e->reset(slave);
00118 } else {
00119 return NULL;
00120 }
00121 }
00122 GECODE_NEVER;
00123 return NULL;
00124 }
00125
00126 Search::Statistics
00127 RBS::statistics(void) const {
00128 return stop->metastatistics()+e->statistics();
00129 }
00130
00131 bool
00132 RBS::stopped(void) const {
00133
00134
00135
00136
00137
00138
00139
00140 return e->stopped();
00141 }
00142
00143 RBS::~RBS(void) {
00144
00145 delete e;
00146 delete master;
00147 delete last;
00148 delete co;
00149 }
00150
00151 }}}
00152
00153