| 1052 | /** Build our RL trace. -bazald **/ |
| 1053 | |
| 1054 | void build_rl_trace(agent* const& thisAgent, preference* const& candidates, preference* const& selected) ///< bazald |
| 1055 | { |
| 1056 | if (thisAgent->rl_params->trace->get_value() == off) |
| 1057 | { |
| 1058 | return; |
| 1059 | } |
| 1060 | |
| 1061 | agent::RL_Trace** next = NIL; |
| 1062 | |
| 1063 | for (preference* cand = candidates; cand; cand = cand->next_candidate) |
| 1064 | { |
| 1065 | if (cand->inst && cand->inst->prod) |
| 1066 | { |
| 1067 | // std::cerr << "rl-trace: " << cand->inst->prod->name->sc->name << std::endl; |
| 1068 | |
| 1069 | // for(preference *pref = cand->inst->match_goal->id->operator_slot->preferences[NUMERIC_INDIFFERENT_PREFERENCE_TYPE]; pref; pref = pref->next) { |
| 1070 | // production * const &prod2 = pref->inst->prod; |
| 1071 | // if(cand->value == pref->value && prod2->rl_rule) { |
| 1072 | // std::cerr << "rl-trace: +" << prod2->name->sc->name << std::endl; |
| 1073 | // } |
| 1074 | // } |
| 1075 | |
| 1076 | std::vector<std::string> index_str; |
| 1077 | index_str.push_back("^name"); |
| 1078 | // for(wme *w = thisAgent->all_wmes_in_rete; w; w = w->rete_next) { |
| 1079 | for (slot* s = cand->value->id->slots; s; s = s->next) |
| 1080 | { |
| 1081 | for (wme* w = s->wmes; w; w = w->next) |
| 1082 | { |
| 1083 | if (cand->value == w->id) |
| 1084 | { |
| 1085 | const std::string attr = symbol_to_string(thisAgent, w->attr, false, NIL, 0); |
| 1086 | const std::string value = symbol_to_string(thisAgent, w->value, false, NIL, 0); |
| 1087 | // std::cerr << "rl-trace: ^" << attr << ' ' << value << std::endl; |
| 1088 | |
| 1089 | if (attr == "name") |
| 1090 | { |
| 1091 | index_str[0] += ' ' + value; |
| 1092 | } |
| 1093 | else |
| 1094 | { |
| 1095 | index_str.push_back('^' + attr + ' ' + value); |
| 1096 | } |
| 1097 | |
| 1098 | std::sort(++index_str.begin(), index_str.end()); |
| 1099 | } |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | const double probability = cand->rl_contribution |
| 1104 | ? exploration_probability_according_to_policy(thisAgent, candidates->slot, candidates, cand) |
| 1105 | : nan(""); |
| 1106 | |
| 1107 | // std::cerr << "rl-trace: =" << probability << std::endl; |
| 1108 | |
| 1109 | agent::RL_Trace* const rl_trace = static_cast<agent::RL_Trace*>(candidates->slot->id->id->rl_trace); |
| 1110 | rl_trace->split[index_str].init = thisAgent->rl_init_count; |
| 1111 | rl_trace->split[index_str].probability = probability; |
no test coverage detected