private double observingToFollowingProb() { double percentageDancers = ((double)DanceFloor.DancerCount()) / ((double)Swarm.BeeCount); return(percentageDancers / (percentageDancers + Constants.RECRUITMENT_CONSTANT)); }
private void ChangeState() { switch (memory.Status) { case State.RESTING: memory.Status = State.OBSERVING; break; case State.OBSERVING: if (rand.NextDouble() <= observingToFollowingProb()) { //Bee starts following instead of going back to explore Destination newDestination = DanceFloor.GetSite(); if (newDestination != null) { memory.Destination = newDestination; if (newDestination is Site) { memory.Status = State.FOLLOWING; memory.Site = (Site)newDestination; } } } else { //Bee starts exploring instead of following memory.Status = State.EXPLORING; StartLevySearch(GetRandomAngle(), RandomFlightLength()); } break; case State.EXPLORING: if (memory.Site == null) { memory.Status = State.RETURNING; memory.Destination = new Location(Swarm.hive); } else { BeginAssessment(); } break; case State.FOLLOWING: BeginAssessment(); break; case State.ASSESSING: memory.Site.CurrentVisitorCount--; if (memory.Site.CurrentVisitorCount > this.QUORUM_THRESHOLD) { memory.QuorumSensed = true; } memory.Status = State.RETURNING; memory.Destination = new Location(Swarm.hive); break; case State.RETURNING: if (memory.Site == null) { memory.Status = State.RESTING; } else { /*if (memory.QuorumSensed && !Swarm.PipingSupressed) * { * memory.Status = State.PIPING; * Swarm.increaseNoise(); * memory.QuorumSensed = false; * } * else*/ { DanceFloor.AddDancer(this); memory.Status = State.DANCING; } } break; case State.PIPING: Swarm.decreaseNoise(); RestOrReturn(); break; case State.DANCING: DanceFloor.RemoveDancer(this); RestOrReturn(); break; } }
/// <summary> /// Updates the variables that determine the equillibria /// </summary> private void updateEquilibriumEquations() { int R, O, E, A, D; double rDot, oDot, eDot, aDot, dDot; R = O = E = A = D = 0; ReadOnlyDictionary <Bee.State, int> taskDistribution = Swarm.GetTaskDistribution(); if (taskDistribution.ContainsKey(Bee.State.RESTING)) { R = taskDistribution[Bee.State.RESTING]; } if (taskDistribution.ContainsKey(Bee.State.OBSERVING)) { O = taskDistribution[Bee.State.OBSERVING]; } if (taskDistribution.ContainsKey(Bee.State.EXPLORING)) { E = taskDistribution[Bee.State.EXPLORING]; } if (taskDistribution.ContainsKey(Bee.State.ASSESSING)) { A = taskDistribution[Bee.State.ASSESSING]; } if (taskDistribution.ContainsKey(Bee.State.DANCING)) { D = taskDistribution[Bee.State.DANCING]; } ReadOnlyDictionary <double, int> danceDistrbution = DanceFloor.GetDanceDistribution(); double vnD = 0; double siteQuality = 0; if (danceDistrbution.Keys.Count != 0) { siteQuality = danceDistrbution.Keys.ToArray()[0]; } foreach (double quality in danceDistrbution.Keys) { vnD += ((1 - quality) * (0.666 / siteQuality) * (D)); } double pD = (D / (D + 0.323)); double qD = 1 - pD; // (2.1) Governing system of equations rDot = -(0.1 * R) + vnD; oDot = (0.1 * R) - (0.125 * O) + (0.033 * E); eDot = ((qD * 0.125 * O) - (0.033 * E)); if (siteQuality != 0) { aDot = ((pD * 0.125 * O) - (0.05 * A) + (0.005 * (0.066 / siteQuality) * D)); dDot = ((0.05 * A) - ((0.066 / siteQuality) * D)); } else { aDot = dDot = 0; } Rdot.Text = rDot.ToString(); Odot.Text = oDot.ToString(); Edot.Text = eDot.ToString(); Adot.Text = aDot.ToString(); Ddot.Text = dDot.ToString(); }