Пример #1
0
        /// <summary>
        /// Initialises the logger.
        /// 
        /// The logger is initialised to send log messages
        /// under the logging domain [AgentId].[log_name]. The 
        /// name of the agent is retrieved by accessing C{agent.id}
        /// variable.
        /// 
        /// If the logger is initialised for the agent itself,
        /// logName has to be set to an empty string.
        /// </summary>
        /// <param name="agent">A POSH agent.
        /// </param>
        /// <param name="logName">Name of the logging domain, "" if called
        /// for the agent.</param>
        /// <param name="defaultLevel">The default logging level.</param>
        public LogBase(string logName, AgentBase agent, object defaultLevel, bool debug)
        {
            // workaround for scheduled POSH, where not all plan elements are
            // initialised with an agent -> the given 'agent' attribute does
            // not have an id

            _debug_ = debug;
            attributes = new Dictionary<string, object>();

            if (agent == null)
                m_agent = ((AgentBase)this);
            else
            {
                m_agent = agent;
                string agentId = agent.id != string.Empty ? agent.id : "NOID";

                if (logName == string.Empty){
                    // called for the agent
                    logDomain = agentId;
                }else
                    logDomain = agentId+"."+logName;
            #if LOG_ON
                log = LogManager.GetLogger(logDomain);
            #else
                log = new Log();
            #endif
            }
            #if LOG_ON
            if (defaultLevel != null)
                ((log4net.Repository.Hierarchy.Logger)log.Logger).Level= defaultLevel as Level;

              //  log4net.Config.XmlConfigurator.Configure();
            #endif
        }
Пример #2
0
        /// <summary>
        /// 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
        /// </summary>
        /// <param name="agent">The agent that uses the behaviour</param>
        /// <param name="actions">The action names to register.</param>
        /// <param name="senses">The sense names to register.</param>
        /// <param name="attributes">List of attributes to initialise behaviour state.</param>
        /// <param name="caller"></param>
        public Behaviour(AgentBase agent,string [] actions,string []senses,Dictionary<string,object> a_attributes,Behaviour caller)
            : this(agent)
        {
            Dictionary<string, SortedList<float,POSHPrimitive>> availableActions = new Dictionary<string, SortedList<float,POSHPrimitive>>();
            Dictionary<string, SortedList<float,POSHPrimitive>> availableSenses = new Dictionary<string, SortedList<float,POSHPrimitive>>();

            if (caller != null)
                GetActionsSenses(caller);
            else
            {
                MethodInfo[] methods = this.GetType().GetMethods();

                availableActions = ExtractPrimitives(this, true);
                availableSenses = ExtractPrimitives(this,false);

                // filtering the primitives which sould not be made available for the agent
                FilterPrimitives(actions,availableActions);
                FilterPrimitives(senses,availableSenses);

                this.attributes[ACTIONS] = availableActions;
                this.attributes[SENSES] = availableSenses;
            }

            this.attributes.Add(INSPECTORS,null);

            // assign additional attributes
            if (a_attributes != null)
                AssignAttributes(a_attributes);
        }
Пример #3
0
 public Movement(AgentBase agent)
     : base(agent,
     new string[] {},
     new string[] {})
 {
     this.info = new PositionsInfo();
     pathHomeId = "PathHome";
     reachPathHomeId = "ReachPathHome";
     pathToEnemyBaseId = "PathThere";
     reachPathToEnemyBaseID = "ReachPathThere";
 }
Пример #4
0
        /// <summary>
        /// Allows To limit the freedom of the action selection by inhibiting agents the usage of certain behaviours.
        /// This follows the idea of Object orientation and Accessability of unneeded information.
        /// </summary>
        /// <param name="agent">The agentbase containing information regarding the used lap plan</param>
        /// <returns>True if the behaviour should be usable by the agent. False otherwise.</returns>
        public bool IsSuitedForAgent(AgentBase agent)
        {
            if (suitedPlans.Trim() == string.Empty)
            {
                return(true);
            }
            if (!suitedPlans.Contains('|'))
            {
                return(agent.linkedPlanName == suitedPlans);
            }
            string [] plans = suitedPlans.Split(new char[] { '|' });

            return(plans.Contains(agent.linkedPlanName));
        }
