/// <summary> /// Handle a request from any agent for the current controllers reference /// </summary> protected void HandleRequestMessage(Agent destination, Controller request) { if (request == null) { Message m = new InformMessage(this, manager); messageQueue.SendPost(destination, m); } }
private float speed; // Speed of movement for the current agent #endregion Fields #region Constructors public TransportAgent(ref Environment environment, ref MessageQueue messages, PointF spawnLocation, int agentID, Image image, Graphics g) : base(ref environment, ref messages, spawnLocation, agentID, image, g) { Reset(); // Create a new broadcast message (Inform) Message aMessage = new InformMessage(this); messageQueue.Broadcast(aMessage); Text = "Logistics " + id.ToString(); type = AGENT_TYPE.AGENT_LOGISTICS; SelectedImageIndex = (int)type; ImageIndex = (int)type; speed = 1.0f; }
public SupplierAgent(ref Environment environment, ref MessageQueue messages, PointF spawnLocation, int agentID, Image image, Graphics g) : base(ref environment, ref messages, spawnLocation, agentID, image, g) { Reset(); // Create a new broadcast message (Inform) Message aMessage = new InformMessage(this); messageQueue.Broadcast(aMessage); Text = "Supplier " + id.ToString(); type = AGENT_TYPE.AGENT_SUPPLIER; SelectedImageIndex = (int)type; ImageIndex = (int)type; supply = 0; }
private ExecutionTree tree; // Execution tree for the current run. #endregion Fields #region Constructors public Controller(ref Environment environment, ref MessageQueue messages, Image image, Graphics g) : base(ref environment, ref messages, new PointF(g.VisibleClipBounds.Width - 16, 0), 0, image, g) { Reset(); // Log agent creation manager = this; // Create a new broadcast message (Inform) Message aMessage = new InformMessage(this); messageQueue.Broadcast(aMessage); ImageKey = "cpu.png"; SelectedImageKey = "cpu.png"; type = AGENT_TYPE.AGENT_CONTROLLER; tree = environment.Execution; }
public ManufacturerAgent(ref Environment environment, ref MessageQueue messages, PointF spawnLocation, int agentID, Image image, Graphics g) : base(ref environment, ref messages, spawnLocation, agentID, image, g) { Reset(); // Create a new broadcast message (Inform) Message aMessage = new InformMessage(this); messageQueue.Broadcast(aMessage); Text = "Manufacturer " + id.ToString(); type = AGENT_TYPE.AGENT_MANUFACTURE; SelectedImageIndex = (int)type; ImageIndex = (int)type; stock = 0; product = 0; }
private double demand; // Represents the total amount of product which the client wants #endregion Fields #region Constructors public ClientAgent(ref Environment environment, ref MessageQueue messages, PointF spawnLocation, int agentID, Image image, Graphics g) : base(ref environment, ref messages, spawnLocation, agentID, image, g) { Reset(); // Create a new broadcast message (Inform) Message aMessage = new InformMessage(this); messageQueue.Broadcast(aMessage); Text = "Client " + id.ToString(); // GUI Display properties type = AGENT_TYPE.AGENT_CLIENT; SelectedImageIndex = (int)type; ImageIndex = (int)type; demand = 0; Nodes.Add("Quantity", "Quantity: " + demand.ToString(), 8, 8); }
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; } } } }
/// <summary> /// Handles a logistics agent request. /// </summary> /// <param name="destination">Original agent which made the request</param> /// <param name="task">Logistics task to be assigned</param> private void HandleInformMessage(TransportTask task) { if (task.RegisteredAgents.Count > 0) { // Generate a Supplier task InformMessage i = new InformMessage(this, task); task.Agent = task.RegisteredAgents[0].TaskAgent; // Send the message first to the client messageQueue.SendPost(task.Source, i); // Send the message also to the logistics agent messageQueue.SendPost(task.RegisteredAgents[0].TaskAgent, i); } }
private void HandleInformMessage(Agent destination, ManufacturerTask task) { if (task.RegisteredAgents.Count > 0) { // Generate a Supplier task SupplierTask sTask = new SupplierTask((SupplierAgent)task.RegisteredAgents[0].TaskAgent, (ManufacturerAgent)task.Agent, task.Demand); tree.AddChild(task, sTask); InformMessage i = new InformMessage(this, sTask); // Send the message first to the client messageQueue.SendPost(task.Agent, i); // Send the message also to the manufacturer messageQueue.SendPost(task.RegisteredAgents[0].TaskAgent, i); } }
/// <summary> /// Received a response from the operator with the results of the client /// task request in the environment. Check if a valid agent is registered /// and form a coordination group with the respective agents if required. /// </summary> /// <param name="destination">Client agent which made the original request</param> /// <param name="task">The results of the Client task request in the enivornment</param> private void HandleInformMessage(Agent destination, ClientTask task) { if (task.RegisteredAgents.Count > 0) { // Create an entry in the execution tree. For now the order // is placed as a task in the tree with the current client as // the target. ExecutionNode n = new ExecutionNode(task); tree.Root.Add(n); // Greedy method means that the best payoff result will be assigned to the // coordination group. // Send a message to the client and the manufacturer informing them of // the current situation InformMessage i = new InformMessage(this, task); // Send the message first to the client messageQueue.SendPost(task.Agent, i); // Generate a manufacturer task ManufacturerTask mTask = new ManufacturerTask((ClientAgent)task.Agent); mTask.Agent = task.RegisteredAgents[0].TaskAgent; tree.AddChild(task, mTask); i = new InformMessage(this, mTask); // Send the message also to the manufacturer communicationNode.AddEdge(task.RegisteredAgents[0].TaskAgent.CommunicationNode); messageQueue.SendPost(task.RegisteredAgents[0].TaskAgent, i); } }
void messageQueue_BroadcastEvent(object sender, BroadcastMessageEventArgs e) { Message broadcastMessage = e.BroadcastMessage; CommunicationGraphNode aNode = broadcastMessage.Author.CommunicationNode; // Add new agent to Communication Graph if (communicationGraph.Add(aNode)) { // Set the Authors node to the graph node GraphEdge edge = new CommunicationGraphEdge(broadcastMessage.Author.CommunicationNode, communicationNode); if (!aNode.Edges.Contains(edge)) aNode.Edges.Add(edge); edge = new CommunicationGraphEdge(communicationNode, broadcastMessage.Author.CommunicationNode); if (!communicationNode.Edges.Contains(edge)) communicationNode.Edges.Add(edge); // Write a message to the agent informing it that the Operator is aware // of its existance Message aMessage = new InformMessage(this); messageQueue.SendPost(broadcastMessage.Author, aMessage); // Also inform the controller if this agent is not a controller if ((broadcastMessage.Author is Controller)) { manager = broadcastMessage.Author; } } broadcastMessage = null; // Clear the message from the queue }
/// <summary> /// Handles a request message from the Controller for agents which can /// help fulfill the task request. The Operator will send a request /// to all of the agents in the communication graph connected directly with /// the operator to request the participating agents payoff functions. /// </summary> /// <param name="destination">Controller agent which made the request</param> /// <param name="task">A Manufacturer request for supply. Required in order to calculate a realistic payoff function.</param> private void HandleRequestMessage(Agent destination, Task task) { // Step through each agent in the communication graph connected to the operator foreach (CommunicationGraphEdge e in communicationNode.Edges) { // Send a payoff request to the agent which is not the operator Agent a = e.DestinationNode.Value; RequestMessage r = new RequestMessage(this, ref task); messageQueue.SendPost(a, r); } if (task.RegisteredAgents.Count > 0) task.RegisteredAgents.Sort(task.RegisteredAgents[0]); // Send the results back to the controller InformMessage i = new InformMessage(this, task); messageQueue.SendPost(destination, i); }