NLAINIMAT::CClassifierSystem Class Reference

#include <classifier.h>


Detailed Description

A simple and minimal version of a Classifier System.
Author:
Gabriel ROBERT

Nevrax France

Date:
2001

Definition at line 165 of file classifier.h.

Public Member Functions

void addClassifier (const CConditionMap &conditionsMap, CClassifierPriority priority, TAction behavior)
void addClassifierSystem (const CClassifierSystem &cs)
 Merge two CS.

 CClassifierSystem ()
 Destructor.

void dividePriorityByTheMinPriorityPart ()
TAction getActionPart (TClassifierNumber classifierNumber) const
TClassifierNumber getClassifierNumber () const
 Return the number of classifiers.

void getDebugString (TClassifierNumber classifierNumber, std::string &t) const
void getDebugString (std::string &t) const
CClassifierPriority getPriorityPart (TClassifierNumber classifierNumber) const
void selectBehavior (const CCSPerception *psensorMap, std::multimap< CClassifierPriority, std::pair< TClassifierNumber, TTargetId > > &mapActivableCS)
void setPriorityPart (TClassifierNumber classifierNumber, CClassifierPriority priority)
virtual ~CClassifierSystem ()

Private Types

typedef std::map< TClassifierNumber,
CClassifier * >::iterator 
TitClassifiers

Private Member Functions

void RAZNoTargetSensors ()
void RAZTargetSensors ()
void updateNoTargetSensors (const CCSPerception *psensorMap)
void updateTargetSensors (const CCSPerception *psensorMap, TTargetId target)

Private Attributes

TClassifierNumber _ClassifierNumber
std::map< TClassifierNumber,
CClassifier * > 
_Classifiers
TSensorMap _Sensors


Member Typedef Documentation

typedef std::map<TClassifierNumber, CClassifier*>::iterator NLAINIMAT::CClassifierSystem::TitClassifiers [private]
 

Definition at line 200 of file classifier.h.

Referenced by selectBehavior().


Constructor & Destructor Documentation

NLAINIMAT::CClassifierSystem::CClassifierSystem  ) 
 

Destructor.

Definition at line 79 of file classifier.cpp.

References _ClassifierNumber.

00080 {
00081         _ClassifierNumber = 0;
00082 }

NLAINIMAT::CClassifierSystem::~CClassifierSystem  )  [virtual]
 

Definition at line 84 of file classifier.cpp.

References _Classifiers.

00085 {
00086         std::map<TClassifierNumber, CClassifier*>::iterator itClassifiers = _Classifiers.begin();
00087         while (itClassifiers != _Classifiers.end())
00088         {
00089                 delete (*itClassifiers).second;
00090                 itClassifiers++;
00091         }
00092 }


Member Function Documentation

void NLAINIMAT::CClassifierSystem::addClassifier const CConditionMap conditionsMap,
CClassifierPriority  priority,
TAction  behavior
 

Add a new classifier in the classifier system.

Parameters:
conditionsMap is a map whose key is the sensor name and value the sensor value.
priority is the importance of this rule. The value should be between 0 an 1.
behavior is the action to execute if this classifier is selected.

Definition at line 94 of file classifier.cpp.

References _ClassifierNumber, _Classifiers, _Sensors, NLAINIMAT::CConditionMap::begin(), NLAINIMAT::CClassifierSystem::CClassifier::Behavior, NLAINIMAT::CClassifierSystem::CClassifier::ConditionWithoutTarget, NLAINIMAT::CClassifierSystem::CClassifier::ConditionWithTarget, NLAINIMAT::CConditionMap::end(), NLAINIMAT::CClassifierSystem::CClassifier::Priority, and NLAINIMAT::TSensor.

Referenced by addClassifierSystem(), NLAINIMAT::CActionClassifiers::addMotivationRule(), and NLAINIMAT::CActionClassifiers::addVirtualActionRule().