Пример #5
0
        /// <summary>
        /// Initialises the logger.
        ///
        /// The logger is initialised to send log messages
        /// under the logging domain [AgentId].[log_name]. The
        /// name of the agent is retrieved by accessing C{agent.id}
        /// variable.
        ///
        /// If the logger is initialised for the agent itself,
        /// logName has to be set to an empty string.
        /// </summary>
        /// <param name="agent">A POSH agent.
        /// </param>
        /// <param name="logName">Name of the logging domain, "" if called
        /// for the agent.</param>
        /// <param name="defaultLevel">The default logging level.</param>
        public LogBase(string logName, AgentBase agent, object defaultLevel, bool debug)
        {
            // workaround for scheduled POSH, where not all plan elements are
            // initialised with an agent -> the given 'agent' attribute does
            // not have an id

            _debug_    = debug;
            attributes = new Dictionary <string, object>();

            if (agent == null)
            {
                m_agent = ((AgentBase)this);
            }
            else
            {
                m_agent = agent;
                string agentId = agent.id != string.Empty ? agent.id : "NOID";

                if (logName == string.Empty)
                {
                    // called for the agent
                    logDomain = agentId;
                }
                else
                {
                    logDomain = agentId + "." + logName;
                }
#if LOG_ON
                log = LogManager.GetLogger(logDomain);
#else
                log = new Log();
#endif
            }
#if LOG_ON
            if (defaultLevel != null)
            {
                ((log4net.Repository.Hierarchy.Logger)log.Logger).Level = defaultLevel as Level;
            }

            //  log4net.Config.XmlConfigurator.Configure();
#endif
        }
Пример #6
0
        public override BehaviourDict GetBehaviours(string lib, ILog log,AgentBase agent)
#endif
        {
            BehaviourDict dict = new BehaviourDict();
            Behaviour[] behaviours = null;
            if (log is ILog)
                log.Debug("Scanning library " + lib + " for behaviour classes");

            if (this.connector is IBehaviourConnector)
                behaviours = this.connector.GetBehaviours(agent);

            if (behaviours != null)
                foreach (Behaviour behave in behaviours)
                    if (behave != null && behave.GetType().IsSubclassOf(typeof(Behaviour)))
                        dict.RegisterBehaviour(behave);



            return dict;
        }
Пример #7
0
        public virtual BehaviourDict GetBehaviours(string lib, ILog log, AgentBase agent)
#endif
        {
            BehaviourDict dict = new BehaviourDict();

            Type[] types = new Type[1] {
                typeof(AgentBase)
            };

            if (log is ILog)
            {
                log.Debug("Scanning library " + lib + " for behaviour classes");
            }


            Assembly a = GetAssembly(lib);

            foreach (Type t in a.GetTypes())
            {
                if (t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(POSH.sys.Behaviour)) && (this.worldScript == null || t.Name != this.worldScript.Second))
                {
                    log.Info(String.Format("Creating instance of behaviour {0}.", t));
                    ConstructorInfo behaviourConstruct = t.GetConstructor(types);
                    object[]        para = new object[1] {
                        agent
                    };
                    log.Debug("Registering behaviour in behaviour dictionary");
                    if (behaviourConstruct != null)
                    {
                        Behaviour behave = (Behaviour)behaviourConstruct.Invoke(para);
                        if (behave.IsSuitedForAgent(agent))
                        {
                            dict.RegisterBehaviour(behave);
                        }
                    }
                }
            }

            return((dict.getBehaviours().Count() > 0) ? dict : new BehaviourDict());
        }
