bab.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
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "gecode/search.hh"
00039
00040 namespace Gecode { namespace Search {
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 BabEngine::ExploreStatus
00054 BabEngine::explore(Space*& s1, Space*& s2) {
00055 start();
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 while (true) {
00070 assert((es == ES_SOLUTION) || (cur == NULL));
00071 if (stop(stacksize())) {
00072 s1 = NULL;
00073 return ES_SOLUTION;
00074 }
00075 if (cur == NULL) {
00076 if (es == ES_CONSTRAIN) {
00077 es = ES_SOLUTION;
00078 goto same;
00079 }
00080 do {
00081 if (!rcs.next(*this)) {
00082 s1 = NULL;
00083 return ES_SOLUTION;
00084 }
00085 {
00086 int l = rcs.lc(s1);
00087 if (l < mark) {
00088 es = ES_CONSTRAIN;
00089 mark = l;
00090 s2 = best;
00091 return ES_CONSTRAIN;
00092 }
00093 }
00094 same:
00095 cur = rcs.recompute<true>(d,*this);
00096 } while (cur == NULL);
00097 EngineCtrl::current(cur);
00098 }
00099 switch (cur->status(propagate)) {
00100 case SS_FAILED:
00101 fail++;
00102 delete cur;
00103 cur = NULL;
00104 EngineCtrl::current(NULL);
00105 break;
00106 case SS_SOLVED:
00107 delete best;
00108 best = cur;
00109 mark = rcs.entries();
00110 s1 = best->clone();
00111 clone++;
00112 cur = NULL;
00113 EngineCtrl::current(NULL);
00114 return ES_SOLUTION;
00115 case SS_BRANCH:
00116 {
00117 Space* c;
00118 if ((d == 0) || (d >= c_d)) {
00119 c = cur->clone();
00120 clone++;
00121 d = 1;
00122 } else {
00123 c = NULL;
00124 d++;
00125 }
00126 const BranchingDesc* desc = rcs.push(cur,c);
00127 EngineCtrl::push(c,desc);
00128 cur->commit(desc,0);
00129 commit++;
00130 break;
00131 }
00132 default:
00133 GECODE_NEVER;
00134 }
00135 }
00136 return ES_SOLUTION;
00137 }
00138
00139
00140
00141
00142 BAB::BAB(Space* s, unsigned int c_d, unsigned int a_d, Stop* st, size_t sz)
00143 : e(c_d,a_d,st,sz) {
00144 unsigned long int p = 0;
00145 Space* c = (s->status(p) == SS_FAILED) ? NULL : s->clone(true);
00146 e.init(c);
00147 e.propagate += p;
00148 e.current(s);
00149 e.current(NULL);
00150 e.current(c);
00151 if (c == NULL)
00152 e.fail += 1;
00153 }
00154
00155 bool
00156 BAB::stopped(void) const {
00157 return e.stopped();
00158 }
00159
00160 Statistics
00161 BAB::statistics(void) const {
00162 Statistics s = e;
00163 s.memory += e.stacksize();
00164 return s;
00165 }
00166
00167 }}
00168
00169