00095 {
00096         // We build a new classifier.
00097         CClassifier* classifier = new CClassifier();
00098         classifier->Behavior = behavior;
00099         classifier->Priority = priority;
00100 
00101         CClassifierConditionCell* condCell;
00102         std::map<TSensor, CConditionMap::CSensor >::const_iterator itCondition;
00103         for (itCondition = conditionsMap.begin(); itCondition != conditionsMap.end(); itCondition++)
00104         {
00105                 // We add the new sensor in the sensor map and init it with a joker value '#'
00106                 TSensor bibu = (*itCondition).first;
00107                 _Sensors[(*itCondition).first] = '#';
00108 
00109                 // A new condition cell is added to the classifier condition.
00110                 condCell = new CClassifierConditionCell(_Sensors.find((*itCondition).first),
00111                                                                                                 (*itCondition).second.SensorValue,
00112                                                                                                 (*itCondition).second.TruthValue);
00113                 if ((*itCondition).second.NeedTarget)
00114                 {
00115                         classifier->ConditionWithTarget.push_back(condCell);
00116                 }
00117                 else
00118                 {
00119                         classifier->ConditionWithoutTarget.push_back(condCell);
00120                 }
00121         }
00122 
00123         // The new classifier is added to the classifier list.
00124         _Classifiers[_ClassifierNumber++] = classifier;
00125 }

void NLAINIMAT::CClassifierSystem::addClassifierSystem const CClassifierSystem cs  ) 
 

Merge two CS.

Definition at line 128 of file classifier.cpp.

References _Classifiers, addClassifier(), NLAINIMAT::CConditionMap::addSensorCondition(), NLAINIMAT::CClassifierSystem::CClassifierConditionCell::getSensorIsTrue(), NLAINIMAT::CClassifierSystem::CClassifierConditionCell::getSensorName(), and NLAINIMAT::CClassifierSystem::CClassifierConditionCell::getValue().

Referenced by NLAINIMAT::CMHiCSbase::addVirtualActionCS().

00129 {
00130         std::map<TClassifierNumber, CClassifier*>::const_iterator itCSClassifiers;
00131 
00132         // Pour chacun des classeurs de cs
00133         for (itCSClassifiers = cs._Classifiers.begin(); itCSClassifiers != cs._Classifiers.end(); itCSClassifiers++)
00134         {
00135                 CConditionMap conditionsMap;
00136                 std::list<CClassifierConditionCell*>::const_iterator itCondCell;
00137 
00138                 // Pour chacune des condition sans cible d'un de ces classeur
00139                 for (itCondCell = (*itCSClassifiers).second->ConditionWithoutTarget.begin();
00140                         itCondCell !=(*itCSClassifiers).second->ConditionWithoutTarget.end();
00141                         itCondCell++)
00142                 {
00143                         CClassifierConditionCell* pCondCell = (*itCondCell);
00144                         // Je construit une liste de condition
00145                         conditionsMap.addSensorCondition(pCondCell->getSensorName(), pCondCell->getValue(),pCondCell->getSensorIsTrue());
00146                 }
00147 
00148                 // Pour chacune des condition avec cible d'un de ces classeur
00149                 for (itCondCell = (*itCSClassifiers).second->ConditionWithTarget.begin();
00150                         itCondCell !=(*itCSClassifiers).second->ConditionWithTarget.end();
00151                         itCondCell++)
00152                 {
00153                         CClassifierConditionCell* pCondCell = (*itCondCell);
00154                         // Je construit une liste de condition
00155                         conditionsMap.addSensorCondition(pCondCell->getSensorName(), pCondCell->getValue(),pCondCell->getSensorIsTrue());
00156                 }
00157                 
00158                 // je rajoute dans mon cs un nouveau classeur avec ces conditions, la priorité et le comportement du classeur
00159                 addClassifier(conditionsMap, (*itCSClassifiers).second->Priority, (*itCSClassifiers).second->Behavior);
00160         }
00161 }

void NLAINIMAT::CClassifierSystem::dividePriorityByTheMinPriorityPart  ) 
 

