private void CreateCart(params Route[] routes) { // compute the transitive closure of the routes routes = routes.SelectMany( route => Closure(route.Robot1, robot => { return(routes.Where(r => r.Robot1 == robot).Select(r => r.Robot2)); }) .Select(target => new Route(route.Robot1, target))).ToArray(); // make sure we don't have duplicate routes routes = routes.Distinct(new RouteComparer()).ToArray(); // for efficiency (less faults), remove reflexive routes routes = routes.Where(route => route.Robot1 != route.Robot2).ToArray(); var cart = new Cart(routes[0].Robot1, routes); var agent = new CartAgent(cart); Carts.Add(cart); CartAgents.Add(agent); cart.SetNames(Carts.Count - 1); agent.Name = $"C{Carts.Count - 1}"; agent.ConfigurationUpdateFailed.Name = agent.Name + ".ConfigUpdateFailed"; foreach (var route in routes) { Agent.Connect(from: RobotAgents.Single(a => route.Robot1 == a.Robot), to: agent); Agent.Connect(from: agent, to: RobotAgents.Single(a => route.Robot2 == a.Robot)); #if !ENABLE_F2 // error F2: routes are bidirectional Agent.Connect(from: RobotAgents.Single(a => route.Robot2 == a.Robot), to: agent); Agent.Connect(from: agent, to: RobotAgents.Single(a => route.Robot1 == a.Robot)); #endif } }
private void CreateRobot(params Capability[] capabilities) { var robot = new Robot(capabilities.OfType <ProcessCapability>().ToArray()); var agent = new RobotAgent(capabilities, robot); Robots.Add(robot); RobotAgents.Add(agent); robot.SetNames(Robots.Count - 1); agent.Name = $"R{Robots.Count - 1}"; agent.ConfigurationUpdateFailed.Name = agent.Name + ".ConfigUpdateFailed"; }
public void CreateObserverController <T>() where T : ObserverController { ObserverController = (ObserverController)Activator.CreateInstance(typeof(T), RobotAgents.Cast <Agent>().Concat(CartAgents), Tasks); }