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; }
public Model(Station[] stations, ObserverController obsContr) { Stations = stations; foreach (var station in stations) { station.ObserverController = obsContr; } ObserverController = obsContr; }
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; }
public ResourceRequest(Station source, Condition condition) { Source = source; Condition = condition; }
/// <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); }
/// <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; }
private void Connect(Station input, Station output) { input.Outputs.Add(output); output.Inputs.Add(input); }