TAction NLAINIMAT::CClassifierSystem::getActionPart TClassifierNumber  classifierNumber  )  const
 

Give the action part of a given Classifier.

Parameters:
classifierNumber is the number of the classifier.
Returns:
is the condition part of the wanted Classifier.

Definition at line 413 of file classifier.cpp.

References _Classifiers, nlassert, NLAINIMAT::TAction, and NLAINIMAT::TClassifierNumber.

00414 {
00415         std::map<TClassifierNumber, CClassifier*>::const_iterator itClassifiers = _Classifiers.find(classifierNumber);
00416         nlassert(itClassifiers != _Classifiers.end());
00417         return (*itClassifiers).second->Behavior;
00418 }

TClassifierNumber NLAINIMAT::CClassifierSystem::getClassifierNumber  )  const [inline]
 

Return the number of classifiers.

Definition at line 262 of file classifier.h.

References _ClassifierNumber, and NLAINIMAT::TClassifierNumber.

00262 {return _ClassifierNumber;}

void NLAINIMAT::CClassifierSystem::getDebugString TClassifierNumber  classifierNumber,
std::string &  t
const
 

Definition at line 505 of file classifier.cpp.

References _Classifiers, NLAINIMAT::CClassifierPriority::getPriority(), NLAINIMAT::CClassifierSystem::CClassifierConditionCell::getSensorIsTrue(), NLAINIMAT::CClassifierSystem::CClassifierConditionCell::getSensorName(), NLAINIMAT::CClassifierSystem::CClassifierConditionCell::getValue(), nlassert, t, NLAINIMAT::TClassifierNumber, and NLMISC::toString().

00506 {
00507         std::string dbg = "";
00508         std::map<TClassifierNumber, CClassifier*>::const_iterator itClassifiers = _Classifiers.find(classifierNumber);
00509         nlassert (itClassifiers != _Classifiers.end());
00510 
00511         dbg += "<" + NLMISC::toString(classifierNumber) + "> ";
00512         std::list<CClassifierConditionCell*>::const_iterator itConditions;
00513         // On parcour la liste de sensor indépendant d'une cible
00514         for (itConditions = (*itClassifiers).second->ConditionWithoutTarget.begin();
00515         itConditions != (*itClassifiers).second->ConditionWithoutTarget.end();
00516         itConditions++)
00517         {
00518                 CClassifierConditionCell* condCell = (*itConditions);
00519                 if (condCell->getSensorIsTrue())
00520                 {
00521                         dbg += " (" + conversionSensor.toString(condCell->getSensorName()) + "= " + condCell->getValue() + ") +";
00522                 }
00523                 else
00524                 {
00525                         dbg += " (" + conversionSensor.toString(condCell->getSensorName()) + "=!" + condCell->getValue() + ") +";
00526                 }
00527         }
00528         // On parcour la liste de sensor dépendant d'une cible
00529         for (itConditions = (*itClassifiers).second->ConditionWithTarget.begin();
00530         itConditions != (*itClassifiers).second->ConditionWithTarget.end();
00531         itConditions++)
00532         {
00533                 CClassifierConditionCell* condCell = (*itConditions);
00534                 if (condCell->getSensorIsTrue())
00535                 {
00536                         dbg += " (" + conversionSensor.toString(condCell->getSensorName()) + "(x)= " + condCell->getValue() + ") +";
00537                 }
00538                 else
00539                 {
00540                         dbg += " (" + conversionSensor.toString(condCell->getSensorName()) + "(x)=!" + condCell->getValue() + ") +";
00541                 }
00542         }
00543         std::string actionName = conversionAction.toString((*itClassifiers).second->Behavior);
00544         CClassifierPriority             prio = (*itClassifiers).second->Priority;
00545         dbg += "> " + actionName + " [" + NLMISC::toString(prio.getPriority()) + "]";
00546         t += dbg;
00547 }

