# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

fuzzyruleset.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 #include "nel/ai/fuzzy/fuzzyruleset.h"
00026 #include "nel/ai/fuzzy/fuzzyrule.h"
00027 
00028 namespace NLAIFUZZY
00029 {
00030         CFuzzyRuleSet::CFuzzyRuleSet(char *comment)
00031         {
00032                 if ( comment )
00033                 {
00034                         _Comment = new char[strlen( comment ) + 1];
00035                         strcpy(_Comment, comment);
00036                 }
00037         }
00038 
00039         void CFuzzyRuleSet::addRule(CFuzzyRule *rule)
00040         {
00041                 _Rules.push_back( rule );
00042         }
00043 
00044         const NLAIAGENT::IObjectIA ::CProcessResult &CFuzzyRuleSet::run()
00045         {
00046                 std::list<CFuzzyRule *>::iterator it_r = _Rules.begin();
00047                 while ( it_r != _Rules.end() )
00048                 {
00049                         ( *it_r )->run();
00050                 }
00051                 return NLAIAGENT::IObjectIA ::ProcessRun;
00052         }
00053 
00054 
00055 
00056         void CFuzzyRuleSet::save(NLMISC::IStream &os)
00057         {               
00058 /*              NLAIAGENT::IObjetOp::save( os );
00059 
00060                 if ( _Value ) 
00061                 {
00062                         os.serial( (bool & ) true );
00063                         os.serial( _Value->getType() );
00064                         _Value->save(os);
00065                 }
00066                 else
00067                         os.serial( (bool &) false );
00068 */                      
00069         }
00070 
00071         void CFuzzyRuleSet::load(NLMISC::IStream &is)
00072         {
00073 /*              if ( _Value )
00074                         _Value->release();
00075 //              NLAIAGENT::IObjetOp::load(is);
00076                 Gen::CIdentTypeAlloc id;
00077                 is.serial( id );
00078                 _Value = (Var *)id.allocClass();
00079                 _Value->load(is);       
00080 */
00081         }
00082 
00083         void CFuzzyRuleSet::getDebugString(std::string &txt) const
00084         {       
00085                 if ( _Comment )
00086                         txt += NLAIC::stringGetBuild("CFuzzyRuleSet %s\n (%d rule)", _Comment, _Rules.size());
00087                 else
00088                         txt += NLAIC::stringGetBuild("CFuzzyRuleSet \n (%d rule)", _Rules.size());
00089         }
00090 
00091         const NLAIC::CIdentType &CFuzzyRuleSet::getType() const
00092         {
00093                 return idFuzzyRuleSet;
00094         }
00095 
00096         const NLAIC::IBasicType *CFuzzyRuleSet::clone() const
00097         {
00098                 NLAIC::IBasicInterface *m = new CFuzzyRuleSet( *this );
00099                 return m;
00100         }
00101 
00102         const NLAIC::IBasicType *CFuzzyRuleSet::newInstance() const
00103         {
00104                 CFuzzyRuleSet *instance = new CFuzzyRuleSet();
00105                 return instance;
00106         }
00107 
00108         bool CFuzzyRuleSet::isEqual(const NLAIAGENT::IBasicObjectIA &) const
00109         {
00110                 return false;
00111         }
00112 
00113         void CFuzzyRuleSet::init(NLAIAGENT::IObjectIA  *p)
00114         {
00115                 NLAIAGENT::IBaseGroupType *params = ((NLAIAGENT::IBaseGroupType *)p);
00116 
00117                 while (  params->size() )
00118                 {
00119                         CFuzzyRule *rule = (CFuzzyRule *) params->getFront();
00120                         addRule( rule );
00121                         params->popFront();
00122                 }
00123         }
00124 }