示例#1
0
    def __init__(self,agent,actions,senses,attributes=None,caller=None):
        """Initialises behaviour with given actions and senses.
        
        The actions and senses has to correspond to
          - the method names that implement those actions/senses
          - the names used in the plan
        
        The log domain of a behaviour is set to
        [AgentId].Behaviour
        
        
        @param agent: The agent that uses the behaviour
        @type agent: L{POSH.AgentBase}
        @param actions: The action names to register.
        @type actions: sequence of strings
        @param senses: The sense names to register.
        @type senses: sequence of string
        @param attributes: List of attributes to initialise behaviour state.
        @type attributes: as for L{POSH.Behaviour.assignAttributes}
        """
        LogBase.__init__(self, agent, "Behaviour")
        self.agent = agent
        # aquire the random number generator from the agent
        self.random = agent.random
                
        if caller!=None:
            self.get_actions_senses(caller)
        else:
            self._actions = actions
            self._senses = senses

        self._inspectors = None
        # assign attributes
        if attributes != None:
            self.assignAttributes(attributes)
示例#2
0
    def __init__(self, library, plan, attributes, world=None):
        """Initialises the agent to use the given library and plan.
        
        The plan has to be given as the plan name without the '.lap' extension.
        The attributes are the ones that are assigned to the behaviours
        when they are initialised. The world is the one that can be accessed
        by the behaviours by the L{AgentBase.getWorld} method.
        
        Note that when the behaviours are loaded from the given library, then
        they are reflected onto the agent object. That means, given that
        there is a behaviour called 'bot', then it can be accessed from another
        behaviour either by self.agent.getBehaviour("bot"), or by
        self.agent.bot. Consequently, behaviour names that clash with already
        existing agent attributes cause an AttributeError to be raise upon
        initialising the behaviours.
        
        The attributes are to be given in the same format as for the
        method L{AgentBase.assignAttributes}.
        
        @param library: The behaviour library to use.
        @type library: string
        @param plan: The plan to use (without the '.lap' ending).
        @type plan: string
        @param attributes: The attributes to be assigned to the behaviours
        @type attributes: as for L{AgentBase.assignAttributes}
        """
        # get unique id for agent first, as constructor of LogBase accesses it
        self.id = unique_agent_id()
        LogBase.__init__(self, self, "")
        # store library for use when spawning new agents
        self._library = library
        self._world = world
        # we need to set the random number generator before we
        # load the behaviours, as they might access it upon
        # construction
        self.random = random
        # if you are profiling, you need to fix this in your init_world.  see library/latchTest for an example & documentation
        # do this before loading Behaviours
        self.profiler = Profiler.initProfile(self)
        # load and register the behaviours, and reflect back onto agent
        self._bdict = self._loadBehaviours()
        self._reflectBehaviours()
        # more for the profiler
        # FIXME: PR -- is there another place to do this?  will it succeed without MASON? JJB 1 March 2008
        try:
            other.profiler.set_second_name(
                other._bdict._behaviours['MASON'].name)
        except:
            # may want this for debugging:  print "profiler is off and/or MASON is not being used"
            pass  # normally don't expect profiling, nor necessarily MASON

        # assign the initial attributes to the behaviours
        self.assignAttributes(attributes)
        # load the plan
        self._loadPlan(get_plan_file(library, plan))
        # loop thread control
        self._exec_loop = False
        self._loop_pause = False
示例#3
0
文件: behaviour.py 项目: clr/cos570
 def __init__(self, log):
     """Initialises behaviour.
     
     Here is the place to implement your acts and senses
     
     The log domain of a behaviour is set to class name.
           
     """
     LogBase.__init__(self, log, self.__class__.__name__)
