00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "nel/ai/nimat/mhics.h"
00027 #include "nel/misc/file.h"
00028
00029 namespace NLAINIMAT
00030 {
00031 using namespace NLMISC;
00032
00033 static const TTargetId NullTargetId = 0;
00034
00036
00038 CMotivationEnergy::CMotivationEnergy()
00039 {
00040 _SumValue = 0;
00041 _MHiCSagent = NULL;
00042
00043 }
00044
00045 CMotivationEnergy::~CMotivationEnergy()
00046 {
00047 }
00048
00049 double CMotivationEnergy::getSumValue() const
00050 {
00051 return _SumValue;
00052 }
00053
00054 void CMotivationEnergy::removeProvider(TMotivation providerName)
00055 {
00056 _MotivationProviders.erase(providerName);
00057 computeMotivationValue();
00058 }
00059
00060
00061
00062
00063
00064
00065
00066 void CMotivationEnergy::addProvider(TMotivation providerName, TClassifierNumber classifierNumber)
00067 {
00068 _MotivationProviders[providerName].insert(classifierNumber);
00069 computeMotivationValue();
00070 }
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 void CMotivationEnergy::computeMotivationValue()
00096 {
00097 _EnergyByMotivation.clear();
00098
00099 TMotivation lastMotivationName = Motivation_Unknown;
00100
00101 std::multimap<TMotivation, std::set<TClassifierNumber> >::iterator itMotivationProviders;
00102 for (itMotivationProviders = _MotivationProviders.begin();
00103 itMotivationProviders != _MotivationProviders.end();
00104 itMotivationProviders++)
00105 {
00106 uint32 lastMaxMotiveValue = 0;
00107 TMotivation motivationName = (*itMotivationProviders).first;
00108 std::set<TClassifierNumber>::iterator itClassifierNumber;
00109 for (itClassifierNumber = (*itMotivationProviders).second.begin(); itClassifierNumber != (*itMotivationProviders).second.end(); itClassifierNumber++)
00110 {
00111 TClassifierNumber classierNumber = (*itClassifierNumber);
00112 uint32 classifierTimer = _MHiCSagent->getMHiCSbase()->getPriorityPart(motivationName, classierNumber).getClassifierTimer();;
00113 bool wasPreviouslyActived = _MHiCSagent->wasClassifierPreviouslyActive(motivationName,classierNumber);
00114 if (wasPreviouslyActived)
00115 {
00116 uint32 temporaryClassifierPriorityTime = _MHiCSagent->getTemporaryClassifierPriorityTime(motivationName, classierNumber);
00117
00118 if (temporaryClassifierPriorityTime > classifierTimer + 15)
00119 {
00120 classifierTimer = temporaryClassifierPriorityTime;
00121 }
00122 else
00123 {
00124 classifierTimer -=1;
00125 }
00126 }
00127 double motiveValue = _MHiCSagent->getMotivationValue(motivationName);
00128 double motivePP = _MHiCSagent->getMotivationPP(motivationName);
00129 uint32 priorityTimer = _MHiCSagent->getMHiCSbase()->getPriorityPart(motivationName, classierNumber).getPriorityTimer();
00130 priorityTimer = std::max(priorityTimer, classifierTimer);
00131
00132
00133 uint32 combinedValue = (motiveValue * 10000.0) - priorityTimer;
00134 if (combinedValue > lastMaxMotiveValue)
00135 {
00136 lastMaxMotiveValue = combinedValue;
00137 _EnergyByMotivation[motivationName].Value = combinedValue;
00138 _EnergyByMotivation[motivationName].PP = motivePP;
00139 }
00140 }
00141 }
00142
00143 TEnergyByMotivation::const_iterator itEnergyByMotivation;
00144 double sum = 0;
00145 for (itEnergyByMotivation = _EnergyByMotivation.begin(); itEnergyByMotivation != _EnergyByMotivation.end(); itEnergyByMotivation++)
00146 {
00147 sum += (*itEnergyByMotivation).second.Value * (*itEnergyByMotivation).second.PP;
00148 }
00149 sum += _MyMotivationValue.PP * _MyMotivationValue.Value;
00150
00151 _SumValue = sum;
00152 nlassert(_SumValue >= 0);
00153 }
00154
00156 void CMotivationEnergy::setMotivationPP(TMotivation motivationName, double PP)
00157 {
00158 _SumValue -= _MyMotivationValue.Value * _MyMotivationValue.PP;
00159 _SumValue += _MyMotivationValue.Value * PP;
00160 _EnergyByMotivation[motivationName].PP = PP;
00161 _MyMotivationValue.PP = PP;
00162 nlassert(_SumValue >= 0);
00163 }
00164
00166 double CMotivationEnergy::getMotivationPP(TMotivation motivationName) const
00167 {
00168 return _MyMotivationValue.PP;
00169 }
00170
00172 void CMotivationEnergy::setMotivationValue(TMotivation motivationName, double value)
00173 {
00174 nlassert(value >= 0);
00175 _SumValue -= _MyMotivationValue.Value * _MyMotivationValue.PP;
00176 nlassert(_SumValue >= 0);
00177 _SumValue += value * _MyMotivationValue.PP;
00178 _EnergyByMotivation[motivationName].Value = value;
00179 _MyMotivationValue.Value = value;
00180
00181 nlassert(_SumValue >= 0);
00182 }
00183
00185 double CMotivationEnergy::getMotivationValue(TMotivation motivationName) const
00186 {
00187 return _MyMotivationValue.Value;
00188 }
00189
00190 const std::map<TMotivation, std::set<TClassifierNumber> >* CMotivationEnergy::getProviders() const
00191 {
00192 return &_MotivationProviders;
00193 }
00194
00196 void CMotivationEnergy::getDebugString(std::string &t) const
00197 {
00198 std::string ret;
00199 TEnergyByMotivation::const_iterator itEnergyByMotivation;
00200
00201 for (itEnergyByMotivation = _EnergyByMotivation.begin(); itEnergyByMotivation!= _EnergyByMotivation.end(); itEnergyByMotivation++)
00202 {
00203 ret += " " + conversionMotivation.toString((*itEnergyByMotivation).first) + " (" + NLMISC::toString((*itEnergyByMotivation).second.Value * (*itEnergyByMotivation).second.PP) + ") ";
00204 }
00205 t+=ret;
00206 }
00207
00209
00211
00212 CMHiCSbase::CMHiCSbase()
00213 {
00214 pActionResources = new CActionResources();
00215 }
00216
00217 CMHiCSbase::~CMHiCSbase()
00218 {
00219 delete pActionResources;
00220 }
00221
00222 void CMHiCSbase::addVirtualActionCS(const CActionClassifiers &action)
00223 {
00224 const std::map<TMotivation, CClassifierSystem> *mapActionByMotivation = action.getClassifiersByMotivationMap();
00225 std::map<TMotivation, CClassifierSystem>::const_iterator ItMapActionByMotivation;
00226 for (ItMapActionByMotivation = mapActionByMotivation->begin(); ItMapActionByMotivation != mapActionByMotivation->end(); ItMapActionByMotivation++)
00227 {
00228 CClassifierSystem* pCS;
00229 TMotivation motivationName = (*ItMapActionByMotivation).first;
00230 const CClassifierSystem* pOtherCS = &((*ItMapActionByMotivation).second);
00231
00232 pCS = &(_MotivationClassifierSystems[motivationName]);
00233 pCS->addClassifierSystem(*pOtherCS);
00234 }
00235
00236 const std::map<TAction, CClassifierSystem> *mapActionByVirtualAction = action.getClassifiersByVirtualActionMap();
00237 std::map<TAction, CClassifierSystem>::const_iterator ItMapActionByVirtualAction;
00238 for (ItMapActionByVirtualAction = mapActionByVirtualAction->begin(); ItMapActionByVirtualAction != mapActionByVirtualAction->end(); ItMapActionByVirtualAction++)
00239 {
00240 CClassifierSystem* pCS;
00241 TAction virtualActionName = (*ItMapActionByVirtualAction).first;
00242 const CClassifierSystem* pOtherCS = &((*ItMapActionByVirtualAction).second);
00243
00244 pCS = &(_VirtualActionClassifierSystems[virtualActionName]);
00245 pCS->addClassifierSystem(*pOtherCS);
00246 }
00247 }
00248
00249 void CMHiCSbase::addActionCS(const CActionClassifiers& action)
00250 {
00251 nlassert ( action.getName() < Action_VIRTUAL_ACTIONS);
00252 addVirtualActionCS(action);
00253 _ActionSet.insert(action.getName());
00254 }
00255
00256 void CMHiCSbase::selectBehavior(TMotivation motivationName,
00257 const CCSPerception* psensorMap,
00258 std::multimap<CClassifierPriority, std::pair<TClassifierNumber, TTargetId> > &mapActivableCS)
00259 {
00260 std::map<TMotivation, CClassifierSystem>::iterator itMotivationClassifierSystems = _MotivationClassifierSystems.find(motivationName);
00261 if (itMotivationClassifierSystems != _MotivationClassifierSystems.end())
00262 {
00263 (*itMotivationClassifierSystems).second.selectBehavior(psensorMap, mapActivableCS);
00264 }
00265 }
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285 TAction CMHiCSbase::getActionPart(TMotivation motivationName, TClassifierNumber classifierNumber) const
00286 {
00287 if (classifierNumber == -1) return Action_DoNothing;
00288
00289 std::map<TMotivation, CClassifierSystem>::const_iterator itMotivationClassifierSystems = _MotivationClassifierSystems.find(motivationName);
00290 nlassert(itMotivationClassifierSystems != _MotivationClassifierSystems.end());
00291 return (*itMotivationClassifierSystems).second.getActionPart(classifierNumber);
00292 }
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 CClassifierPriority CMHiCSbase::getPriorityPart(TMotivation motivationName, TClassifierNumber classifierNumber) const
00304 {
00305 if (classifierNumber == -1) return CClassifierPriority();
00306
00307 std::map<TMotivation, CClassifierSystem>::const_iterator itMotivationClassifierSystems = _MotivationClassifierSystems.find(motivationName);
00308 nlassert(itMotivationClassifierSystems != _MotivationClassifierSystems.end());
00309 return (*itMotivationClassifierSystems).second.getPriorityPart(classifierNumber);
00310 }
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320 void CMHiCSbase::setPriorityValue(TMotivation motivationName, TClassifierNumber classifierNumber, CClassifierPriority priority)
00321 {
00322 std::map<TMotivation, CClassifierSystem>::iterator itMotivationClassifierSystems = _MotivationClassifierSystems.find(motivationName);
00323 nlassert(itMotivationClassifierSystems != _MotivationClassifierSystems.end());
00324 (*itMotivationClassifierSystems).second.setPriorityPart(classifierNumber, priority);
00325 }
00326
00327 bool CMHiCSbase::isAnAction(TAction behav) const
00328 {
00329 std::set<TAction>::const_iterator itActionSet = _ActionSet.find(behav);
00330 return (itActionSet != _ActionSet.end());
00331 }
00332
00334 void CMHiCSbase::getDebugString(std::string &t) const
00335 {
00336 std::string ret = "\n---------------------------";
00337 std::map<TMotivation, CClassifierSystem>::const_iterator itMotivationClassifierSystems;
00338 for (itMotivationClassifierSystems = _MotivationClassifierSystems.begin(); itMotivationClassifierSystems != _MotivationClassifierSystems.end(); itMotivationClassifierSystems++)
00339 {
00340 ret += "\nMotivation : " + conversionMotivation.toString((*itMotivationClassifierSystems).first);
00341 (*itMotivationClassifierSystems).second.getDebugString(ret);
00342 }
00343 std::map<TAction, CClassifierSystem>::const_iterator itVirtualActionClassifierSystems;
00344 for (itVirtualActionClassifierSystems = _VirtualActionClassifierSystems.begin(); itVirtualActionClassifierSystems != _VirtualActionClassifierSystems.end(); itVirtualActionClassifierSystems++)
00345 {
00346 ret += "\nVirtual Action : " + conversionAction.toString((*itVirtualActionClassifierSystems).first);
00347 (*itVirtualActionClassifierSystems).second.getDebugString(ret);
00348 }
00349 ret += "\nACTIONS :\n";
00350 std::set<TAction>::const_iterator itActionSet;
00351 for (itActionSet = _ActionSet.begin(); itActionSet != _ActionSet.end(); itActionSet++)
00352 {
00353 ret += conversionAction.toString((*itActionSet)) + "\n";
00354 }
00355 t+=ret;
00356 }
00357
00358
00359 void CMHiCSbase::printDebugString() const
00360 {
00361 std::string ret = "";
00362 nldebug("\n---------------------------");
00363 std::map<TMotivation, CClassifierSystem>::const_iterator itMotivationClassifierSystems;
00364 for (itMotivationClassifierSystems = _MotivationClassifierSystems.begin(); itMotivationClassifierSystems != _MotivationClassifierSystems.end(); itMotivationClassifierSystems++)
00365 {
00366 ret += (("\nMotivation : " + conversionMotivation.toString((*itMotivationClassifierSystems).first)).c_str());
00367 (*itMotivationClassifierSystems).second.getDebugString(ret);
00368 nldebug(ret.c_str());
00369 ret = "";
00370 }
00371 std::map<TAction, CClassifierSystem>::const_iterator itVirtualActionClassifierSystems;
00372 for (itVirtualActionClassifierSystems = _VirtualActionClassifierSystems.begin(); itVirtualActionClassifierSystems != _VirtualActionClassifierSystems.end(); itVirtualActionClassifierSystems++)
00373 {
00374 ret += (("\nVirtual Action : " + conversionAction.toString((*itVirtualActionClassifierSystems).first)).c_str());
00375 (*itVirtualActionClassifierSystems).second.getDebugString(ret);
00376 nldebug(ret.c_str());
00377 ret = "";
00378 }
00379 ret += ("\nACTIONS :\n");
00380 std::set<TAction>::const_iterator itActionSet;
00381 for (itActionSet = _ActionSet.begin(); itActionSet != _ActionSet.end(); itActionSet++)
00382 {
00383 ret += ((conversionAction.toString((*itActionSet)) + "\n").c_str());
00384 nldebug(ret.c_str());
00385 ret = "";
00386 }
00387 }
00388
00389
00391 bool CMHiCSbase::loadClassifierFromFile(std::string fileName)
00392 {
00393 bool ret;
00394 const uint32 aboeufSize = 2048;
00395 char aboeuf[aboeufSize];
00396 std::string laLigne, leMot;
00397 uint lastPos = 0;
00398 uint nextPos = 0;
00399 NLMISC::CIFile melkior;
00400 CConditionMap conditionsMap;
00401 std::map<TAction, CActionClassifiers > actionsMap;
00402 std::vector<TSensor> sensorVector;
00403 ret = melkior.open(fileName, true);
00404 if (!ret) return false;
00405
00406 melkior.getline(aboeuf, aboeufSize);
00407
00408 melkior.getline(aboeuf, aboeufSize);
00409 laLigne = aboeuf;
00410
00411 nextPos = laLigne.find_first_of(";",lastPos);
00412 leMot = laLigne.substr(lastPos,nextPos - lastPos);
00413 nlassert(leMot == "Motivations");
00414 lastPos = nextPos+1;
00415 nextPos = laLigne.find_first_of(";", lastPos);
00416 leMot = laLigne.substr(lastPos, nextPos-lastPos);
00417 while (leMot != "Actions")
00418 {
00419
00420 TSensor titi = conversionSensor.fromString(leMot);
00421 nlassert (titi != Sensor_Unknown);
00422 sensorVector.push_back(titi);
00423
00424 lastPos = nextPos+1;
00425 nextPos = laLigne.find_first_of(";", lastPos);
00426 leMot = laLigne.substr(lastPos, nextPos-lastPos);
00427 }
00428
00429 melkior.getline(aboeuf, aboeufSize);
00430 laLigne = aboeuf;
00431 lastPos = 0;
00432 nextPos = 0;
00433 while (laLigne.size() > 0)
00434 {
00435 TMotivation laMotive;
00436 TAction laVirtuelle;
00437
00438 nextPos = laLigne.find_first_of(";",lastPos);
00439 leMot = laLigne.substr(lastPos,nextPos - lastPos);
00440 if (leMot.size() == 0) break;
00441 laMotive = conversionMotivation.fromString(leMot);
00442 if (laMotive == Motivation_Unknown)
00443 {
00444
00445 laVirtuelle = conversionAction.fromString(leMot);
00446 nlassert(laVirtuelle != Action_Unknown);
00447 }
00448
00449 lastPos = nextPos+1;
00450 nextPos = laLigne.find_first_of(";",lastPos);
00451 leMot = laLigne.substr(lastPos,nextPos - lastPos);
00452
00453
00454 uint ii;
00455 for (ii = 0; ii < sensorVector.size(); ii++)
00456 {
00457 if (leMot.size() >0)
00458 {
00459 TSensor sensorName = sensorVector[ii];
00460 if (leMot[0] == '!')
00461 {
00462 conditionsMap.addIfNotSensorCondition(sensorName,leMot[1]);
00463 }
00464 else
00465 {
00466 conditionsMap.addIfSensorCondition(sensorName,leMot[0]);
00467 }
00468 }
00469
00470 lastPos = nextPos+1;
00471 nextPos = laLigne.find_first_of(";",lastPos);
00472 leMot = laLigne.substr(lastPos,nextPos - lastPos);
00473 }
00474
00475 TAction actionName = conversionAction.fromString(leMot);
00476 nlassert(actionName != Action_Unknown);
00477
00478 lastPos = nextPos+1;
00479 nextPos = laLigne.find_first_of(";",lastPos);
00480 leMot = laLigne.substr(lastPos,nextPos - lastPos);
00481
00482
00483 CClassifierPriority laforce;
00484 laforce.SetClassifierTimer( atof(leMot.c_str()) );
00485
00486
00487 std::map<TAction, CActionClassifiers >::iterator itActionsMap = actionsMap.find(actionName);
00488 if (itActionsMap == actionsMap.end())
00489 {
00490 CActionClassifiers bibu(actionName);
00491 actionsMap.insert(std::make_pair(actionName, bibu));
00492 }
00493 CActionClassifiers mon_action(actionName);
00494
00495 if (laMotive == Motivation_Unknown)
00496 {
00497 actionsMap[actionName].addVirtualActionRule(laVirtuelle,conditionsMap, laforce);
00498 }
00499 else
00500 {
00501 actionsMap[actionName].addMotivationRule(laMotive,conditionsMap, laforce);
00502 }
00503
00504 conditionsMap.clear();
00505 melkior.getline(aboeuf, aboeufSize);
00506 laLigne = aboeuf;
00507 lastPos = 0;
00508 nextPos = 0;
00509 }
00510 melkior.close();
00511
00512 std::map<TAction, CActionClassifiers >::iterator itActionsMap;
00513 for (itActionsMap = actionsMap.begin(); itActionsMap != actionsMap.end(); itActionsMap++)
00514 {
00515
00516 TAction testAction = (*itActionsMap).second.getName();
00517 nlassert (testAction != Action_Unknown);
00518 if (testAction > Action_VIRTUAL_ACTIONS)
00519 {
00520 addVirtualActionCS( (*itActionsMap).second );
00521 }
00522 else
00523 {
00524 addActionCS( (*itActionsMap).second );
00525 }
00526 }
00527
00528 return true;
00529 }
00530
00531 void CMHiCSbase::dbgPrintClassifierPriorityInFile(std::string fileName) const
00532 {
00533 int i;
00534 std::map<TMotivation, CClassifierSystem>::const_iterator itMotivationClassifierSystems;
00535 std::string nomDuFichier = "D:\\jgab\\doc\\IA\\_These\\gnuplot\\TFC\\";
00536 nomDuFichier += fileName;
00537
00538 NLMISC::CIFile baltazar;
00539 bool yaqqunauboutdufil = baltazar.open(nomDuFichier.c_str(), true);
00540 baltazar.close();
00541
00542 NLMISC::COFile melkior;
00543 std::string ohlabellephrase = "";
00544
00545 if (!yaqqunauboutdufil)
00546 {
00547 melkior.open(nomDuFichier.c_str(), false, true);
00548
00549 for(itMotivationClassifierSystems = _MotivationClassifierSystems.begin();
00550 itMotivationClassifierSystems != _MotivationClassifierSystems.end();
00551 itMotivationClassifierSystems++)
00552 {
00553 TMotivation laMotive = (*itMotivationClassifierSystems).first;
00554 for (i= 0; i< (*itMotivationClassifierSystems).second.getClassifierNumber(); i++)
00555 {
00556 ohlabellephrase += "MAX ";
00557 ohlabellephrase += NLAINIMAT::conversionMotivation.toString(laMotive);
00558 ohlabellephrase += " ";
00559 (*itMotivationClassifierSystems).second.getDebugString(i,ohlabellephrase);
00560 ohlabellephrase += ";T2S ";
00561 ohlabellephrase += NLAINIMAT::conversionMotivation.toString(laMotive);
00562 ohlabellephrase += " ";
00563 (*itMotivationClassifierSystems).second.getDebugString(i,ohlabellephrase);
00564 ohlabellephrase += ";ExT ";
00565 ohlabellephrase += NLAINIMAT::conversionMotivation.toString(laMotive);
00566 ohlabellephrase += " ";
00567 (*itMotivationClassifierSystems).second.getDebugString(i,ohlabellephrase);
00568
00569
00570 ohlabellephrase += ";";
00571 }
00572 }
00573 ohlabellephrase += "\n";
00574 }
00575 else
00576 {
00577 melkior.open(nomDuFichier.c_str(), true, true);
00578 }
00579
00580 for(itMotivationClassifierSystems = _MotivationClassifierSystems.begin();
00581 itMotivationClassifierSystems != _MotivationClassifierSystems.end();
00582 itMotivationClassifierSystems++)
00583 {
00584 TMotivation laMotive = (*itMotivationClassifierSystems).first;
00585 for (i= 0; i< (*itMotivationClassifierSystems).second.getClassifierNumber(); i++)
00586 {
00587 CClassifierPriority laSuperPrio = getPriorityPart(laMotive, i);
00588 ohlabellephrase += NLMISC::toString(laSuperPrio.getPriority());
00589 ohlabellephrase += ";";
00590 ohlabellephrase += NLMISC::toString(laSuperPrio.getPriorityTimer());
00591 ohlabellephrase += ";";
00592 ohlabellephrase += NLMISC::toString(laSuperPrio.getClassifierTimer());
00593 ohlabellephrase += ";";
00594 }
00595 }
00596 ohlabellephrase += "\n";
00597
00598
00599 uint8 *buf = (uint8 *)ohlabellephrase.c_str();
00600 uint len = ohlabellephrase.length();
00601 melkior.serialBuffer(buf,len);
00602 melkior.close();
00603 }
00604
00605 void CMHiCSbase::learningUpdatePriorityValueTimeToSuccess(TMotivation motivationName, TClassifierNumber classifierNumber, uint32 timeToSuccess)
00606 {
00607
00608 std::map<TMotivation, CClassifierSystem>::iterator itMotivationClassifierSystems = _MotivationClassifierSystems.find(motivationName);
00609 nlassert(itMotivationClassifierSystems != _MotivationClassifierSystems.end());
00610 uint32 oldTime2Success = (*itMotivationClassifierSystems).second.getPriorityPart(classifierNumber).getPriorityTimer();
00611 uint32 newTime2Success;
00612 if (oldTime2Success == 0)
00613 {
00614 newTime2Success = timeToSuccess;
00615 }
00616 else
00617 {
00618 if (oldTime2Success > timeToSuccess)
00619 {
00620 newTime2Success = (timeToSuccess*3 + oldTime2Success)/4;
00621 }
00622 else
00623 {
00624 newTime2Success = (timeToSuccess + oldTime2Success*3)/4;
00625 }
00626 }
00627
00628 CClassifierPriority newPrio;
00629 newPrio.setPriorityTimer(newTime2Success);
00630
00631 newPrio.SetClassifierTimer((*itMotivationClassifierSystems).second.getPriorityPart(classifierNumber).getClassifierTimer());
00632 (*itMotivationClassifierSystems).second.setPriorityPart(classifierNumber, newPrio);
00633 }
00634 void CMHiCSbase::learningUpdatePriorityValueClassifierTime(TMotivation motivationName, TClassifierNumber classifierNumber, uint32 time)
00635 {
00636
00637 std::map<TMotivation, CClassifierSystem>::iterator itMotivationClassifierSystems = _MotivationClassifierSystems.find(motivationName);
00638 nlassert(itMotivationClassifierSystems != _MotivationClassifierSystems.end());
00639 uint32 oldTime = (*itMotivationClassifierSystems).second.getPriorityPart(classifierNumber).getClassifierTimer();
00640 uint32 newTime;
00641 if (oldTime == 0)
00642 {
00643 newTime = time;
00644 }
00645 else
00646 {
00647 if (oldTime > time)
00648 {
00649 newTime = (time + oldTime*3)/4;
00650 }
00651 else
00652 {
00653 newTime = (time*3 + oldTime)/4;
00654 }
00655 }
00656 CClassifierPriority newPrio;
00657 newPrio.setPriorityTimer((*itMotivationClassifierSystems).second.getPriorityPart(classifierNumber).getPriorityTimer());
00658 newPrio.SetClassifierTimer(newTime);
00659
00660 (*itMotivationClassifierSystems).second.setPriorityPart(classifierNumber, newPrio);
00661 }
00662
00663
00665
00667
00668 CMHiCSagent::CMHiCSagent(CMHiCSbase* pMHiCSbase)
00669 {
00670 nlassert (pMHiCSbase != NULL);
00671 _pMHiCSbase = pMHiCSbase;
00672 _pActionsExecutionIntensityByTarget = new std::map<TTargetId, std::map<TAction, CMotivationEnergy> >();
00673 _pOldActionsExecutionIntensityByTarget = new std::map<TTargetId, std::map<TAction, CMotivationEnergy> >();
00674 _Learning = true;
00675 _pInfoClassifierActivity = new std::map<TMotivation, std::map<TClassifierNumber, CClassifierActivityInfo> >();
00676 _pOldInfoClassifierActivity = new std::map<TMotivation, std::map<TClassifierNumber, CClassifierActivityInfo> >();
00677
00678
00679
00680 }
00681
00682 CMHiCSagent::~CMHiCSagent()
00683 {
00684 delete _pOldActionsExecutionIntensityByTarget;
00685 delete _pActionsExecutionIntensityByTarget;
00686 delete _pInfoClassifierActivity;
00687 delete _pOldInfoClassifierActivity;
00688 }
00689
00691 std::string CMHiCSagent::targetId2String(TTargetId id) const
00692 {
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702 std::string ret = NLMISC::toString(id);
00703 return ret;
00704 }
00705
00707 void CMHiCSagent::getDebugString(std::string &t) const
00708 {
00709 std::string ret = "\n\n---------------------------\n";
00710 ret += "\nPerceptions :";
00711 ret += "\n Without target";
00712 NLAINIMAT::TSensorMap::const_iterator itNoTargetSensors;
00713 for (itNoTargetSensors = _pSensorsValues->NoTargetSensors.begin();
00714 itNoTargetSensors != _pSensorsValues->NoTargetSensors.end();
00715 itNoTargetSensors++)
00716 {
00717 ret += "\n " + conversionSensor.toString((*itNoTargetSensors).first) + "(" + (*itNoTargetSensors).second + ")";
00718 }
00719 std::map<TTargetId, TSensorMap>::const_iterator itTargetSensors;
00720 for (itTargetSensors = _pSensorsValues->TargetSensors.begin();
00721 itTargetSensors != _pSensorsValues->TargetSensors.end();
00722 itTargetSensors++)
00723 {
00724 ret += "\n On target n#" + targetId2String((*itTargetSensors).first);
00725 for (itNoTargetSensors = (*itTargetSensors).second.begin();
00726 itNoTargetSensors != (*itTargetSensors).second.end();
00727 itNoTargetSensors++)
00728 {
00729 ret += "\n " + conversionSensor.toString((*itNoTargetSensors).first) + "(" + (*itNoTargetSensors).second + ")";
00730 }
00731 }
00732 ret += "\n\nMotivations :";
00733 std::map<TMotivation, CMotivationEnergy>::const_iterator itClassifiersAndMotivationIntensity;
00734 for (itClassifiersAndMotivationIntensity = _ClassifiersAndMotivationIntensity.begin();
00735 itClassifiersAndMotivationIntensity != _ClassifiersAndMotivationIntensity.end();
00736 itClassifiersAndMotivationIntensity++)
00737 {
00738 ret += "\n <" + conversionMotivation.toString((*itClassifiersAndMotivationIntensity).first) + "> ";
00739 ret += "[MI=" + NLMISC::toString((*itClassifiersAndMotivationIntensity).second.getSumValue()) + "] :";
00740 (*itClassifiersAndMotivationIntensity).second.getDebugString(ret);
00741
00742 ret += "\n";
00743 }
00744
00745
00746
00747
00748
00749
00750
00751
00752
00757
00758
00759
00760 ret += "\nACTIONS :";
00761 std::map<TAction, CMotivationEnergy>::const_iterator itActionsExecutionIntensity;
00762
00763
00764
00765
00766
00767
00769
00770
00771
00772
00774
00775
00776 t+=ret;
00777 }
00778
00780 void CMHiCSagent::setMotivationPP(TMotivation motivationName, double PP)
00781 {
00782 _ClassifiersAndMotivationIntensity[motivationName].setMHiCSagent(this);
00783 _ClassifiersAndMotivationIntensity[motivationName].setMotivationPP(motivationName, PP);
00784
00785 }
00786
00788 double CMHiCSagent::getMotivationPP(TMotivation motivationName) const
00789 {
00790 std::map<TMotivation, CMotivationEnergy>::const_iterator itClassifiersAndMotivationIntensity = _ClassifiersAndMotivationIntensity.find(motivationName);
00791 if (itClassifiersAndMotivationIntensity != _ClassifiersAndMotivationIntensity.end())
00792 {
00793 return (*itClassifiersAndMotivationIntensity).second.getMotivationPP(motivationName);
00794 }
00795 else
00796 {
00797 return -1;
00798 }
00799 }
00800
00802 void CMHiCSagent::setMotivationValue(TMotivation motivationName, double value)
00803 {
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814 std::map<TMotivation, CMotivationEnergy>::iterator itClassifiersAndMotivationIntensity = _ClassifiersAndMotivationIntensity.find(motivationName);
00815 if (itClassifiersAndMotivationIntensity == _ClassifiersAndMotivationIntensity.end())
00816 {
00817 itClassifiersAndMotivationIntensity = _ClassifiersAndMotivationIntensity.insert(std::make_pair(motivationName,CMotivationEnergy())).first;
00818
00819
00820
00821 }
00822 (*itClassifiersAndMotivationIntensity).second.setMHiCSagent(this);
00823 (*itClassifiersAndMotivationIntensity).second.setMotivationValue(motivationName, value);
00824
00825 }
00826
00827 double CMHiCSagent::getMotivationValue(TMotivation motivationName) const
00828 {
00829 std::map<TMotivation, CMotivationEnergy>::const_iterator itClassifiersAndMotivationIntensity = _ClassifiersAndMotivationIntensity.find(motivationName);
00830 if (itClassifiersAndMotivationIntensity != _ClassifiersAndMotivationIntensity.end())
00831 {
00832 return (*itClassifiersAndMotivationIntensity).second.getMotivationValue(motivationName);
00833 }
00834 else
00835 {
00836 return -1;
00837 }
00838 }
00839
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00855 double CMHiCSagent::getExecutionIntensity(TAction action, TTargetId target) const
00856 {
00857 std::map<TTargetId, std::map<TAction, CMotivationEnergy> >::const_iterator itActionsExecutionIntensityByTarget;
00858 itActionsExecutionIntensityByTarget = _pActionsExecutionIntensityByTarget->find(target);
00859 if (itActionsExecutionIntensityByTarget == _pActionsExecutionIntensityByTarget->end())
00860 {
00861 return -1;
00862 }
00863 std::map<TAction, CMotivationEnergy>::const_iterator itActionsExecutionIntensity = (*itActionsExecutionIntensityByTarget).second.find(action);
00864 if (itActionsExecutionIntensity != (*itActionsExecutionIntensityByTarget).second.end())
00865 {
00866 return (*itActionsExecutionIntensity).second.getSumValue();
00867 }
00868 else
00869 {
00870 return -1;
00871 }
00872 }
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982 void CMHiCSagent::motivationCompute()
00983 {
00984 TAction behav;
00985
00986 std::map<TMotivation, CMotivationEnergy>::iterator itClassifiersAndMotivationIntensity;
00987
00988
00989 for (itClassifiersAndMotivationIntensity = _ClassifiersAndMotivationIntensity.begin();
00990 itClassifiersAndMotivationIntensity != _ClassifiersAndMotivationIntensity.end();
00991 itClassifiersAndMotivationIntensity++)
00992 {
00993 CMotivationEnergy* pCSselection = &((*itClassifiersAndMotivationIntensity).second);
00994 TMotivation selectionName = (*itClassifiersAndMotivationIntensity).first;
00995 double energy = pCSselection->getSumValue();
00996
00997 if (energy > 0)
00998 {
00999
01000 std::multimap<CClassifierPriority, std::pair<TClassifierNumber, TTargetId> > mapActivableCS;
01001 std::multimap<CClassifierPriority, std::pair<TClassifierNumber, TTargetId> >::iterator itMapActivableCS;
01002
01003
01004 _pMHiCSbase->selectBehavior(selectionName,_pSensorsValues, mapActivableCS);
01005
01006
01007 for (itMapActivableCS = mapActivableCS.begin(); itMapActivableCS != mapActivableCS.end(); itMapActivableCS++)
01008 {
01009 TClassifierNumber selectedClassifierNumber = (*itMapActivableCS).second.first;
01010 TTargetId currentTargetId = (*itMapActivableCS).second.second;
01011 behav = _pMHiCSbase->getActionPart(selectionName, selectedClassifierNumber);
01012
01013 (*_pInfoClassifierActivity)[selectionName][selectedClassifierNumber].IsActivable = true;
01014
01015
01016 if (behav != Action_DoNothing)
01017 {
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027 (*_pActionsExecutionIntensityByTarget)[currentTargetId][behav].setMHiCSagent(this);
01028 (*_pActionsExecutionIntensityByTarget)[currentTargetId][behav].addProvider(selectionName, selectedClassifierNumber);
01029 }
01030 }
01031 }
01032 }
01033 }
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159 void CMHiCSagent::run()
01160 {
01161 std::map<TTargetId, std::map<TAction, CMotivationEnergy> > *bibu = _pOldActionsExecutionIntensityByTarget;
01162 _pOldActionsExecutionIntensityByTarget = _pActionsExecutionIntensityByTarget;
01163 _pActionsExecutionIntensityByTarget = bibu;
01164 _pActionsExecutionIntensityByTarget->clear();
01165
01166 std::map<TMotivation, std::map<TClassifierNumber, CClassifierActivityInfo> > *biba = _pOldInfoClassifierActivity;
01167 _pOldInfoClassifierActivity = _pInfoClassifierActivity;
01168 _pInfoClassifierActivity = biba;
01169 _pInfoClassifierActivity->clear();
01170
01171 motivationCompute();
01172
01173 }
01174
01175
01176 void CMHiCSagent::setSensors(CCSPerception* psensorMap)
01177 {
01178 _pSensorsValues = psensorMap;
01179 }
01180
01181 void CMHiCSagent::setLearning(bool active)
01182 {
01183 _Learning = active;
01184 }
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219 void CMHiCSagent::learningComputation()
01220 {
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236 uint32 newTime = NLMISC::CTime::getSecondsSince1970();
01237 std::set<TMotivation> decreasingMotivations;
01238 std::map<TMotivation, CMotivationEnergy>::iterator itOldClassifiersAndMotivationIntensity, itClassifiersAndMotivationIntensity;
01239 for(itOldClassifiersAndMotivationIntensity = _OldClassifiersAndMotivationIntensity.begin();
01240 itOldClassifiersAndMotivationIntensity != _OldClassifiersAndMotivationIntensity.end();
01241 itOldClassifiersAndMotivationIntensity++)
01242 {
01243 TMotivation motivationName = (*itOldClassifiersAndMotivationIntensity).first;
01244 double oldMV = (*itOldClassifiersAndMotivationIntensity).second.getMotivationValue(motivationName);
01245 itClassifiersAndMotivationIntensity = _ClassifiersAndMotivationIntensity.find(motivationName);
01246 nlassert(itClassifiersAndMotivationIntensity != _ClassifiersAndMotivationIntensity.end());
01247 double newMV = (*itClassifiersAndMotivationIntensity).second.getMotivationValue(motivationName);
01248 if (newMV < oldMV)
01249 {
01250 decreasingMotivations.insert(motivationName);
01251 }
01252 }
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285 std::set<TMotivation>::iterator itDecreasingMotivations;
01286 for (itDecreasingMotivations = decreasingMotivations.begin(); itDecreasingMotivations != decreasingMotivations.end(); itDecreasingMotivations++)
01287 {
01288 TMotivation motivationName = (*itDecreasingMotivations);
01289 std::map<TMotivation, std::map<TClassifierNumber, CTemporaryPriority> >::iterator itTemporaryPriority = _TemporaryPriority.find(motivationName);
01290 if (itTemporaryPriority != _TemporaryPriority.end())
01291 {
01292 std::map<TClassifierNumber, CTemporaryPriority>::iterator itPrioByCl;
01293 for (itPrioByCl = (*itTemporaryPriority).second.begin(); itPrioByCl != (*itTemporaryPriority).second.end(); itPrioByCl++ )
01294 {
01295
01296
01297
01298
01299 uint32 startTime = (*itPrioByCl).second.StartTime;
01300 if (startTime > newTime)
01301 {
01302 newTime = startTime;
01303 }
01304 uint32 timeToSatisfaction = newTime - startTime;
01305 TClassifierNumber classifierNumber = (*itPrioByCl).first;
01306
01307 _pMHiCSbase->learningUpdatePriorityValueTimeToSuccess(motivationName, classifierNumber, timeToSatisfaction);
01308
01309 }
01310 }
01311 _TemporaryPriority.erase(motivationName);
01312 }
01313
01314
01315 std::map<TTargetId, std::map<TAction, CMotivationEnergy> >::iterator itActionsExecutionIntensityByTarget;
01316 std::map<TAction, CMotivationEnergy>::iterator itActionsExecutionIntensity;
01317 for(itActionsExecutionIntensityByTarget = _pActionsExecutionIntensityByTarget->begin();
01318 itActionsExecutionIntensityByTarget != _pActionsExecutionIntensityByTarget->end();
01319 itActionsExecutionIntensityByTarget++)
01320 {
01321 for(itActionsExecutionIntensity = (*itActionsExecutionIntensityByTarget).second.begin();
01322 itActionsExecutionIntensity != (*itActionsExecutionIntensityByTarget).second.end();
01323 itActionsExecutionIntensity++)
01324 {
01325 const std::map<TMotivation, std::set<TClassifierNumber> >* provounet = (*itActionsExecutionIntensity).second.getProviders();
01326 std::map<TMotivation, std::set<TClassifierNumber> >::const_iterator itProvounet;
01327 for(itProvounet = provounet->begin();
01328 itProvounet != provounet->end();
01329 itProvounet++)
01330 {
01331 TMotivation motivationName = (*itProvounet).first;
01332 std::set<TClassifierNumber>::const_iterator itClassifierNumber;
01333 for (itClassifierNumber = (*itProvounet).second.begin(); itClassifierNumber != (*itProvounet).second.end(); itClassifierNumber++)
01334 {
01335 TClassifierNumber classifierNumber = (*itClassifierNumber);
01336
01337
01338
01339
01340 (*_pInfoClassifierActivity)[motivationName][classifierNumber].IsActive = true;
01341
01342
01343 }
01344 }
01345 }
01346 }
01347
01348
01349 std::map<TMotivation, std::map<TClassifierNumber, CClassifierActivityInfo> >::iterator itOldInfoClassifierActivity;
01350 std::map<TMotivation, std::map<TClassifierNumber, CClassifierActivityInfo> >::iterator itInfoClassifierActivity;
01351 for(itOldInfoClassifierActivity = (*_pOldInfoClassifierActivity).begin();
01352 itOldInfoClassifierActivity != (*_pOldInfoClassifierActivity).end();
01353 itOldInfoClassifierActivity++ )
01354 {
01355 TMotivation motivationName = (*itOldInfoClassifierActivity).first;
01356 std::map<TClassifierNumber, CClassifierActivityInfo>::iterator itClassifiers, itClassifiersBis;
01357 for (itClassifiers = (*itOldInfoClassifierActivity).second.begin(); itClassifiers != (*itOldInfoClassifierActivity).second.end(); itClassifiers++)
01358 {
01359
01360
01361 TClassifierNumber classifierNumber = (*itClassifiers).first;
01362 bool wasActive = (*itClassifiers).second.IsActive;
01363 bool isActive = (*_pInfoClassifierActivity)[motivationName][classifierNumber].IsActive;
01364 if (wasActive && !isActive)
01365 {
01366
01367 uint32 diffTime = _TemporaryPriority[motivationName][classifierNumber].TemporaryClassifierPriorityTime;
01368 if (diffTime >0)
01369 {
01370 _pMHiCSbase->learningUpdatePriorityValueClassifierTime(motivationName, classifierNumber, diffTime);
01371
01372 }
01373 }
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01451
01453
01454
01455 }
01456 }
01457
01458 std::map<TClassifierNumber, CClassifierActivityInfo>::iterator itUnChtitClassifierNumberInfo;
01459
01460 for(itInfoClassifierActivity = (*_pInfoClassifierActivity).begin();
01461 itInfoClassifierActivity != (*_pInfoClassifierActivity).end();
01462 itInfoClassifierActivity++)
01463 {
01464 TMotivation motivationName = (*itInfoClassifierActivity).first;
01465
01466 for(itUnChtitClassifierNumberInfo = (*itInfoClassifierActivity).second.begin();
01467 itUnChtitClassifierNumberInfo != (*itInfoClassifierActivity).second.end();
01468 itUnChtitClassifierNumberInfo++)
01469 {
01470 TClassifierNumber leNumberDuClasseur = (*itUnChtitClassifierNumberInfo).first;
01471 bool wasActive = (*_pOldInfoClassifierActivity)[motivationName][leNumberDuClasseur].IsActive;
01472 bool isActive = (*itUnChtitClassifierNumberInfo).second.IsActive;
01473 if (isActive)
01474 {
01475 if (!wasActive)
01476 {
01477 _TemporaryPriority[motivationName][leNumberDuClasseur].StartTime = newTime;
01478 _TemporaryPriority[motivationName][leNumberDuClasseur].LastTime = newTime;
01479 _TemporaryPriority[motivationName][leNumberDuClasseur].FixedStartTime = true;
01480 _TemporaryPriority[motivationName][leNumberDuClasseur].TemporaryClassifierPriorityTime = 0;
01481 }
01482
01483 uint32 lastTime = _TemporaryPriority[motivationName][leNumberDuClasseur].LastTime;
01484 if (lastTime > newTime)
01485 {
01486 newTime = lastTime;
01487 }
01488 uint32 diffTime = newTime - lastTime;
01489 _TemporaryPriority[motivationName][leNumberDuClasseur].LastTime = newTime;
01490 _TemporaryPriority[motivationName][leNumberDuClasseur].TemporaryClassifierPriorityTime += diffTime;
01491 }
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01529
01530
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
01543 }
01544 }
01545 }
01546
01547
01548 const std::map<TTargetId, std::map<TAction, CMotivationEnergy> >* CMHiCSagent::selectBehavior()
01549 {
01550
01551 double priority;
01552 TAction action;
01553 TTargetId target;
01554 std::multimap<double, std::pair<TTargetId,TAction> > actionsToRemove;
01555
01556 std::map<TTargetId, std::map<TAction, CMotivationEnergy> >::iterator itActionsExecutionIntensityByTarget;
01557 std::map<TAction, CMotivationEnergy>::const_iterator itMotiveByAction;
01558 for (itActionsExecutionIntensityByTarget = _pActionsExecutionIntensityByTarget->begin();
01559 itActionsExecutionIntensityByTarget != _pActionsExecutionIntensityByTarget->end();
01560 itActionsExecutionIntensityByTarget++)
01561 {
01562 for (itMotiveByAction = (*itActionsExecutionIntensityByTarget).second.begin();
01563 itMotiveByAction != (*itActionsExecutionIntensityByTarget).second.end();
01564 itMotiveByAction++)
01565 {
01566 priority = (*itMotiveByAction).second.getSumValue();
01567 action = (*itMotiveByAction).first;
01568 target = (*itActionsExecutionIntensityByTarget).first;
01569
01570
01571
01572
01573
01574 actionsToRemove.insert(std::make_pair(priority, std::make_pair(target,action)));
01575 }
01576 }
01577
01578 _pMHiCSbase->pActionResources->filterMyActions(actionsToRemove);
01579
01580 std::multimap<double, std::pair<TTargetId,TAction> >::iterator itActionsToRemove;
01581 for (itActionsToRemove = actionsToRemove.begin();
01582 itActionsToRemove != actionsToRemove.end();
01583 itActionsToRemove++)
01584 {
01585 target = (*itActionsToRemove).second.first;
01586 action = (*itActionsToRemove).second.second;
01587 itActionsExecutionIntensityByTarget = _pActionsExecutionIntensityByTarget->find(target);
01588 nlassert (itActionsExecutionIntensityByTarget != _pActionsExecutionIntensityByTarget->end());
01589 itMotiveByAction = (*itActionsExecutionIntensityByTarget).second.find(action);
01590 nlassert (itMotiveByAction != (*itActionsExecutionIntensityByTarget).second.end());
01591 (*itActionsExecutionIntensityByTarget).second.erase(action);
01592 if ( (*itActionsExecutionIntensityByTarget).second.begin() == (*itActionsExecutionIntensityByTarget).second.end() )
01593 {
01594 _pActionsExecutionIntensityByTarget->erase(target);
01595 }
01596 }
01597
01598 if (_Learning)
01599 {
01600 learningComputation();
01601
01602 _OldClassifiersAndMotivationIntensity = _ClassifiersAndMotivationIntensity;
01603 }
01604
01605 return _pActionsExecutionIntensityByTarget;
01606 }
01607
01608 uint32 CMHiCSagent::getTemporaryClassifierPriorityTime(TMotivation motivationName, TClassifierNumber classifierNumber) const
01609 {
01610 std::map<TMotivation, std::map<TClassifierNumber, CTemporaryPriority> >::const_iterator itTemporaryPriority = _TemporaryPriority.find(motivationName);
01611 if (itTemporaryPriority == _TemporaryPriority.end())
01612 {
01613 return 0;
01614 }
01615 std::map<TClassifierNumber, CTemporaryPriority>::const_iterator itIteratorBis = (*itTemporaryPriority).second.find(classifierNumber);
01616 if (itIteratorBis == (*itTemporaryPriority).second.end())
01617 {
01618 return 0;
01619 }
01620 uint32 bibureturn = (*itIteratorBis).second.TemporaryClassifierPriorityTime;
01621 return bibureturn;
01622 }
01623
01624 bool CMHiCSagent::wasClassifierPreviouslyActive (TMotivation motivationName, TClassifierNumber classifierNumber) const
01625 {
01626 bool wasPreviouslyActived = false;
01627
01628 std::map<TMotivation, std::map<TClassifierNumber, CClassifierActivityInfo> >::const_iterator itOldInfoClassifierActivity;
01629 itOldInfoClassifierActivity = (*_pOldInfoClassifierActivity).find(motivationName);
01630 if (itOldInfoClassifierActivity != _pOldInfoClassifierActivity->end())
01631 {
01632 std::map<TClassifierNumber, CClassifierActivityInfo>::const_iterator itClassifierInfo = (*itOldInfoClassifierActivity).second.find(classifierNumber);
01633 if (itClassifierInfo != (*itOldInfoClassifierActivity).second.end() )
01634 {
01635 wasPreviouslyActived = (*itClassifierInfo).second.IsActive;
01636 }
01637 }
01638 return wasPreviouslyActived;
01639 }
01640
01641
01643
01644
01645
01646
01647
01648 }
01649