dfs.icc
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 namespace Gecode {
00039
00040 namespace Search {
00041
00042
00043
00044
00045
00046 forceinline
00047 DfsEngine::DfsEngine(unsigned int c_d0, unsigned int a_d0,
00048 Stop* st, size_t sz)
00049 : EngineCtrl(st,sz), rcs(a_d0), cur(NULL), c_d(c_d0), d(0) {}
00050
00051
00052 forceinline void
00053 DfsEngine::init(Space* s) {
00054 cur = s;
00055 }
00056
00057 forceinline void
00058 DfsEngine::reset(Space* s) {
00059 delete cur;
00060 rcs.reset();
00061 cur = s;
00062 d = 0;
00063 EngineCtrl::reset(s);
00064 }
00065
00066 forceinline void
00067 DfsEngine::reset(void) {
00068 delete cur;
00069 rcs.reset();
00070 cur = NULL;
00071 d = 0;
00072 EngineCtrl::reset();
00073 }
00074
00075 forceinline size_t
00076 DfsEngine::stacksize(void) const {
00077 return rcs.stacksize();
00078 }
00079
00080 forceinline Space*
00081 DfsEngine::explore(void) {
00082 start();
00083 while (true) {
00084 while (cur) {
00085 if (stop(stacksize()))
00086 return NULL;
00087 switch (cur->status(propagate)) {
00088 case SS_FAILED:
00089 fail++;
00090 delete cur;
00091 cur = NULL;
00092 EngineCtrl::current(NULL);
00093 break;
00094 case SS_SOLVED:
00095 {
00096 Space* s = cur;
00097 cur = NULL;
00098 EngineCtrl::current(NULL);
00099 return s;
00100 }
00101 case SS_BRANCH:
00102 {
00103 Space* c;
00104 if ((d == 0) || (d >= c_d)) {
00105 clone++;
00106 c = cur->clone();
00107 d = 1;
00108 } else {
00109 c = NULL;
00110 d++;
00111 }
00112 const BranchingDesc* desc = rcs.push(cur,c);
00113 EngineCtrl::push(c,desc);
00114 commit++;
00115 cur->commit(desc,0);
00116 break;
00117 }
00118 default: GECODE_NEVER;
00119 }
00120 }
00121 if (!rcs.next(*this))
00122 return NULL;
00123 cur = rcs.recompute<false>(d,*this);
00124 EngineCtrl::current(cur);
00125 }
00126 return NULL;
00127 }
00128
00129 forceinline
00130 DfsEngine::~DfsEngine(void) {
00131 delete cur;
00132 rcs.reset();
00133 }
00134
00135 }
00136
00137
00138
00139
00140
00141
00142 template <class T>
00143 forceinline
00144 DFS<T>::DFS(T* s, const Search::Options& o)
00145 : Search::DFS(s,o.c_d,o.a_d,o.stop,sizeof(T)) {}
00146
00147 template <class T>
00148 forceinline T*
00149 DFS<T>::next(void) {
00150 return dynamic_cast<T*>(Search::DFS::next());
00151 }
00152
00153
00154
00155
00156
00157
00158
00159
00160 template <class T>
00161 forceinline T*
00162 dfs(T* s, const Search::Options& o) {
00163 DFS<T> d(s,o);
00164 return dynamic_cast<T*>(d.next());
00165 }
00166
00167 }
00168
00169