示例#4
0
    def __init__(self, library, plan, attributes, world = None):
        """Initialises the agent to use the given library and plan.
        
        The plan has to be given as the plan name without the '.lap' extension.
        The attributes are the ones that are assigned to the behaviours
        when they are initialised. The world is the one that can be accessed
        by the behaviours by the L{AgentBase.getWorld} method.
        
        Note that when the behaviours are loaded from the given library, then
        they are reflected onto the agent object. That means, given that
        there is a behaviour called 'bot', then it can be accessed from another
        behaviour either by self.agent.getBehaviour("bot"), or by
        self.agent.bot. Consequently, behaviour names that clash with already
        existing agent attributes cause an AttributeError to be raise upon
        initialising the behaviours.
        
        The attributes are to be given in the same format as for the
        method L{AgentBase.assignAttributes}.
        
        @param library: The behaviour library to use.
        @type library: string
        @param plan: The plan to use (without the '.lap' ending).
        @type plan: string
        @param attributes: The attributes to be assigned to the behaviours
        @type attributes: as for L{AgentBase.assignAttributes}
        """
        # get unique id for agent first, as constructor of LogBase accesses it
        self.id = unique_agent_id()
        LogBase.__init__(self, self, "")
       # store library for use when spawning new agents
        self._library = library
        self._world = world
        # we need to set the random number generator before we
        # load the behaviours, as they might access it upon
        # construction
        self.random = random
        # if you are profiling, you need to fix this in your init_world.  see library/latchTest for an example & documentation
        # do this before loading Behaviours
        self.profiler=Profiler.initProfile(self) 
        # load and register the behaviours, and reflect back onto agent
        self._bdict = self._loadBehaviours()
        self._reflectBehaviours()
        # more for the profiler
        # FIXME: PR -- is there another place to do this?  will it succeed without MASON? JJB 1 March 2008
        try:
            other.profiler.set_second_name(other._bdict._behaviours['MASON'].name)
        except:
            # may want this for debugging:  print "profiler is off and/or MASON is not being used"
            pass # normally don't expect profiling, nor necessarily MASON
 
        # assign the initial attributes to the behaviours
        self.assignAttributes(attributes)
        # load the plan
        self._loadPlan(get_plan_file(library, plan))
        # loop thread control
        self._exec_loop = False
        self._loop_pause = False
示例#5
0
文件: element.py 项目: clr/cos570
 def __init__(self, agent, log_domain):
     """Initialises the element, and assigns it a unique id.
     
     @param agent: The agent that uses the element.
     @type agent: L{SPOSH.Agent}
     @param log_domain: The logging domain for the element.
     @type log_domain: string
     """
     LogBase.__init__(self, agent.getLog(), log_domain)
     self._id = _get_next_id()
     self._name = "NoName"
示例#6
0
    def __init__(self,agent,actions,senses,attributes=None,caller=None):
        """Initialises behaviour with given actions and senses.
        
        The actions and senses has to correspond to
          - the method names that implement those actions/senses
          - the names used in the plan
        
        The log domain of a behaviour is set to
        [AgentId].Behaviour
        
        
        @param agent: The agent that uses the behaviour
        @type agent: L{POSH.AgentBase}
        @param actions: The action names to register.
        @type actions: sequence of strings
        @param senses: The sense names to register.
        @type senses: sequence of string
        @param attributes: List of attributes to initialise behaviour state.
        @type attributes: as for L{POSH.Behaviour.assignAttributes}
        """
        import types
        LogBase.__init__(self, agent, "Behaviour")
        self.agent = agent
        # acquire the random number generator from the agent
        self.random = agent.random
                
        if caller!=None:
            self.get_actions_senses(caller)
        else:
            # In the behaviour class if you have a single action or
            # sense and specify it as e.g. ('sense') instead of
            # ('sense',) you will get an error when it gets processed
            # later on. The name is split into characters and so the
            # error message says that you haven't got a sense called
            # 's' ()or whatever the first letter is). Check for this
            # and fix up to save confusion later.
            errorMessage = "- Fixed %s parameter in %s._init__() not specified as a tuple"
            if type(actions) != types.TupleType:
                print errorMessage % ("actions", self.__class__.__name__)
                actions = (actions,)
            if type(senses) != types.TupleType:
                print errorMessage % ("senses", self.__class__.__name__)
                senses = (senses,)

            self._actions = actions
            self._senses = senses

        self._inspectors = None
        # assign attributes
        if attributes != None:
            self.assignAttributes(attributes)