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/meta/rbs.hh>
00040
00041 namespace Gecode { namespace Search { namespace Meta {
00042
00043 bool
00044 RestartStop::stop(const Statistics& s, const Options& o) {
00045
00046 if (s.fail > l) {
00047 e_stopped = true;
00048 m_stat.restart++;
00049 return true;
00050 }
00051
00052 if ((m_stop != NULL) && m_stop->stop(m_stat+s,o)) {
00053 e_stopped = false;
00054 return true;
00055 }
00056 return false;
00057 }
00058
00059
00060 Space*
00061 RBS::next(void) {
00062 if (restart) {
00063 restart = false;
00064 sslr++;
00065 NoGoods& ng = e->nogoods();
00066
00067 ng.ng(0);
00068 MetaInfo mi(stop->m_stat.restart,sslr,e->statistics().fail,last,ng);
00069 bool r = master->master(mi);
00070 stop->m_stat.nogood += ng.ng();
00071 if (master->status(stop->m_stat) == SS_FAILED) {
00072 stop->update(e->statistics());
00073 delete master;
00074 master = NULL;
00075 e->reset(NULL);
00076 return NULL;
00077 } else if (r) {
00078 stop->update(e->statistics());
00079 Space* slave = master;
00080 master = master->clone(shared_data,shared_info);
00081 complete = slave->slave(mi);
00082 e->reset(slave);
00083 sslr = 0;
00084 stop->m_stat.restart++;
00085 }
00086 }
00087 while (true) {
00088 Space* n = e->next();
00089 if (n != NULL) {
00090
00091 restart = true;
00092 delete last;
00093 last = n->clone(shared_data);
00094 return n;
00095 } else if ( (!complete && !e->stopped()) ||
00096 (e->stopped() && stop->enginestopped()) ) {
00097
00098
00099 sslr = 0;
00100 NoGoods& ng = e->nogoods();
00101 ng.ng(0);
00102 MetaInfo mi(stop->m_stat.restart,sslr,e->statistics().fail,last,ng);
00103 (void) master->master(mi);
00104 stop->m_stat.nogood += ng.ng();
00105 long unsigned int nl = ++(*co);
00106 stop->limit(e->statistics(),nl);
00107 if (master->status(stop->m_stat) == SS_FAILED)
00108 return NULL;
00109 Space* slave = master;
00110 master = master->clone(shared_data,shared_info);
00111 complete = slave->slave(mi);
00112 e->reset(slave);
00113 } else {
00114 return NULL;
00115 }
00116 }
00117 GECODE_NEVER;
00118 return NULL;
00119 }
00120
00121 Search::Statistics
00122 RBS::statistics(void) const {
00123 return stop->metastatistics()+e->statistics();
00124 }
00125
00126 void
00127 RBS::constrain(const Space& b) {
00128 if (!best)
00129 throw NoBest("RBS::constrain");
00130 if (last != NULL) {
00131 last->constrain(b);
00132 if (last->status() == SS_FAILED) {
00133 delete last;
00134 } else {
00135 return;
00136 }
00137 }
00138 last = b.clone(shared_data);
00139 master->constrain(b);
00140 e->constrain(b);
00141 }
00142
00143 bool
00144 RBS::stopped(void) const {
00145
00146
00147
00148
00149
00150
00151
00152 return e->stopped();
00153 }
00154
00155 RBS::~RBS(void) {
00156 delete e;
00157 delete master;
00158 delete last;
00159 delete co;
00160 delete stop;
00161 }
00162
00163 }}}
00164
00165