public void GetTasksInProgressTest2() { Assert.AreEqual(0, _tasksManager.GetTasksInProgress(1).Count); _tasksManager.AddInProgress(_task); _task.Add(1, 1); Assert.AreEqual(0, _tasksManager.GetTasksInProgress(1).Count); }
/// <summary> /// Check if the incompleteInformation model is on /// If so, check if the task is blocked (has incomplete information) /// and ask help from teammates /// </summary> /// <param name="task"></param> /// <returns>true if the task is blocked</returns> public bool CheckBlockerIncompleteInformation(SymuTask task) { if (task is null) { throw new ArgumentNullException(nameof(task)); } var murphy = Environment.MainOrganization.Murphies.IncompleteInformation; if (!murphy.On || Math.Abs(task.WorkToDo) < Tolerance || // Task is done !task.IsAssigned || !task.HasCreator || task.Creator.Equals(AgentId)) // Worker can't be blocked by himself { return(false); } var blocked = murphy.CheckInformation(); if (!blocked) { return(false); } var blocker = task.Add(Murphy.IncompleteInformation, Schedule.Step); TryRecoverBlocker(task, blocker); return(true); }
/// <summary> /// Agent has checked its beliefs against the task. /// Now the agent must define its answer given the mandatory and required scores /// By default, mandatoryScore is checked against MurphyIncompleteBeliefs.ThresholdForReacting /// The task is blocked if necessary. /// Override this method to implement your own answer /// </summary> /// <param name="task"></param> /// <param name="knowledgeId"></param> /// <param name="mandatoryScore"></param> /// <param name="requiredScore"></param> /// <param name="mandatoryIndex"></param> /// <param name="requiredIndex"></param> /// <exception cref="ArgumentNullException"></exception> protected virtual void CheckBlockerIncompleteBelief(SymuTask task, IAgentId knowledgeId, float mandatoryScore, float requiredScore, byte mandatoryIndex, byte requiredIndex) { if (task == null) { throw new ArgumentNullException(nameof(task)); } // Cognitive.InternalCharacteristics.RiskAversionThreshold should be > Environment.Organization.Murphies.IncompleteBelief.ThresholdForReacting if (mandatoryScore > -Environment.MainOrganization.Murphies.IncompleteBelief.ThresholdForReacting) { return; } // mandatoryScore is not enough => agent don't want to do the task, the task is blocked var blocker = task.Add(Murphy.IncompleteBelief, Schedule.Step, knowledgeId, mandatoryIndex); TryRecoverBlockerIncompleteBelief(task, blocker); }
/// <summary> /// Check a particular beliefId from Task.BeliefBits against Agent.Beliefs /// Prevent the agent from acting on a particular belief /// Task may be blocked if it is the case /// </summary> public void CheckRiskAversion(SymuTask task, IAgentId knowledgeId) { if (task is null) { throw new ArgumentNullException(nameof(task)); } if (!BeliefsModel.On) { return; } var taskBits = task.KnowledgesBits.GetBits(knowledgeId); float mandatoryScore = 0; byte mandatoryIndex = 0; var belief = BeliefsModel.GetBeliefFromKnowledgeId(knowledgeId); var actorBelief = BeliefsModel.GetActorBelief(knowledgeId); MurphyIncompleteBelief.CheckRiskAversion(belief, taskBits, actorBelief, ref mandatoryScore, ref mandatoryIndex, -Cognitive.InternalCharacteristics.RiskAversionValue()); if (!(mandatoryScore <= -Cognitive.InternalCharacteristics.RiskAversionValue())) { return; } var murphy = Environment.MainOrganization.Murphies.IncompleteBelief; // Prevent the agent from acting on a particular belief if (murphy.ShouldGuess((byte)task.HasBeenCancelledBy.Count)) { // to avoid complete blocking, we allow the agent, depending on the Murphies.IncompleteBelief parameters // to unblock the task var blocker = task.Add(Murphy.IncompleteBelief, Schedule.Step, knowledgeId, mandatoryIndex); RecoverBlockerIncompleteBeliefByGuessing(task, blocker); } else { // Agent can cancel the task a certain number of times TaskProcessor.Cancel(task); } }
/// <summary> /// Check Task.KnowledgesBits for a specific KnowledgeBit against WorkerAgent.expertise /// If Has expertise Task will be complete /// If has expertise for mandatoryKnowledgesBits but not for requiredKnowledgesBits, he will guess, and possibly /// complete the task incorrectly /// If hasn't expertise for mandatoryKnowledgesBits && for requiredKnowledgesBits, he will ask for help (co workers, /// internet forum, ...) && learn /// </summary> /// <param name="task"></param> /// <param name="knowledgeId"></param> protected virtual void CheckBlockerIncompleteKnowledge(SymuTask task, IAgentId knowledgeId) { if (task == null) { throw new ArgumentNullException(nameof(task)); } if (!Environment.MainOrganization.Murphies.IncompleteKnowledge.On || Math.Abs(task.WorkToDo) < Tolerance || // Task is done !task.IsAssigned) { return; } var taskBits = task.KnowledgesBits.GetBits(knowledgeId); // If taskBits.Mandatory.Any => mandatoryCheck is false unless workerKnowledge has the good knowledge or there is no mandatory knowledge var mandatoryOk = taskBits.GetMandatory().Length == 0; // If taskBits.Required.Any => RequiredCheck is false unless workerKnowledge has the good knowledge or there is no required knowledge var requiredOk = taskBits.GetRequired().Length == 0; byte mandatoryIndex = 0; byte requiredIndex = 0; Environment.MainOrganization.Murphies.IncompleteKnowledge.CheckKnowledge(knowledgeId, taskBits, KnowledgeModel, ref mandatoryOk, ref requiredOk, ref mandatoryIndex, ref requiredIndex, Schedule.Step); if (!mandatoryOk) { // mandatoryCheck is false => Task is blocked var blocker = task.Add(Murphy.IncompleteKnowledge, Schedule.Step, knowledgeId, mandatoryIndex); TryRecoverBlockerIncompleteKnowledge(task, blocker); } else if (!requiredOk) { RecoverBlockerIncompleteKnowledgeByGuessing(task, null, knowledgeId, requiredIndex, BlockerResolution.Guessing); } }
public void IsBlockedTest() { Assert.IsFalse(_task.IsBlocked); _task.Add(1, 0); Assert.IsTrue(_task.IsBlocked); }