public virtual void OnReconfigured() { // For now, the resource disappears magically... Resource = null; _currentRole = default(Role); _hasRole = false; _requests.Clear(); _stateMachine.ChangeState(State.Idle); // Todo: This is a bit of a hack }
protected override void OnRoleChosen(Role role) { // If we fail to move to the robot, the cart loses its route if (Cart.MoveTo(((RobotAgent)role.PreCondition.Port).Robot)) return; // ODP inconsistency: We shouldn't be doing this in all cases; for example, // the cart might have the connections R0->R1 and R1->R2. If // R0->R1 breaks, R1 would no longer be in its inputs and // outputs, which is obviously wrong Disconnect(this, role.PreCondition.Port); Disconnect(role.PreCondition.Port, this); CheckConstraints(); }
private bool PostMatching(Role role, Agent agent) { if (role.PostCondition.Port.AllocatedRoles.All(role1 => role1.PreCondition.Port != agent)) { ; } else if ( !role.PostCondition.Port.AllocatedRoles.Any( role1 => role.PostCondition.StateMatches(role1.PreCondition.State))) { ; } else if (role.PostCondition.Port.AllocatedRoles.All(role1 => role.PostCondition.Task != role1.PreCondition.Task)) { ; } return role.PostCondition.Port.AllocatedRoles.Any(role1 => role1.PreCondition.Port == agent && role.PostCondition.StateMatches(role1.PreCondition.State) && role.PostCondition.Task == role1.PreCondition.Task); }
/// <summary> /// Applies the <paramref name="roleAllocations" /> to the system. /// </summary> /// <param name="roleAllocations">The sequence of agents and the capabilities they should execute.</param> protected virtual void ApplyConfiguration(Tuple<Agent, Capability[]>[] roleAllocations) { foreach (var task in Tasks) task.IsResourceInProduction = false; _lastRoleAllocations = roleAllocations; var allocatedCapabilities = 0; for (var i = 0; i < roleAllocations.Length; i++) { var agent = roleAllocations[i].Item1; var capabilities = roleAllocations[i].Item2; var preAgent = i == 0 ? null : roleAllocations[i - 1].Item1; var postAgent = i == roleAllocations.Length - 1 ? null : roleAllocations[i + 1].Item1; var preCondition = new Condition(Tasks[0], preAgent, allocatedCapabilities); var postCondition = new Condition(Tasks[0], postAgent, allocatedCapabilities + capabilities.Length); var role = new Role(preCondition, postCondition, allocatedCapabilities, capabilities.Length); allocatedCapabilities += capabilities.Length; agent.Configure(role); } }
private bool PreMatching(Role role, Agent agent) { return role.PreCondition.Port.AllocatedRoles.Any(role1 => role1.PostCondition.Port == agent && role.PreCondition.StateMatches(role1.PostCondition.State) && role.PreCondition.Task == role1.PostCondition.Task); }
public override void Configure(Role role) { }
public virtual void Configure(Role role) { AllocatedRoles.Add(role); }
protected bool TryChooseRole(Func<Role, bool> predicate, out Role role) { foreach (var allocatedRole in AllocatedRoles) { if (predicate(allocatedRole)) { role = allocatedRole; return true; } } role = default(Role); return false; }
protected virtual void OnRoleChosen(Role role) { }