00001 #include <cassert> 00002 using namespace std; 00003 00004 #include "search_engine.h" 00005 #include "state.h" 00006 #include "operator.h" 00007 00008 SearchEngine::SearchEngine() 00009 { 00010 solved = false; 00011 solved_at_least_once = false; 00012 } 00013 00014 SearchEngine::~SearchEngine() 00015 { 00016 } 00017 00018 void SearchEngine::statistics(time_t &) const 00019 { 00020 } 00021 00022 bool SearchEngine::found_solution() const 00023 { 00024 return solved; 00025 } 00026 00027 bool SearchEngine::found_at_least_one_solution() const 00028 { 00029 return solved_at_least_once; 00030 } 00031 00032 const Plan &SearchEngine::get_plan() const 00033 { 00034 assert(solved); 00035 return plan; 00036 } 00037 00038 void SearchEngine::set_plan(const Plan &p) 00039 { 00040 solved = true; 00041 solved_at_least_once = true; 00042 plan = p; 00043 } 00044 00045 const PlanTrace& SearchEngine::get_path() const 00046 { 00047 assert(solved); 00048 return path; 00049 } 00050 00051 void SearchEngine::set_path(const PlanTrace &states) 00052 { 00053 // We need to free the old path as ClosedList::trace_path created new TSSs for us. 00054 for(PlanTrace::const_iterator it = path.begin(); it != path.end(); it++) 00055 delete (*it); 00056 path.clear(); 00057 path = states; 00058 } 00059 00060 enum SearchEngine::status SearchEngine::search() 00061 { 00062 status st = IN_PROGRESS; 00063 while(st == IN_PROGRESS) { 00064 st = step(); 00065 } 00066 if (st == FAILED || st == FAILED_TIMEOUT) { 00067 solved = false; 00068 } 00069 return st; 00070 } 00071