void NLAINIMAT::CClassifierSystem::getDebugString std::string &  t  )  const
 

Definition at line 459 of file classifier.cpp.

References _Classifiers, NLAINIMAT::CClassifierPriority::getPriority(), NLAINIMAT::CClassifierSystem::CClassifierConditionCell::getSensorIsTrue(), NLAINIMAT::CClassifierSystem::CClassifierConditionCell::getSensorName(), NLAINIMAT::CClassifierSystem::CClassifierConditionCell::getValue(), t, and NLMISC::toString().

00460 {
00461         std::string dbg = "\n";
00462 
00463         std::map<TClassifierNumber, CClassifier*>::const_iterator itClassifiers;
00464         for (itClassifiers = _Classifiers.begin(); itClassifiers != _Classifiers.end(); itClassifiers++)
00465         {
00466                 dbg += "<" + NLMISC::toString((*itClassifiers).first) + "> ";
00467                 std::list<CClassifierConditionCell*>::const_iterator itConditions;
00468                 // On parcour la liste de sensor indépendant d'une cible
00469                 for (itConditions = (*itClassifiers).second->ConditionWithoutTarget.begin();
00470                         itConditions != (*itClassifiers).second->ConditionWithoutTarget.end();
00471                         itConditions++)
00472                 {
00473                         CClassifierConditionCell* condCell = (*itConditions);
00474                         if (condCell->getSensorIsTrue())
00475                         {
00476                                 dbg += " (" + conversionSensor.toString(condCell->getSensorName()) + "= " + condCell->getValue() + ") +";
00477                         }
00478                         else
00479                         {
00480                                 dbg += " (" + conversionSensor.toString(condCell->getSensorName()) + "=!" + condCell->getValue() + ") +";
00481                         }
00482                 }
00483                 // On parcour la liste de sensor dépendant d'une cible
00484                 for (itConditions = (*itClassifiers).second->ConditionWithTarget.begin();
00485                         itConditions != (*itClassifiers).second->ConditionWithTarget.end();
00486                         itConditions++)
00487                 {
00488                         CClassifierConditionCell* condCell = (*itConditions);
00489                         if (condCell->getSensorIsTrue())
00490                         {
00491                                 dbg += " (" + conversionSensor.toString(condCell->getSensorName()) + "(x)= " + condCell->getValue() + ") +";
00492                         }
00493                         else
00494                         {
00495                                 dbg += " (" + conversionSensor.toString(condCell->getSensorName()) + "(x)=!" + condCell->getValue() + ") +";
00496                         }
00497                 }
00498                 std::string actionName = conversionAction.toString((*itClassifiers).second->Behavior);
00499                 CClassifierPriority             prio = (*itClassifiers).second->Priority;
00500                 dbg += "> " + actionName + " [" + NLMISC::toString(prio.getPriority()) + "]\n";
00501         }
00502         t += dbg;
00503 }

CClassifierPriority NLAINIMAT::CClassifierSystem::getPriorityPart TClassifierNumber  classifierNumber  )  const
 

Definition at line 420 of file classifier.cpp.

References _Classifiers, nlassert, and NLAINIMAT::TClassifierNumber.

00421 {
00422         std::map<TClassifierNumber, CClassifier*>::const_iterator itClassifiers = _Classifiers.find(classifierNumber);
00423         nlassert(itClassifiers != _Classifiers.end());
00424         return (*itClassifiers).second->Priority;
00425 }

void NLAINIMAT::CClassifierSystem::RAZNoTargetSensors  )  [private]
 

Definition at line 215 of file classifier.cpp.

References _Sensors, and NLAINIMAT::Sensors_WITHTARGET.

Referenced by selectBehavior().

00216 {
00217         TSensorMap::iterator itSensorBorder = _Sensors.upper_bound(Sensors_WITHTARGET);
00218         TSensorMap::iterator itSensors;
00219         for (itSensors = _Sensors.begin(); itSensors != itSensorBorder; itSensors++)
00220         {
00221                 (*itSensors).second = '#';
00222         }
00223 }

