コード例 #1
0
 /// <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>();
 }
コード例 #2
0
 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 + ")";
     }
       }
 }
コード例 #3
0
 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 + ")";
       }
 }
コード例 #4
0
 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;
       }
     }
       }
 }
コード例 #5
0
 public void DeRegister(Agent agent)
 {
     if (postbox.ContainsKey(agent)) {
     postbox.Remove(agent);
       }
 }
コード例 #6
0
ファイル: Environment.cs プロジェクト: stevenandrewcarter/COG
 /// <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;
 }
コード例 #7
0
 /// <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;
 }
コード例 #8
0
ファイル: FrmCogMain.cs プロジェクト: stevenandrewcarter/COG
 void env_NewAgent(object sender, ref Agent agent)
 {
     populationStatus.AddNewAgent(agent);
 }
コード例 #9
0
 public RequestMessage(Agent Author, ref Task messageContent)
     : base(Author)
 {
     content = messageContent;
 }
コード例 #10
0
 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");
       }
 }
コード例 #11
0
 public void SelectNode(Agent agent)
 {
     trvCurPln.SelectedNode = agent;
 }
コード例 #12
0
 public InformMessage(Agent Author)
     : base(Author)
 {
 }
コード例 #13
0
 public InformMessage(Agent Author, object messageContent)
     : base(Author)
 {
     content = messageContent;
 }
コード例 #14
0
 /// <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();
       }
 }
コード例 #15
0
 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;
 }
コード例 #16
0
ファイル: Agent.cs プロジェクト: stevenandrewcarter/COG
 /// <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;
       }
 }
コード例 #17
0
 public void Register(Agent agent)
 {
     if (!postbox.ContainsKey(agent)) {
     postbox.Add(agent, new Queue<Message>());
       }
 }
コード例 #18
0
ファイル: ClientTask.cs プロジェクト: stevenandrewcarter/COG
 public ClientTask(Agent client)
 {
     agents = new List<TaskComparer>();
       agent = client;
 }
コード例 #19
0
 public MessageEventArgs(Agent Destination, Message newMessage)
 {
     destination = Destination;
       message = newMessage;
 }
コード例 #20
0
 public CommunicationGraphNode(Agent aAgent)
 {
     agent = aAgent;
 }
コード例 #21
0
 public RequestMessage(Agent Author, object messageContent)
     : base(Author)
 {
     content = messageContent;
 }
コード例 #22
0
 public CoordinationGraphNode(Agent aValue)
 {
     agent = aValue;
 }
コード例 #23
0
ファイル: FrmCogMain.cs プロジェクト: stevenandrewcarter/COG
 void env_DeleteAgent(object sender, ref Agent agent)
 {
     populationStatus.RemoveAgent(agent);
 }
コード例 #24
0
ファイル: Environment.cs プロジェクト: stevenandrewcarter/COG
 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;
 }
コード例 #25
0
ファイル: Message.cs プロジェクト: stevenandrewcarter/COG
        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;
        }
コード例 #26
0
 /// <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);
 }