/// <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 }
/// <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); }
public Movement(AgentBase agent) : base(agent, new string[] {}, new string[] {}) { this.info = new PositionsInfo(); pathHomeId = "PathHome"; reachPathHomeId = "ReachPathHome"; pathToEnemyBaseId = "PathThere"; reachPathToEnemyBaseID = "ReachPathThere"; }
/// <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)); }
/// <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 }
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; }
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()); }
/// <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); } }
public virtual BehaviourDict GetBehaviours(string lib, AgentBase agent) { return(GetBehaviours(lib, null, agent)); }
public LatchedBehaviour(AgentBase agent, string[] actions, string[] senses, Dictionary<string, object> attributes, Behaviour caller) : base(agent,actions,senses,attributes,caller) { }
private static Profiler _reallyInitProfile(AgentBase other) { other.profiler = new Profiler(other.id); return(other.profiler); }
public override BehaviourDict GetBehaviours(string lib, AgentBase agent) { return(GetBehaviours(lib, null, agent)); }
public override BehaviourDict GetBehaviours(string lib,AgentBase agent) { return GetBehaviours (lib, null,agent); }
public LogBase(string logName, AgentBase agent) : this(logName, agent, null, false) { }
// 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; }
public LatchedBehaviour(AgentBase agent, string[] actions, string[] senses) : this(agent, actions, senses, null, null) { }
/// <summary> /// /// </summary> /// <param name="agent"></param> /// <param name="planName"></param> /// <returns></returns> public void ReLinkAgents(AgentBase agent, string planName) { agent.LoadPlan(planName); }
/// <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)
public Behaviour(AgentBase agent,string [] actions,string []senses) : this(agent,actions,senses,null, null) { }
/// <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)); }
public Status(AgentBase agent) : base(agent, new string[] {}, new string[] {}) { }
//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>(); }
public virtual BehaviourDict GetBehaviours(string lib, AgentBase agent) { return GetBehaviours (lib, null, agent); }
public void computeMultiAgentAverage(string fileName, AgentBase[] agents) { // TODO: Profiler needs to be completed throw new NotImplementedException(); }
/// <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)
private static Profiler _reallyInitProfile(AgentBase other) { other.profiler = new Profiler(other.id); return other.profiler; }
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(); }
public LatchedBehaviour(AgentBase agent, string[] actions, string[] senses, Dictionary <string, object> attributes, Behaviour caller) : base(agent, actions, senses, attributes, caller) { }
/// <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; }
/// <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)
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; }
// 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); }
/// <summary> /// /// </summary> /// <param name="agent"></param> /// <param name="planName"></param> /// <returns></returns> public void ReLinkAgents(AgentBase agent,string planName) { agent.LoadPlan(planName); }
public Combat(AgentBase agent) : base(agent,new string[] {}, new string[] {}) { info = new CombatInfo(); }
public UTBehaviour(AgentBase agent, string[] actions, string[] senses) : base(agent, actions, senses) { }