Пример #8
0
        /// <summary>
        /// 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
        /// </summary>
        /// <param name="agent">The agent that uses the behaviour</param>
        /// <param name="actions">The action names to register.</param>
        /// <param name="senses">The sense names to register.</param>
        /// <param name="attributes">List of attributes to initialise behaviour state.</param>
        /// <param name="caller"></param>
        public Behaviour(AgentBase agent, string [] actions, string [] senses, Dictionary <string, object> a_attributes, Behaviour caller)
            : this(agent)
        {
            Dictionary <string, SortedList <float, POSHPrimitive> > availableActions = new Dictionary <string, SortedList <float, POSHPrimitive> >();
            Dictionary <string, SortedList <float, POSHPrimitive> > availableSenses  = new Dictionary <string, SortedList <float, POSHPrimitive> >();

            if (caller != null)
            {
                GetActionsSenses(caller);
            }
            else
            {
                MethodInfo[] methods = this.GetType().GetMethods();

                availableActions = ExtractPrimitives(this, true);
                availableSenses  = ExtractPrimitives(this, false);


                // filtering the primitives which sould not be made available for the agent
                FilterPrimitives(actions, availableActions);
                FilterPrimitives(senses, availableSenses);



                this.attributes[ACTIONS] = availableActions;
                this.attributes[SENSES]  = availableSenses;
            }

            this.attributes.Add(INSPECTORS, null);

            // assign additional attributes
            if (a_attributes != null)
            {
                AssignAttributes(a_attributes);
            }
        }
Пример #9
0
 public virtual BehaviourDict GetBehaviours(string lib, AgentBase agent)
 {
     return(GetBehaviours(lib, null, agent));
 }
Пример #10
0
 public LatchedBehaviour(AgentBase agent, string[] actions, string[] senses, 
     Dictionary<string, object> attributes, Behaviour caller)
     : base(agent,actions,senses,attributes,caller)
 {
 }
Пример #11
0
 private static Profiler _reallyInitProfile(AgentBase other)
 {
     other.profiler = new Profiler(other.id);
     return(other.profiler);
 }
Пример #12
0
 public override BehaviourDict GetBehaviours(string lib, AgentBase agent)
 {
     return(GetBehaviours(lib, null, agent));
 }
Пример #13
0
        public override BehaviourDict GetBehaviours(string lib,AgentBase agent)
		{
			return GetBehaviours (lib, null,agent);
		}
Пример #14
0
 public LogBase(string logName, AgentBase agent)
     : this(logName, agent, null, false)
 {
 }
Пример #15
0
 // this normally does nothing.  If you want it to do something, you have to reset it!
 // (see next two functions)
 private static Profiler _initProfile(AgentBase other)
 {
     return null;
 }
Пример #16
0
 public LatchedBehaviour(AgentBase agent, string[] actions, string[] senses)
     : this(agent, actions, senses, null, null)
 {
 }
Пример #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="agent"></param>
 /// <param name="planName"></param>
 /// <returns></returns>
 public void ReLinkAgents(AgentBase agent, string planName)
 {
     agent.LoadPlan(planName);
 }
Пример #18
0
        /// <summary>
        /// Returns a sequence of classes, containing all behaviour classes that
        /// are available in a particular library.
        ///
        /// The method searches the behaviour subclasses by attempting to import
        /// all file in the library ending in .dll, except for the WORLDSCRIPT, and
        /// search through all classes they contain to see if they are derived from
        /// any behaviour class.
        ///
        /// If a log object is given, then logging output at the debug level is
        /// produced.
        /// </summary>
        /// <param name="lib">Name of the library to find the classes for</param>
        /// <param name="log">A log object</param>
        /// <returns>The dictionary containing the Assembly dll name and the included Behaviour classes</returns>
#if LOG_ON
        public virtual BehaviourDict GetBehaviours(string lib, log4net.ILog log, AgentBase agent)
Пример #19
0
 public Behaviour(AgentBase agent,string [] actions,string []senses)
     : this(agent,actions,senses,null, null)
 {
 }
