public Environment(BufferedGraphics g, ImageList newEntities, int size, int newIterations, int newDuration) { rnd = new Random(System.Environment.TickCount); stats = new Dictionary<STATISTIC, double>(); results = new List<string>(); messageQueue = new MessageQueue(); Environment a = this; executionTree = new ExecutionTree(ref a); entities = newEntities; device = g; WorkerSupportsCancellation = true; speed = 5; // Determine the percent chance that a new agent will be introduced into the environment. // The higher the chance the more likely the size of the population will be larger. if (size == 0) populationSize = 0.10; else if (size == 1) populationSize = 0.25; else if (size == 2) populationSize = 0.50; // Set the run parameters iterations = newIterations; duration = newDuration * 60; timer = new TimeSpan(); }
private Graph communicationGraph = new Graph(); // Communication graph structure #endregion Fields #region Constructors public Operator(ref Environment environment, ref MessageQueue messages, Image image, Graphics g) : base(ref environment, ref messages, new PointF(0, 0), 0, image, g) { Reset(); // Log agent creation switchboard = this; messageQueue.BroadcastEvent += new MessageQueue.BroadcastMessageHandler(messageQueue_BroadcastEvent); ImageKey = "telephone.png"; SelectedImageKey = "telephone.png"; type = AGENT_TYPE.AGENT_OPERATOR; }
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); }
/// <summary> /// Default constructor. Sets all local variables to null /// </summary> public Agent(ref Environment environment, ref MessageQueue messages, PointF spawnLocation, int agentID, Image image, Graphics g) { // Intialise variables env = environment; // Create a communication node for the agent messageQueue = messages; messageQueue.Register(this); messageQueue.MessageEvent += new MessageQueue.MessageHandler(messageQueue_MessageEvent); assignedTask = null; this.g = g; if (image != null) { this.image = image; location = spawnLocation; } coordinationNode = new CoordinationGraphNode(this); communicationNode = new CommunicationGraphNode(this); // Initialise Agent state variables id = agentID; rnd = new Random(System.Environment.TickCount); lifeCounter = rnd.Next(MIN_LIFE_COUNTER, MAX_LIFE_COUNTER); }
public void New() { if (agents != null && agents.Count > 0) { while (agents.Count > 0) { Agent agent = agents[agents.Count - 1]; RemoveAgent(agent); } } agents = new List<Agent>(); Environment a = this; messageQueue = new MessageQueue(); if (executionTree == null) executionTree = new ExecutionTree(ref a); Agent operatorAgent = AddNewAgent(AGENT_TYPE.AGENT_OPERATOR, entities.Images[(int)AGENT_TYPE.AGENT_OPERATOR]); operatorAgent.Name = "Operator"; Agent controllerAgent = AddNewAgent(AGENT_TYPE.AGENT_CONTROLLER, entities.Images[(int)AGENT_TYPE.AGENT_CONTROLLER]); controllerAgent.Name = "Controller"; timer = new TimeSpan(); stats = new Dictionary<STATISTIC, double>(); stats.Add(STATISTIC.STOCKPRODUCED, 0); stats.Add(STATISTIC.STOCKSENT, 0); stats.Add(STATISTIC.STOCKLOST, 0); stats.Add(STATISTIC.STOCKDELIVERED, 0); stats.Add(STATISTIC.STOCKDELIVEREDUSED, 0); stats.Add(STATISTIC.STOCKDELIVEREDLOST, 0); stats.Add(STATISTIC.PRODUCTPRODUCED, 0); stats.Add(STATISTIC.PRODUCTPRODUCEDUSED, 0); stats.Add(STATISTIC.PRODUCTPRODUCEDLOST, 0); stats.Add(STATISTIC.PRODUCTDELIVERED, 0); totAgents = 0; readings = 0; }