Exemple #1
0
		public static void Connect(Agent from, Agent to)
		{
			if (!from.Outputs.Contains(to))
				from.Outputs.Add(to);

			if (!to.Inputs.Contains(from))
				to.Inputs.Add(from);
		}
Exemple #2
0
		public void Execute(Agent agent)
		{
			if (_current >= _capabilitiesToApplyCount)
				throw new InvalidOperationException("The role has already been completely executed and must be reset.");

			var capability = Task.Capabilities[_capabilitiesToApplyStart + _current++];
			agent.AvailableCapabilities.First(c => c.IsEquivalentTo(capability)).Execute(agent);
		}
Exemple #3
0
		public override void PlaceResource(Agent agent)
		{
			// If we fail to transfer the resource, the robot loses all of its connections
			if (Robot.PlaceResource(((CartAgent)agent).Cart))
				return;

			Robot.DiscardWorkpiece();
			ClearConnections();
			CheckConstraints();
		}
Exemple #4
0
		protected override void OnResourceReady(Agent agent)
		{
			base.OnResourceReady(agent);

			// If we fail to move to the robot, the cart loses its route
			if (Cart.MoveTo(((RobotAgent)agent).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, agent);
			Disconnect(agent, this);
			CheckConstraints();
		}
		private void GenerateConstraints(Agent agent)
		{
			agent.Constraints = new List<Func<bool>>
			{
				// I/O Consistency
				() => agent.AllocatedRoles.All(role => role.PreCondition.Port == null || agent.Inputs.Contains(role.PreCondition.Port)),
				() => agent.AllocatedRoles.All(role => role.PostCondition.Port == null || agent.Outputs.Contains(role.PostCondition.Port)),
				// Capability Consistency
				() =>
					agent.AllocatedRoles.All(
						role => role.CapabilitiesToApply.All(capability => agent.AvailableCapabilities.Any(c => c.IsEquivalentTo(capability)))),
				//   Pre-PostconditionConsistency
				() =>
					agent.AllocatedRoles.Any(role => role.PostCondition.Port == null || role.PreCondition.Port == null) ||
					agent.AllocatedRoles.TrueForAll(role => PostMatching(role, agent) && PreMatching(role, agent))
			};
		}
Exemple #6
0
		protected override bool CheckOutput(Agent agent)
		{
			return Robot.CanTransfer();
		}
Exemple #7
0
		public static void Disconnect(Agent from, Agent to)
		{
			from.Outputs.Remove(to);
			to.Inputs.Remove(from);
		}
		public override void Execute(Agent agent)
		{
			agent.Consume(this);
		}
		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);
		}
Exemple #10
0
		protected virtual void OnResourceReady(Agent agent)
		{
			agent.ResourceReady(this);
		}
Exemple #11
0
		protected virtual bool CheckOutput(Agent agent)
		{
			return true;
		}
Exemple #12
0
		public virtual void PlaceResource(Agent agent)
		{
		}
Exemple #13
0
		public virtual void TakeResource(Agent agent)
		{
		}
Exemple #14
0
		protected override bool CheckOutput(Agent agent)
		{
			return Cart.CanMove(((RobotAgent)agent).Robot);
		}
		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);
		}
Exemple #16
0
		private void TransferResource(Agent agent)
		{
			_stateMachine.Transition(
				from: State.Output,
				to: State.ResourceGiven,
				guard: Resource != null,
				action: () =>
				{
					PlaceResource(agent);
					agent.TakeResource(this);

					agent.Resource = Resource;
					Resource = null;
				});
		}
Exemple #17
0
		private void ResourceReady(Agent otherAgent)
		{
			if (_requests.Count < Model.MaxAgentRequests && !_requests.Contains(otherAgent))
				_requests.Add(otherAgent);
		}
		public override void Execute(Agent agent)
		{
			agent.Process(this);
		}
		public override void Execute(Agent agent)
		{
			agent.Produce(this);
		}