Пример #20
0
        /// <summary>
        /// Allows To limit the freedom of the action selection by inhibiting agents the usage of certain behaviours.
        /// This follows the idea of Object orientation and Accessability of unneeded information.
        /// </summary>
        /// <param name="agent">The agentbase containing information regarding the used lap plan</param>
        /// <returns>True if the behaviour should be usable by the agent. False otherwise.</returns>
        public bool IsSuitedForAgent(AgentBase agent)
        {
            if (suitedPlans.Trim() == string.Empty)
                return true;
            if (!suitedPlans.Contains('|'))
                return ( agent.linkedPlanName == suitedPlans);
            string [] plans = suitedPlans.Split(new char[]{'|'});

            return (plans.Contains(agent.linkedPlanName));
        }
Пример #21
0
 public Status(AgentBase agent)
     : base(agent,
                 new string[] {},
 new string[] {})
 {
 }
Пример #22
0
 //public List<string> actions{get; private set;}
 /// <summary>
 /// Returns a list of available senses.
 /// </summary>
 //public List<string> senses {get; private set;}
 //private List<string> inspectors;getN
 Behaviour(AgentBase agent)
     : base("Behaviour", agent)
 {
     this.agent = agent;
     this.suitedPlans = string.Empty;
     // aquire the random number generator from the agent
     this.random = agent.random;
     this.attributes = new Dictionary<string, object>();
 }
Пример #23
0
        public virtual BehaviourDict GetBehaviours(string lib, AgentBase agent)
		{
			return GetBehaviours (lib, null, agent);
		}
Пример #24
0
 public void computeMultiAgentAverage(string fileName, AgentBase[] agents)
 {
     // TODO: Profiler needs to be completed
     throw new NotImplementedException();
 }
Пример #25
0
        /// <summary>
        /// Returns a sequence of classes, containing all behaviour classes that
        /// are available in a particular library.
        /// 
        /// The method searches the behaviour subclasses by attempting to import
        /// all file in the library ending in .dll, except for the WORLDSCRIPT, and
        /// search through all classes they contain to see if they are derived from
        /// any behaviour class.
        /// 
        /// If a log object is given, then logging output at the debug level is
        /// produced.
        /// </summary>
        /// <param name="lib">Name of the library to find the classes for</param>
        /// <param name="log">A log object</param>
        /// <returns>The dictionary containing the Assembly dll name and the included Behaviour classes</returns>
#if LOG_ON
        public virtual BehaviourDict GetBehaviours(string lib, log4net.ILog log,AgentBase agent)
Пример #26
0
 private static Profiler _reallyInitProfile(AgentBase other)
 {
     other.profiler = new Profiler(other.id);
     return other.profiler;
 }
Пример #27
0
        public virtual BehaviourDict GetBehaviours(string lib, ILog log,AgentBase agent)
#endif
        {
            BehaviourDict dict = new BehaviourDict();
            Type[] types = new Type[1] { typeof(AgentBase) };

            if (log is ILog)
                log.Debug("Scanning library "+lib+" for behaviour classes");

            
            Assembly a = GetAssembly(lib);
            foreach(Type t in a.GetTypes())
                if (t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(POSH.sys.Behaviour)) && (this.worldScript == null || t.Name != this.worldScript.Second))
                {
                    log.Info(String.Format("Creating instance of behaviour {0}.", t));
                    ConstructorInfo behaviourConstruct = t.GetConstructor(types);
                    object[] para = new object[1] { agent };
                    log.Debug("Registering behaviour in behaviour dictionary");
                    if (behaviourConstruct != null)
                    {
                        Behaviour behave = (Behaviour)behaviourConstruct.Invoke(para);
                        if (behave.IsSuitedForAgent(agent))
                                dict.RegisterBehaviour(behave);
                    }
                }
            
            return ( dict.getBehaviours().Count() > 0 ) ? dict : new BehaviourDict();
        }
Пример #28
0
 public LatchedBehaviour(AgentBase agent, string[] actions, string[] senses,
                         Dictionary <string, object> attributes, Behaviour caller)
     : base(agent, actions, senses, attributes, caller)
 {
 }
