예제 #1
0
		public static Model NoRedundancyCircularModel()
		{
			// create 3 stations
			var dispenser = new ParticulateDispenser();
			var stations = new Station[]
			{
				new ContainerLoader(),
				dispenser,
				new PalletisationStation()
			};

			dispenser.SetStoredAmount(IngredientType.BlueParticulate, 50u);
			dispenser.SetStoredAmount(IngredientType.RedParticulate, 50u);
			dispenser.SetStoredAmount(IngredientType.YellowParticulate, 50u);

			// connect them to a circle
			for (var i = 0; i < stations.Length; ++i)
			{
				var next = stations[(i + 1) % stations.Length];
				stations[i].Outputs.Add(next);
				next.Inputs.Add(stations[i]);
			}

			var model = new Model(stations, new FastObserverController(stations));

			var recipe = new Recipe(ingredients: new[]
			{
				new Ingredient(IngredientType.BlueParticulate, 12),
				new Ingredient(IngredientType.RedParticulate, 4),
				new Ingredient(IngredientType.YellowParticulate, 5)
			}, amount: 3);
			model.ScheduleProduction(recipe);

			return model;
		}
예제 #2
0
		public Model(Station[] stations, ObserverController obsContr)
		{
			Stations = stations;
			foreach (var station in stations)
			{
				station.ObserverController = obsContr;
			}
			ObserverController = obsContr;
		}
예제 #3
0
		protected Role? ChooseRole(Station source, Condition condition)
		{
			foreach (var role in AllocatedRoles)
			{
				// there should be at most one such role
				if (role.PreCondition.Matches(condition) && role.PreCondition.Port == source)
					return role;
			}
			return null;
		}
예제 #4
0
			public ResourceRequest(Station source, Condition condition)
			{
				Source = source;
				Condition = condition;
			}
예제 #5
0
		/// <summary>
		///   Informs the station a container is available.
		/// </summary>
		/// <param name="source">The station currently holding the container.</param>
		/// <param name="condition">The container's current condition.</param>
		public void ResourceReady(Station source, Condition condition)
		{
			var request = new ResourceRequest(source, condition);
			if (!_resourceRequests.Contains(request))
				_resourceRequests.Add(request);
		}
예제 #6
0
		/// <summary>
		///   Get a fresh role from the <see cref="RolePool" />.
		/// </summary>
		/// <param name="recipe">The recipe the role will belong to.</param>
		/// <param name="input">The station the role declares as input port. May be null.</param>
		/// <param name="previous">The previous condition (postcondition of the previous role). May be null.</param>
		/// <returns>A <see cref="Role" /> instance with the given data.</returns>
		protected Role GetRole(Recipe recipe, Station input, Condition? previous)
		{
			var role = new Role();

			// update precondition
			role.PreCondition.Recipe = recipe;
			role.PreCondition.Port = input;
			role.PreCondition.ResetState();
			if (previous != null)
				role.PreCondition.CopyStateFrom(previous.Value);

			// update postcondition
			role.PostCondition.Recipe = recipe;
			role.PostCondition.Port = null;
			role.PostCondition.ResetState();
			role.PostCondition.CopyStateFrom(role.PreCondition);

			role.ResetCapabilitiesToApply();

			return role;
		}
예제 #7
0
		private void Connect(Station input, Station output)
		{
			input.Outputs.Add(output);
			output.Inputs.Add(input);
		}