void NLAINIMAT::CClassifierSystem::RAZTargetSensors  )  [private]
 

Definition at line 204 of file classifier.cpp.

References _Sensors, and NLAINIMAT::Sensors_WITHTARGET.

Referenced by selectBehavior().

00205 {
00206         TSensorMap::iterator itSensorBorder = _Sensors.upper_bound(Sensors_WITHTARGET);
00207         TSensorMap::iterator itSensors;
00208         for (itSensors = itSensorBorder; itSensors != _Sensors.end(); itSensors++)
00209         {
00210                 (*itSensors).second = '#';
00211         }
00212 }

void NLAINIMAT::CClassifierSystem::selectBehavior const CCSPerception psensorMap,
std::multimap< CClassifierPriority, std::pair< TClassifierNumber, TTargetId > > &  mapActivableCS
 

Select a behavior according to the values in the sensorMap.

Parameters:
sensorMap is a map whose key is the sensor name and value the sensor value.
mapActivableCS is the return value for the map containing all the activable CS. TClassifierPriority is the priority, TClassifierNumber the classifier number and TTargetId la cible de l'action

Definition at line 357 of file classifier.cpp.

References _Classifiers, RAZNoTargetSensors(), RAZTargetSensors(), NLAINIMAT::CCSPerception::TargetSensors, TitClassifiers, NLAINIMAT::TTargetId, updateNoTargetSensors(), and updateTargetSensors().

00359 {
00360         // We update the internal sensor values for the no target sensors
00361         updateNoTargetSensors(psensorMap);
00362 
00363         TitClassifiers itClassifiers;
00364         
00365         for (itClassifiers = _Classifiers.begin();
00366         itClassifiers != _Classifiers.end();
00367         itClassifiers++)
00368         {
00369                 // S'il y a des conditions dépendantes d'une cible, ce n'est pas activable.
00370                 if ((*itClassifiers).second->ConditionWithTarget.begin() == (*itClassifiers).second->ConditionWithTarget.end())
00371                 {
00372                         if ( (*itClassifiers).second->isActivable())
00373                         {
00374                                 mapActivableCS.insert(std::make_pair((*itClassifiers).second->Priority, std::make_pair((*itClassifiers).first, NullTargetId)));
00375                         }
00376                 }
00377         }
00378         
00379         // We now do the same, but with target sensors.
00380         std::map<TTargetId, TSensorMap>::const_iterator itTargetSensorMap;
00381         for (itTargetSensorMap = psensorMap->TargetSensors.begin(); itTargetSensorMap != psensorMap->TargetSensors.end(); itTargetSensorMap++)
00382         {
00383                 TTargetId myTarget = (*itTargetSensorMap).first;
00384                 // We update the internal sensor values for the target sensors
00385                 updateTargetSensors(psensorMap, myTarget);
00386                 
00387                 // We select the activables classifiers
00388                 for (itClassifiers = _Classifiers.begin();
00389                 itClassifiers != _Classifiers.end();
00390                 itClassifiers++)
00391                 {
00392                         // S'il n'y a pas de conditions dépendantes d'une cible, ça a déjà été traité au dessus.
00393                         if ((*itClassifiers).second->ConditionWithTarget.begin() != (*itClassifiers).second->ConditionWithTarget.end())
00394                         {
00395                                 if ( (*itClassifiers).second->isActivable())
00396                                 {
00397                                         mapActivableCS.insert(std::make_pair((*itClassifiers).second->Priority, std::make_pair((*itClassifiers).first, myTarget)));
00398                                 }
00399                         }
00400                 }
00401                 RAZTargetSensors();
00402         }
00403         
00404         // We set the sensors back to the default value.
00405         RAZNoTargetSensors();
00406 
00407 //              // We set the return values.
00408 //              lastClassifierNumber = selectionNumber;
00409 //              lastTarget = myTarget;
00410 //              lastSelectionMaxPriority = higherPriority;
00411 }

