/// <summary> /// Internal representation of a logistic task from one agent to another. /// </summary> /// <param name="sourceAgent">Source agent to collect from</param> /// <param name="destinationAgent">Destination agent to deliver to</param> /// <param name="amount">Amount to deliver</param> public TransportTask(Agent sourceAgent, Agent destinationAgent, double amount) { source = sourceAgent; // agent = sourceAgent; destination = destinationAgent; quantity = amount; agents = new List<TaskComparer>(); }
public void RemoveAgent(Agent agent) { if (trvCurPln.InvokeRequired) { NodeCallback d = new NodeCallback(RemoveAgent); trvCurPln.Invoke(d, new object[] { agent }); } else { if (agent is Operator || agent is Controller) { trvCurPln.Nodes[0].Nodes.Remove(agent); } else { trvCurPln.Nodes[1].Nodes[(int)agent.Type].Nodes.Remove(agent); trvCurPln.Nodes[1].Nodes[(int)agent.Type].Text = agentTypes[(int)agent.Type] + " (" + trvCurPln.Nodes[1].Nodes[(int)agent.Type].Nodes.Count + ")"; } } }
public void AddNewAgent(Agent agent) { if (trvCurPln.InvokeRequired) { NodeCallback d = new NodeCallback(AddNewAgent); trvCurPln.Invoke(d, new object[] { agent }); } else { // Check if a simulation agent has been added if ((int)agent.Type < 4) { trvCurPln.Nodes[1].Nodes[(int)agent.Type].Nodes.Add(agent); trvCurPln.Nodes[1].Nodes[(int)agent.Type].Text = agentTypes[(int)agent.Type] + " (" + trvCurPln.Nodes[1].Nodes[(int)agent.Type].Nodes.Count + ")"; } else { int newNode = trvCurPln.Nodes[0].Nodes.Add(agent); trvCurPln.Nodes[0].Nodes[newNode].Text = agentTypes[(int)agent.Type]; } int totAgents = 0; for (int i = 0; i < trvCurPln.Nodes[1].Nodes.Count; i++) { totAgents += trvCurPln.Nodes[1].Nodes[i].Nodes.Count; } trvCurPln.Nodes[1].Text = "Simulation Agents (" + totAgents + ")"; } }
protected override void Act() { // Perform a move location call if required if (destination != null) { Move(); if (destination.Intersect(new PointF(location.X + 4, location.Y + 4))) { // Perform a load action and send a message to the agent informing it of the // action if (((TransportTask)assignedTask).Load > load) { load = ((TransportTask)assignedTask).Load; InformMessage m = new InformMessage(this, assignedTask); messageQueue.SendPost(((TransportTask)assignedTask).Source, m); } else { load = 0; InformMessage m = new InformMessage(this, assignedTask); messageQueue.SendPost(((TransportTask)assignedTask).Destination, m); // Task complete clear the logistics agent for further tasks assignedTask = null; destination = null; } } } }
public void DeRegister(Agent agent) { if (postbox.ContainsKey(agent)) { postbox.Remove(agent); } }
/// <summary> /// Perform a hit test at the location in the environment /// </summary> /// <param name="x">X-Point of the environment</param> /// <param name="y">Y-Point of the environment</param> /// <returns>Selected agent if any</returns> public Agent Selected(float x, float y) { if (selectedAgent != null) { selectedAgent.Selected = false; selectedAgent = null; } for (int i = 0; i < agents.Count; i++) { Agent a = agents[i]; if (a.Intersect(new PointF(x, y))) { selectedAgent = a; } } if (selectedAgent != null) selectedAgent.Selected = true; return selectedAgent; }
/// <summary> /// Informs the supplier agent that it is now part of the coordination group /// </summary> /// <param name="author">Controller agent of the system</param> /// <param name="content">Supplier Task</param> protected void HandleInformMessage(Agent author, SupplierTask content) { coordinationNode.AddEdge(content.Manufacturer.CoordinationNode); communicationNode.AddEdge(content.Manufacturer.CommunicationNode); // Update the coordination information assignedTask = content; manager = author; }
void env_NewAgent(object sender, ref Agent agent) { populationStatus.AddNewAgent(agent); }
public RequestMessage(Agent Author, ref Task messageContent) : base(Author) { content = messageContent; }
public void SendPost(Agent destination, ref Message aMessage) { // Check if the post box exists if (postbox.ContainsKey(destination)) { // Post box exists place post into the box // postbox[destination].Enqueue(aMessage); MessageEvent(this, new MessageEventArgs(destination, aMessage)); } else { // Throw exception indicating that the post box is not valid throw new Exception("No post box exists for that destination"); } }
public void SelectNode(Agent agent) { trvCurPln.SelectedNode = agent; }
public InformMessage(Agent Author) : base(Author) { }
public InformMessage(Agent Author, object messageContent) : base(Author) { content = messageContent; }
/// <summary> /// Executes the logistics agent's sensor functionality. /// Determines the location of the destination agent. From the /// location the logistic agent can calculate the movement vector /// to its destinantion /// </summary> protected override void Sensor() { if (assignedTask != null) { // Check if the logistics agent has picked up the load if (((TransportTask)assignedTask).Load > load) destination = ((TransportTask)assignedTask).Source; else destination = ((TransportTask)assignedTask).Destination; // Calculate the movement unit vector to its destination. DetermineMoveDirection(); } }
public Message GetPost(Agent agent) { Message aMessage = null; // Check if a post box exists for this agent if (postbox.ContainsKey(agent)) { if (postbox[agent].Count > 0) { // Post is in the post box // Remove this message from the post box aMessage = postbox[agent].Dequeue(); } } return aMessage; }
/// <summary> /// Thread safe callback to update the treeview control. /// </summary> /// <param name="agent">Agent node to update</param> /// <param name="node">Child node to update</param> /// <param name="text">Text string to display in the node</param> protected void Update(Agent agent, string node, string text) { if (agent.TreeView.InvokeRequired) { UpdateCallback d = new UpdateCallback(Update); agent.TreeView.Invoke(d, new object[] { agent, node, text }); } else { agent.Nodes[node].Text = text; } }
public void Register(Agent agent) { if (!postbox.ContainsKey(agent)) { postbox.Add(agent, new Queue<Message>()); } }
public ClientTask(Agent client) { agents = new List<TaskComparer>(); agent = client; }
public MessageEventArgs(Agent Destination, Message newMessage) { destination = Destination; message = newMessage; }
public CommunicationGraphNode(Agent aAgent) { agent = aAgent; }
public RequestMessage(Agent Author, object messageContent) : base(Author) { content = messageContent; }
public CoordinationGraphNode(Agent aValue) { agent = aValue; }
void env_DeleteAgent(object sender, ref Agent agent) { populationStatus.RemoveAgent(agent); }
public bool RemoveAgent(Agent agent) { if (agents.Contains(agent)) { // Kill that agent agents.Remove(agent); agent.Kill(); if (DeleteAgent != null) DeleteAgent(this, ref agent); agent = null; return true; } return false; }
protected object content; // Message is contained as a object #endregion Fields #region Constructors /// <summary> /// Creates a message instance for the current agent /// </summary> /// <param name="aAgent">Agent that creates this message</param> public Message(Agent Author) { author = Author; }
/// <summary> /// Informs the Supplier agent that the transport request is completed. /// </summary> /// <param name="author">Controller agent</param> /// <param name="content">Transport Task request</param> protected void HandleInformMessage(Agent author, TransportTask content) { // Update the coordination information ((SupplierTask)assignedTask).Transport = content.RegisteredAgents[0].TaskAgent; communicationNode.AddEdge(content.RegisteredAgents[0].TaskAgent.CommunicationNode); }