Go to the documentation of this file.00001 #include "heuristic.h"
00002 #include "operator.h"
00003
00004 using namespace std;
00005
00006 Heuristic::Heuristic()
00007 {
00008 heuristic = NOT_INITIALIZED;
00009 num_computations = 0;
00010 }
00011
00012 Heuristic::~Heuristic()
00013 {
00014 }
00015
00016 void Heuristic::set_preferred(const Operator *op)
00017 {
00018 if(op->get_name().compare("wait") == 0) {
00019 const ScheduledOperator *s_op = dynamic_cast<const ScheduledOperator*>(op);
00020 assert(op);
00021 set_waiting_time(min(waiting_time, s_op->time_increment));
00022 return;
00023 }
00024 for(int i = 0; i < preferred_operators.size(); i++) {
00025 if(preferred_operators[i] == op) {
00026 return;
00027 }
00028 }
00029 preferred_operators.push_back(op);
00030 }
00031
00032 double Heuristic::evaluate(const TimeStampedState &state)
00033 {
00034
00035 if(heuristic == NOT_INITIALIZED)
00036 initialize();
00037 preferred_operators.clear();
00038 heuristic = compute_heuristic(state);
00039 num_computations++;
00040 assert(heuristic == DEAD_END || heuristic >= 0);
00041
00042 if(heuristic == DEAD_END) {
00043
00044
00045
00046
00047 preferred_operators.clear();
00048 }
00049
00050
00051 #ifndef NDEBUG
00052 if(heuristic != DEAD_END) {
00053
00054
00055
00056
00057
00058 }
00059 #endif
00060 return heuristic;
00061 }
00062
00063 bool Heuristic::is_dead_end()
00064 {
00065 return heuristic == DEAD_END;
00066 }
00067
00068 double Heuristic::get_heuristic()
00069 {
00070
00071
00072
00073 assert(heuristic >= 0);
00074 return heuristic;
00075 }
00076
00077 void Heuristic::get_preferred_operators(std::vector<const Operator *> &result)
00078 {
00079 assert(heuristic >= 0);
00080 result.insert(result.end(), preferred_operators.begin(),
00081 preferred_operators.end());
00082 }