public bool RemoveAgent(Guid agentId) { if (Agents.All(r => r.Id != agentId)) { return(false); } Agents.RemoveAll(r => r.Id == agentId); return(true); }
protected override void Reconfigure() { var isReconfPossible = IsReconfPossible(_availableRobots, Tasks); if (!isReconfPossible) { OracleState = ReconfStates.Failed; } else if (OracleState != ReconfStates.Failed) { OracleState = ReconfStates.Succedded; } // find optimal path that satisfies the required capabilities CalculateShortestPaths(); var path = FindPath(Tasks[0]); var roles = path == null ? null : Convert(Tasks[0], path).ToArray(); #if ENABLE_F5 var length = roles?.Sum(role => Math.Max(role.Item2.Length, 1)); if (roles == null || length > 2 * Tasks[0].Capabilities.Length) #else if (roles == null) #endif { if (isReconfPossible) { throw new Exception("Reconfiguration failed even though there is a solution."); } ReconfigurationState = ReconfStates.Failed; } else { ApplyConfiguration(roles); if (!isReconfPossible) { throw new Exception("Reconfiguration successful even though there is no valid configuration."); } if (ReconfigurationState != ReconfStates.Failed) { ReconfigurationState = ReconfStates.Succedded; } } // validate invariant if (!Agents.All(agent => agent.ValidateConstraints())) { throw new Exception("Reconfiguration violated constraints"); } }