void NLAINIMAT::CClassifierSystem::setPriorityPart TClassifierNumber  classifierNumber,
CClassifierPriority  priority
 

Definition at line 427 of file classifier.cpp.

References _Classifiers, nlassert, and NLAINIMAT::TClassifierNumber.

00428 {
00429         std::map<TClassifierNumber, CClassifier*>::iterator itClassifiers = _Classifiers.find(classifierNumber);
00430         nlassert(itClassifiers != _Classifiers.end());
00431         (*itClassifiers).second->Priority = priority;
00432 }

void NLAINIMAT::CClassifierSystem::updateNoTargetSensors const CCSPerception psensorMap  )  [private]
 

Definition at line 164 of file classifier.cpp.

References _Sensors, NLAINIMAT::CCSPerception::NoTargetSensors, NLAINIMAT::TSensor, and NLAINIMAT::TSensorValue.

Referenced by selectBehavior().

00165 {
00166         // We use an internal sensor map, because each condition cell is mapped to this intrenal map.
00167         TSensorMap::iterator itSensors;
00168         TSensorMap::const_iterator itNoTargetSensors;
00169 
00170         for (itSensors = _Sensors.begin(); itSensors != _Sensors.end(); itSensors++)
00171         {
00172                 TSensor sensName = (*itSensors).first;
00173                 itNoTargetSensors = psensorMap->NoTargetSensors.find(sensName);
00174                 if (itNoTargetSensors !=psensorMap->NoTargetSensors.end())
00175                 {
00176                         TSensorValue c = (*itNoTargetSensors).second;
00177                         (*itSensors).second = c;
00178                 }
00179         }
00180 }

void NLAINIMAT::CClassifierSystem::updateTargetSensors const CCSPerception psensorMap,
TTargetId  target
[private]
 

Definition at line 183 of file classifier.cpp.

References _Sensors, nlassert, NLAINIMAT::CCSPerception::TargetSensors, NLAINIMAT::TSensor, NLAINIMAT::TSensorValue, and NLAINIMAT::TTargetId.

Referenced by selectBehavior().

00184 {
00185         // We update the internal sensor values for the target sensors
00186         TSensorMap::iterator itSensors;
00187         TSensorMap::const_iterator itTargetSensors;
00188         std::map<TTargetId, TSensorMap>::const_iterator itTargetSensorMap = psensorMap->TargetSensors.find(target);
00189         nlassert( itTargetSensorMap != psensorMap->TargetSensors.end() );
00190 
00191         for (itSensors = _Sensors.begin(); itSensors != _Sensors.end(); itSensors++)
00192         {
00193                 TSensor sensName = (*itSensors).first;
00194                 itTargetSensors = (*itTargetSensorMap).second.find(sensName);
00195                 if (itTargetSensors != (*itTargetSensorMap).second.end())
00196                 {
00197                         TSensorValue c = (*itTargetSensors).second;
00198                         (*itSensors).second = c;
00199                 }
00200         }
00201 }


Field Documentation

TClassifierNumber NLAINIMAT::CClassifierSystem::_ClassifierNumber [private]
 

Definition at line 222 of file classifier.h.

Referenced by addClassifier(), CClassifierSystem(), and getClassifierNumber().

std::map<TClassifierNumber, CClassifier*> NLAINIMAT::CClassifierSystem::_Classifiers [private]
 

Definition at line 221 of file classifier.h.

Referenced by addClassifier(), addClassifierSystem(), getActionPart(), getDebugString(), getPriorityPart(), selectBehavior(), setPriorityPart(), and ~CClassifierSystem().

TSensorMap NLAINIMAT::CClassifierSystem::_Sensors [private]
 

Definition at line 220 of file classifier.h.

Referenced by addClassifier(), RAZNoTargetSensors(), RAZTargetSensors(), updateNoTargetSensors(), and updateTargetSensors().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 11:09:43 2004 for NeL by doxygen 1.3.6