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