bab-reco.cc
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 #include "search/bab-reco.hh"
00025
00026 namespace Gecode { namespace Search {
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 BabReCoEngine::~BabReCoEngine(void) {
00040 ds.reset();
00041 delete best;
00042 delete cur;
00043 }
00044
00045 size_t
00046 BabReCoEngine::stacksize(void) const {
00047 return ds.size();
00048 }
00049
00050 bool
00051 BabReCoEngine::explore(Space*& s1, Space*& s2) {
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 while (true) {
00064 if (cur == NULL) {
00065 if (!ds.next(*this)) {
00066 s1 = NULL;
00067 return true;
00068 }
00069 cur = ds.recompute(d,*this);
00070 FullStatistics::current(cur);
00071 if (ds.entries() <= mark) {
00072
00073 mark = ds.entries();
00074 d = 0;
00075 s1 = cur;
00076 s2 = best;
00077 return false;
00078 }
00079 }
00080 unsigned int alt;
00081 switch (cur->status(alt,propagate)) {
00082 case SS_FAILED:
00083 fail++;
00084 delete cur;
00085 cur = NULL;
00086 FullStatistics::current(NULL);
00087 break;
00088 case SS_SOLVED:
00089 delete best;
00090 best = cur;
00091 mark = ds.entries();
00092 s1 = best->clone();
00093 clone++;
00094 cur = NULL;
00095 FullStatistics::current(NULL);
00096 return true;
00097 case SS_BRANCH:
00098 {
00099 Space* c;
00100 if ((d == 0) || (d >= c_d)) {
00101 c = cur->clone();
00102 clone++;
00103 d = 1;
00104 } else {
00105 c = NULL;
00106 if (alt > 1)
00107 d++;
00108 }
00109 BranchingDesc* desc = ds.push(cur,c,alt);
00110 FullStatistics::push(c,desc);
00111 cur->commit(0,desc,propagate);
00112 commit++;
00113 break;
00114 }
00115 }
00116 }
00117 return true;
00118 }
00119
00120 }}
00121
00122