From: Markus R. <rol...@us...> - 2005-12-05 21:16:59
|
Update of /cvsroot/simspark/simspark/spark/oxygen/agentaspect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14301/agentaspect Added Files: agentaspect.cpp agentaspect.h agentaspect_c.cpp createaction.h effector.cpp effector.h effector_c.cpp perceptor.cpp perceptor.h perceptor_c.cpp Log Message: --- NEW FILE: createaction.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: createaction.h,v 1.1 2005/12/05 21:16:49 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef OXYGEN_CREATEACTION_H #define OXYGEN_CREATEACTION_H #include <oxygen/gamecontrolserver/actionobject.h> namespace oxygen { class CreateAction : public oxygen::ActionObject { public: CreateAction() : ActionObject("create") {} virtual ~CreateAction() {} }; }; // namespace oxygen #endif // OXYGEN_CREATEACTION_H --- NEW FILE: effector_c.cpp --- /* -*- mode: c++; c-basic-indent: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: effector_c.cpp,v 1.1 2005/12/05 21:16:49 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <zeitgeist/class.h> #include "effector.h" using namespace oxygen; void CLASS(Effector)::DefineClass() { DEFINE_BASECLASS(oxygen/BaseNode); } --- NEW FILE: agentaspect.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: agentaspect.cpp,v 1.1 2005/12/05 21:16:49 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "agentaspect.h" #include <zeitgeist/logserver/logserver.h> using namespace boost; using namespace oxygen; using namespace salt; using namespace std; AgentAspect::AgentAspect() : Transform() { SetName("agentAspect"); } AgentAspect::~AgentAspect() { } bool AgentAspect::RealizeActions(boost::shared_ptr<ActionObject::TList> actions) { UpdateEffectorMap(); for ( ActionObject::TList::iterator iter = actions->begin(); iter != actions->end(); ++iter ) { shared_ptr<ActionObject> action = (*iter); std::string predicate = action->GetPredicate(); shared_ptr<Effector> effector = GetEffector(predicate); if (effector.get() == 0) { GetLog()->Warning() << "(AgentAspect) No effector found for predicate " << predicate << "\n"; continue; } bool realized = effector->Realize(action); if (! realized) { GetLog()->Warning() << "(AgentAspect) Failed to realize predicate " << predicate << "\n"; } } return true; } shared_ptr<PredicateList> AgentAspect::QueryPerceptors() { // build list of perceptors, searching recursively TLeafList perceptors; ListChildrenSupportingClass<Perceptor>(perceptors,true); shared_ptr<PredicateList> predList(new PredicateList()); // query the perceptors for new data for ( TLeafList::iterator iter = perceptors.begin(); iter != perceptors.end(); ++iter ) { shared_static_cast<Perceptor>(*iter)->Percept(predList); } return predList; } shared_ptr<Effector> AgentAspect::GetEffector(const std::string predicate) const { TEffectorMap::const_iterator iter = mEffectorMap.find(predicate); if (iter == mEffectorMap.end()) { return shared_ptr<Effector>(); } return (*iter).second; } void AgentAspect::UpdateEffectorMap() { // build list of effectors, searching recursively TLeafList effectors; ListChildrenSupportingClass<Effector>(effectors,true); // build the effector map mEffectorMap.clear(); for ( TLeafList::iterator iter = effectors.begin(); iter != effectors.end(); ++iter ) { shared_ptr<Effector> effector = shared_static_cast<Effector>(*iter); mEffectorMap[effector->GetPredicate()] = effector; } } bool AgentAspect::Init(const string& createEffector) { shared_ptr<Effector> create = shared_dynamic_cast<Effector> (GetCore()->New(createEffector)); if (create.get() == 0) { GetLog()->Error() << "ERROR: (AgentAspect) Could not construct a createEffector '" << createEffector << "'\n"; return false; } create->SetName("_CreateEffector"); // link it into our hierarchy bool added = AddChildReference(create); if (! added) { GetLog()->Error() << "ERROR: (AgentAspect) failed to set up the CreateEffector '" << createEffector << "'\n"; return false; } else { GetLog()->Debug() << "(AgentAspect) created CreateEffector '" << createEffector << "'\n"; } return added; } --- NEW FILE: perceptor_c.cpp --- /* -*- mode: c++; c-basic-indent: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: perceptor_c.cpp,v 1.1 2005/12/05 21:16:49 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "perceptor.h" using namespace boost; using namespace oxygen; FUNCTION(Perceptor,setPredicateName) { std::string inName; if ( (in.GetSize() != 1) || (! in.GetValue(in.begin(),inName)) ) { return false; } obj->SetPredicateName(inName); return true; } void CLASS(Perceptor)::DefineClass() { DEFINE_BASECLASS(oxygen/BaseNode); DEFINE_FUNCTION(setPredicateName); } --- NEW FILE: effector.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: effector.h,v 1.1 2005/12/05 21:16:49 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef OXYGEN_EFFECTOR_H #define OXYGEN_EFFECTOR_H // #ifdef HAVE_CONFIG_H // #include <config.h> // #endif #include <oxygen/sceneserver/basenode.h> #include <oxygen/gamecontrolserver/baseparser.h> namespace oxygen { class ActionObject; class AgentAspect; class Effector : public BaseNode { public: Effector() : BaseNode() {}; virtual ~Effector() {}; /** realizes the action described by the ActionObject */ virtual bool Realize(boost::shared_ptr<ActionObject> action) = 0; /** returns the name of the predicate this effector implements */ virtual std::string GetPredicate() = 0; /** constructs an Actionobject, describing a predicate */ virtual boost::shared_ptr<ActionObject> GetActionObject(const Predicate& predicate) = 0; protected: /** Returns the AgentAspect this Effector belongs to */ boost::shared_ptr<AgentAspect> GetAgentAspect(); }; DECLARE_ABSTRACTCLASS(Effector); } // namespace oxygen #endif //OXYGEN_EFFECTOR_H --- NEW FILE: agentaspect_c.cpp --- /* -*- mode: c++; c-basic-indent: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: agentaspect_c.cpp,v 1.1 2005/12/05 21:16:49 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "agentaspect.h" using namespace boost; using namespace oxygen; void CLASS(AgentAspect)::DefineClass() { DEFINE_BASECLASS(oxygen/Transform); } --- NEW FILE: effector.cpp --- /* -*- mode: c++; c-basic-indent: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: effector.cpp,v 1.1 2005/12/05 21:16:49 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "effector.h" #include "agentaspect.h" using namespace oxygen; using namespace boost; shared_ptr<AgentAspect> Effector::GetAgentAspect() { return shared_static_cast<AgentAspect> (make_shared(GetParentSupportingClass("AgentAspect"))); } --- NEW FILE: perceptor.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: perceptor.h,v 1.1 2005/12/05 21:16:49 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef OXYGEN_PERCEPTOR_H #define OXYGEN_PERCEPTOR_H #include <oxygen/sceneserver/basenode.h> #include <oxygen/gamecontrolserver/baseparser.h> namespace oxygen { class Perceptor : public oxygen::BaseNode { public: /*! This is called by agents to trigger the percept event implemented by this perceptor. The perceptor can return data through the PredicateList which is passed as a parameter. \return true, if valid data is available and false otherwise. */ virtual bool Percept(boost::shared_ptr<PredicateList> predList) = 0; //! set / change predicate name (for example for debugging purposes) void SetPredicateName(const std::string& my_name); protected: //! the predicate name std::string mPredicateName; }; DECLARE_ABSTRACTCLASS(Perceptor); } // namespace oxygen #endif //OXYGEN_PERCEPTOR_H --- NEW FILE: agentaspect.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: agentaspect.h,v 1.1 2005/12/05 21:16:49 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef OXYGEN_AGENTASPECT_H #define OXYGEN_AGENTASPECT_H // #ifdef HAVE_CONFIG_H // #include <config.h> // #endif #include <oxygen/sceneserver/transform.h> #include <oxygen/gamecontrolserver/actionobject.h> #include <oxygen/gamecontrolserver/baseparser.h> #include "effector.h" #include "perceptor.h" namespace oxygen { #if 0 } #endif class AgentAspect : public Transform { public: AgentAspect(); virtual ~AgentAspect(); /** Initializes the AgentAspect. Called immediately after the AgentAspect is created by the GameControlServer. \param createEffector is the name of the initial effector class that the agent uses to construct all remaining parts */ virtual bool Init(const std::string& createEffector); /** RealizeActions realizes the actions described by \param actions using the corresponding effectors */ virtual bool RealizeActions(boost::shared_ptr<ActionObject::TList> actions); /** QuerySensors collects data from all perceptors below this AgentAspect */ virtual boost::shared_ptr<PredicateList> QueryPerceptors(); /** updates the map of Effectors below this AgentAspect */ virtual void UpdateEffectorMap(); /** looks up the effector corresponding to a predicate */ virtual boost::shared_ptr<Effector> GetEffector(const std::string predicate) const; protected: typedef std::map<std::string, boost::shared_ptr<Effector> > TEffectorMap; //! the map of effectors below this AgentAspect TEffectorMap mEffectorMap; private: }; DECLARE_CLASS(AgentAspect); } // namespace oxygen #endif //OXYGEN_AGENTASPECT_H --- NEW FILE: perceptor.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: perceptor.cpp,v 1.1 2005/12/05 21:16:49 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "perceptor.h" using namespace oxygen; void Perceptor::SetPredicateName(const std::string& my_name) { mPredicateName = my_name; } |