# 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  

interpret_object_operator.h

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 
00026 #ifndef NL_OPERATOR_CLASS
00027 #define NL_OPERATOR_CLASS
00028 
00029 #include "nel/ai/script/interpret_object_agent.h"
00030 #include "nel/ai/logic/goal.h"
00031 #include "nel/ai/logic/fact.h"
00032 #include "nel/ai/logic/var.h"
00033 #include "nel/ai/fuzzy/fuzzyset.h"
00034 
00035 namespace NLAISCRIPT
00036 {
00037         class COperatorClass: public CAgentClass
00038         {
00039         private:
00040                 NLAILOGIC::CGoal                                                        *_Goal;                         
00041 
00042                 const NLAIAGENT::IVarName                                       *_GoalAssert;           
00043                 std::list<const NLAIAGENT::IVarName *>          _GoalVars;                      
00044                 std::vector<sint32>                                                     _GoalPosVar;            
00045 
00046                 std::vector<NLAILOGIC::IBaseVar *>                      _Vars;                          
00047 
00048                 std::vector< NLAILOGIC::IBaseAssert *>          _Conds;                         
00049                 std::vector< std::vector<sint32> >                      _PosVarsCond;           
00050 
00051                 std::vector<NLAILOGIC::IBaseAssert *>           _Concs;                         
00052                 std::vector< std::vector<sint32> >                      _PosVarsConc;           
00053 
00054                 std::vector<NLAIAGENT::IMessageBase::TPerformatif>      _TrigMsgPerf;
00055                 std::vector<NLAIC::CIdentType>                          _TrigMsgClass;
00056                 std::vector<std::string>                                        _TrigMsgVarname;
00057                 std::vector<sint32>                                                     _TrigMsgPos;
00058 
00059                 char                                                                            *_Comment;                      
00060 
00061                 std::vector<NLAILOGIC::CGoal>                           _Steps;                         // Successive goals to be achieved
00062                 std::vector<sint32>                                                     _StepsMode;                     // Infos about synchro for the steps of the operator
00063 
00064                 sint32                                                                          _UpdateCycles;          // Number of cycles before checking preconditions
00065 
00066                 float                                                                           _Priority;
00067 
00068         public:
00069                 static const NLAIC::CIdentType IdOperatorClass;
00070                 
00072                 void setComment(char *);
00073 
00075 //              virtual void setGoal(NLAILOGIC::CGoal *);
00076                 virtual void setGoal(const NLAIAGENT::CStringVarName &);
00077                 virtual void setGoal(const NLAIAGENT::IVarName *, std::list<const NLAIAGENT::IVarName *> &);
00078                 virtual const NLAILOGIC::CGoal *getGoal();
00079 
00081                 virtual bool isValid(NLAILOGIC::CFactBase *);
00082 
00084                 void compileFactPattern (NLAILOGIC::CFactPattern   *, std::vector<NLAILOGIC::IBaseAssert *> &, std::vector<sint32> &);
00085 
00086                 // Buils a CFact from its assret and an instanciation for the values of the variables of the rule.
00087                 NLAILOGIC::CFact *buildFromVars(NLAILOGIC::IBaseAssert *, std::vector<sint32> &, NLAILOGIC::CValueSet *);
00088 
00090                 sint32 getVarPos(NLAILOGIC::IBaseVar *);
00091 
00093                 NLAILOGIC::CValueSet *unifyLiaison( const NLAILOGIC::CValueSet *, NLAILOGIC::CValueSet *, std::vector<sint32> &);
00094 
00095                 void getPosListForward(sint32, sint32, std::vector<sint32> &);
00096                 void getPosListBackward(sint32, sint32, std::vector<sint32> &);
00097                 void getAssertPos(NLAILOGIC::IBaseAssert *, std::vector<NLAILOGIC::IBaseAssert *> &, std::vector<sint32> &);
00098                 NLAILOGIC::CValueSet *unifyBackward(std::list<NLAILOGIC::CFact *> &);
00099                 NLAILOGIC::CValueSet *unifyForward(std::list<NLAILOGIC::CFact *> &);
00100 
00101                 virtual std::list<NLAILOGIC::CFact *> *test(std::list<NLAILOGIC::CFact *> &) {return NULL;}
00102                 virtual std::list<NLAILOGIC::CFact *> *backward(std::list<NLAILOGIC::CFact *> &);
00103                 virtual std::list<NLAILOGIC::CFact *> *forward(std::list<NLAILOGIC::CFact *> &);
00104                 virtual std::list<NLAILOGIC::CFact *> *propagate(std::list<NLAILOGIC::CFact *> &);
00105 
00107                 virtual float priority() const;
00108 
00112                 virtual void success();
00113                 virtual void failure();
00114 
00117                 virtual void success( NLAILOGIC::IBaseOperator *);
00118                 virtual void failure( NLAILOGIC::IBaseOperator *);
00119 
00120 public:
00121                 COperatorClass(const NLAIAGENT::IVarName &);
00122                 COperatorClass(const NLAIC::CIdentType &);
00123                 COperatorClass(const NLAIAGENT::IVarName &, const NLAIAGENT::IVarName &);
00124                 COperatorClass(const COperatorClass &);
00125                 COperatorClass();
00126                 virtual ~COperatorClass();
00127 
00128                 const NLAIC::IBasicType *clone() const;
00129                 const NLAIC::IBasicType *newInstance() const;
00130                 virtual void getDebugString(std::string &) const;
00131 
00132                 virtual NLAIAGENT::IObjectIA *buildNewInstance() const;
00133 
00134 
00135                 void addPrecondition(NLAILOGIC::CFactPattern *);
00136                 void addPostcondition(NLAILOGIC::CFactPattern *);
00137 
00141 
00142                 // Logique
00143                 std::list<const NLAIAGENT::IVarName *> _BooleanConds;
00144                 std::list<const NLAIAGENT::IVarName *> _BooleanConcs;
00145                 std::vector<const NLAIAGENT::IVarName *> _CondAsserts;
00146                 std::vector<const NLAIAGENT::IVarName *> _ConcAsserts;
00147                 std::vector< std::list<const NLAIAGENT::IVarName *> *> _ClassCondVars;
00148                 std::vector< std::list<const NLAIAGENT::IVarName *> *> _ClassConcVars;
00149                 std::vector< IOpCode *> _CondCode;
00150                 std::vector< IOpCode *> _ConcCode;
00151 
00152                 NLAILOGIC::CFactBase *_FactBase;
00153 
00154                 std::vector<NLAIAGENT::IVarName *> _FuzzyVars;
00155                 std::vector<NLAIAGENT::IVarName *> _FuzzySets;
00156         //      NLAIAGENT::CStringVarName *_GoalName;
00158 
00159 /*
00161                 void addPrecondition(NLAILOGIC::CFactPattern   *);
00162 
00164                 void addPostcondition(NLAILOGIC::CFactPattern   *);
00165 */
00166 //              virtual ~COperatorClass();
00167 
00169                 void addFirstOrderCond(const NLAIAGENT::IVarName *, std::list<const NLAIAGENT::IVarName *> &);
00170                 void addFirstOrderConc(const NLAIAGENT::IVarName *, std::list<const NLAIAGENT::IVarName *> &);
00171 
00173                 void addBoolCond(const NLAIAGENT::IVarName *);
00174                 void addBoolConc(const NLAIAGENT::IVarName *);
00175 
00178                 void addCodeCond(IOpCode *);
00180                 void addCodeConc(IOpCode *);
00181 
00182                 // Adds a fuzzy cond of the form <attrib> is <filter>
00183                 void addFuzzyCond(NLAIAGENT::IVarName *, NLAIAGENT::IVarName *);
00184 
00186                 void buildLogicTables();
00187 
00188                 bool isValidFonc(NLAIAGENT::IObjectIA *);
00189                 void activatePostConditions(NLAIAGENT::IObjectIA *);
00190 
00191                 void initialiseFactBase(NLAILOGIC::CFactBase *);
00192 
00193                 std::vector<NLAIAGENT::IVarName *> &getFuzzyVars()
00194                 {
00195                         return _FuzzyVars;
00196                 }
00197 
00198                 std::vector<NLAIAGENT::IVarName *> &getFuzzySets()
00199                 {
00200                         return _FuzzySets;
00201                 }
00202 
00203                 std::vector<NLAILOGIC::IBaseVar *>      &getVars()
00204                 {
00205                         return _Vars;
00206                 }
00207 
00208                 std::vector< NLAILOGIC::IBaseAssert *>  &getConds()
00209                 {
00210                         return _Conds;
00211                 }
00212 
00213                 std::vector< NLAILOGIC::IBaseAssert *>  &getConcs()
00214                 {
00215                         return _Concs;
00216                 }
00217 
00218                 std::vector< std::vector<sint32> >      &getPosVarsConds()
00219                 {
00220                         return _PosVarsCond;
00221                 }
00222 
00223                 std::vector< std::vector<sint32> >      &getPosVarsConcs()
00224                 {
00225                         return _PosVarsConc;
00226                 }
00227 
00228                 std::vector<sint32> &getGoalVarPos()
00229                 {
00230                         return _GoalPosVar;
00231                 }
00232 
00233                 virtual void setUpdateEvery(sint32 cycles)
00234                 {
00235                         _UpdateCycles = cycles;
00236                 }
00237 
00238                 sint32 getUpdateEvery()
00239                 {
00240                         return _UpdateCycles;
00241                 }
00242 
00243                 void setPriority(float p)
00244                 {
00245                         _Priority = p;
00246                 }
00247 
00248                 float getPriority() const
00249                 {
00250                         return _Priority;
00251                 }
00252 
00253                 void RegisterMessage(NLAIAGENT::IMessageBase::TPerformatif , const std::string &, const std::string & );
00254                 virtual sint32 checkTriggerMsg(const NLAIAGENT::IMessageBase *);
00255                 inline sint32 NbMsgTrigger()
00256                 {
00257                         return _TrigMsgPerf.size();
00258                 }
00259         };
00260 }
00261 #endif