Пример #29
0
 /// <summary>
 /// Running is checking if the agents are still active. 
 /// The method should be called only once when all agents are started to either iteratively check if they are all active(loopsRunning = true). In this case, 
 /// the method will only return when all agents stoped running.
 /// If you want externally check if the agents are active use loopsRunning = false to see if at least one agent is alive.
 /// </summary>
 /// <param name="verbose">If true, we try to write an info stream to the Console.</param>
 /// <param name="agents">The list of Agents we want to check.</param>
 /// <param name="iterate">If true, we iterativly check all agents and return once none is active. 
 /// If false, we just execute one cycle and return if at least one agent is active.</param>
 /// <returns> Returns the status of the system based on at least one active agent.</returns>
 public virtual bool Running(bool verbose, AgentBase[] agents, bool iterate)
 {
     // check all 0.1 seconds if the loops are still running, and exit otherwise
     while (iterate)
     {
         Thread.Sleep(100);
         iterate = false;
         foreach (AgentBase agent in agents)
             if (agent.LoopStatus().First)
                 iterate = true;
     }
     if (verbose)
         Console.Out.WriteLine("- all agents stopped");
     return iterate;
 }
Пример #30
0
        /// <summary>
        /// Returns a sequence of classes, containing all behaviour classes that
        /// are available in a particular library.
        /// 
        /// The method searches the behaviour subclasses by attempting to import
        /// all file in the library ending in .dll, except for the WORLDSCRIPT, and
        /// search through all classes they contain to see if they are derived from
        /// any behaviour class.
        /// 
        /// If a log object is given, then logging output at the debug level is
        /// produced.
        /// </summary>
        /// <param name="lib">Name of the library to find the classes for</param>
        /// <param name="log">A log object</param>
        /// <returns>The dictionary containing the Assembly dll name and the included Behaviour classes</returns>
#if LOG_ON
        public override BehaviourDict GetBehaviours(string lib, log4net.ILog log, AgentBase agent)
Пример #31
0
        public bool StartAgents(bool verbose, AgentBase[] agents)
        {
            if (verbose)
                Console.Out.WriteLine("- starting the agent(s)");
            if (agents is AgentBase[])
                foreach (AgentBase agent in agents)
                    agent.StartLoop();

            return true;
        }
Пример #32
0
 // this normally does nothing.  If you want it to do something, you have to reset it!
 // (see next two functions)
 private static Profiler _initProfile(AgentBase other)
 {
     return(null);
 }
Пример #33
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="agent"></param>
 /// <param name="planName"></param>
 /// <returns></returns>
 public void ReLinkAgents(AgentBase agent,string planName)
 {
     agent.LoadPlan(planName);
 }
Пример #34
0
 public Combat(AgentBase agent)
     : base(agent,new string[] {},
                 new string[] {})
 {
     info = new CombatInfo();
 }
Пример #35
0
 public UTBehaviour(AgentBase agent, string[] actions, string[] senses)
     : base(agent, actions, senses)
 {
 }
Пример #36
0
        /// <summary>
        /// Returns a sequence of classes, containing all behaviour classes that
        /// are available in a particular library.
        ///
        /// The method searches the behaviour subclasses by attempting to import
        /// all file in the library ending in .dll, except for the WORLDSCRIPT, and
        /// search through all classes they contain to see if they are derived from
        /// any behaviour class.
        ///
        /// If a log object is given, then logging output at the debug level is
        /// produced.
        /// </summary>
        /// <param name="lib">Name of the library to find the classes for</param>
        /// <param name="log">A log object</param>
        /// <returns>The dictionary containing the Assembly dll name and the included Behaviour classes</returns>
#if LOG_ON
        public override BehaviourDict GetBehaviours(string lib, log4net.ILog log, AgentBase agent)
Пример #37
0
 public LogBase(string logName, AgentBase agent) : this(logName, agent, null, false)
 {
 }