public ActorInfo GetNext(List<ActorInfo> actorList, ActorInfo currentActor) { var enabled = actorList.Where(info => info.enabled).ToList(); maxActors = Math.Max(maxActors, actorList.Count); maxEnabledActors = Math.Max(maxEnabledActors, enabled.Count); if (enabled.Count == 0) { return null; } var enabledNotSend = enabled.Where( info => info.currentOp != OpType.SEND && info.currentOp != OpType.Yield).ToList(); var choices = enabledNotSend.Count > 0 ? new List<ActorInfo> { enabledNotSend[0] } : enabled; int nextIndex = choices.Count == 1 ? 0 : rand.Next(choices.Count); LOGGER.Trace("Actors: {0}", new ActorList(actorList, choices[nextIndex])); if (numSteps >= stepLimit) { return null; } if (choices[nextIndex].currentOp == OpType.SEND || choices[nextIndex].currentOp == OpType.Yield) { ++numSteps; } return choices[nextIndex]; }
public ActorInfo GetNext(List<ActorInfo> actorList, ActorInfo currentActor) { // Add new actors to the priority list. for (int i = actorPriorityList.Count; i < actorList.Count; ++i) { InsertActorRandomly(actorList[i]); } var enabled = actorPriorityList.Where(info => info.enabled).ToList(); maxActors = Math.Max(maxActors, actorList.Count); maxEnabledActors = Math.Max(maxEnabledActors, enabled.Count); if (enabled.Count == 0) { return null; } var enabledNotSend = enabled.Where(info => info.currentOp != OpType.SEND && info.currentOp != OpType.Yield).ToList(); var choices = enabledNotSend.Count > 0 ? enabledNotSend : enabled; LOGGER.Trace("Actors: {0}", new ActorList(actorList, choices[0])); // Increment num steps and reduce priority of next actor if this is a change point. if (choices[0].currentOp == OpType.SEND || choices[0].currentOp == OpType.Yield) { if (numSteps >= stepLimit) { return null; } ++numSteps; if (changePoints.Contains(numSteps)) { if (badActors.Count > 0) { LOGGER.Info("ChangePoint {0}: boosting bad actor", numSteps); // move bad actor to the highest priority. actorPriorityList.Remove(badActors[0]); actorPriorityList.Insert(0, badActors[0]); badActors.RemoveAt(0); } else { LOGGER.Info("ChangePoint {0}: lowering current actor", numSteps); // move current actor to the lowest priority. actorPriorityList.Remove(choices[0]); actorPriorityList.Add(choices[0]); } changePoints.Remove(numSteps); } } if (choices[0].currentOp == OpType.Yield) { LOGGER.Info("Step {0}: lowering current actor because of yield.", numSteps); actorPriorityList.Remove(choices[0]); actorPriorityList.Add(choices[0]); } return choices[0]; }
private void InsertActorRandomly(ActorInfo actorInfo) { int pos = rand.Next(actorPriorityList.Count + 1); actorPriorityList.Insert(pos, actorInfo); if (expectBadActor) { if (actorInfo.name != null && actorInfo.name.StartsWith("bad")) { badActors.Add(actorInfo); } } }
public ActorList(List<ActorInfo> actorList, ActorInfo selected) { this.actorList = actorList; this.selected = selected; }