dfs-copy.cc
Go to the documentation of this file.00001 /* 00002 * Main authors: 00003 * Christian Schulte <schulte@gecode.org> 00004 * 00005 * Copyright: 00006 * Christian Schulte, 2004 00007 * 00008 * Last modified: 00009 * $Date: 2005-08-09 21:44:53 +0200 (Tue, 09 Aug 2005) $ by $Author: schulte $ 00010 * $Revision: 2192 $ 00011 * 00012 * This file is part of Gecode, the generic constraint 00013 * development environment: 00014 * http://www.gecode.org 00015 * 00016 * See the file "LICENSE" for information on usage and 00017 * redistribution of this file, and for a 00018 * DISCLAIMER OF ALL WARRANTIES. 00019 * 00020 */ 00021 00022 00023 00024 #include "search/dfs-copy.hh" 00025 00026 namespace Gecode { namespace Search { 00027 00028 DfsCopyEngine::~DfsCopyEngine(void) { 00029 delete cur; 00030 ds.reset(); 00031 } 00032 00033 void 00034 DfsCopyEngine::reset(Space* s) { 00035 delete cur; 00036 ds.reset(); 00037 cur = s; 00038 FullStatistics::reset(s); 00039 } 00040 00041 size_t 00042 DfsCopyEngine::stacksize(void) const { 00043 return ds.size(); 00044 } 00045 00046 Space* 00047 DfsCopyEngine::explore(void) { 00048 while (true) { 00049 if (cur == NULL) { 00050 if (ds.empty()) 00051 return NULL; 00052 unsigned int alt = ds.top().alt(); 00053 if (ds.top().rightmost()) { 00054 cur = ds.pop().space(); 00055 FullStatistics::pop(cur); 00056 } else { 00057 clone++; 00058 cur = ds.top().space()->clone(true,propagate); 00059 ds.top().next(); 00060 } 00061 commit++; 00062 cur->commit(alt,NULL,propagate); 00063 FullStatistics::current(cur); 00064 } 00065 unsigned int alt; 00066 switch (cur->status(alt,propagate)) { 00067 case SS_FAILED: { 00068 fail++; 00069 delete cur; 00070 cur = NULL; 00071 FullStatistics::current(NULL); 00072 break; 00073 } 00074 case SS_SOLVED: { 00075 Space *s = cur; 00076 cur = NULL; 00077 FullStatistics::current(NULL); 00078 return s; 00079 } 00080 case SS_BRANCH: { 00081 if (alt > 1) { 00082 ds.push(cur,alt); 00083 FullStatistics::push(ds.top().space()); 00084 clone++; 00085 } 00086 commit++; 00087 cur->commit(0,NULL,propagate); 00088 break; 00089 } 00090 } 00091 } 00092 } 00093 00094 }} 00095 00096 // STATISTICS: search-any