| 199 | } |
| 200 | |
| 201 | void ModelReusableAgent::updateReuseModel() { |
| 202 | if (this->_previousActions.empty()) |
| 203 | return; |
| 204 | ActionPtr lastAction = this->_previousActions.back(); |
| 205 | ActivityNameActionPtr modelAction = std::dynamic_pointer_cast<ActivityNameAction>( |
| 206 | lastAction); |
| 207 | if (nullptr == modelAction || nullptr == this->_newState) |
| 208 | return; |
| 209 | auto hash = (uint64_t) modelAction->hash(); |
| 210 | stringPtr activity = this->_newState->getActivityString(); // mark: use the _newstate as last selected action's target |
| 211 | if (activity == nullptr) |
| 212 | return; |
| 213 | { |
| 214 | std::lock_guard<std::mutex> reuseGuard(this->_reuseModelLock); |
| 215 | auto iter = this->_reuseModel.find(hash); |
| 216 | if (iter == this->_reuseModel.end()) { |
| 217 | BDLOG("can not find action %s in reuse map", modelAction->getId().c_str()); |
| 218 | ReuseEntryM entryMap; |
| 219 | entryMap.emplace(std::make_pair(activity, 1)); |
| 220 | this->_reuseModel[hash] = entryMap; |
| 221 | } else { |
| 222 | ((*iter).second)[activity] += 1; |
| 223 | } |
| 224 | auto qValueReuseEntryIter = this->_reuseQValue.find(hash); |
| 225 | this->_reuseQValue[hash] = modelAction->getQValue(); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | ActivityStateActionPtr ModelReusableAgent::selectNewActionEpsilonGreedyRandomly() const { |
| 230 | if (this->eGreedy()) { |
no test coverage detected