00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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;
00062 std::vector<sint32> _StepsMode;
00063
00064 sint32 _UpdateCycles;
00065
00066 float _Priority;
00067
00068 public:
00069 static const NLAIC::CIdentType IdOperatorClass;
00070
00072 void setComment(char *);
00073
00075
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
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
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
00158
00159
00161
00162
00164
00165
00166
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
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