/// <summary>
        ///   Checks if the given station can satisfy all the demanded capabilities.
        /// </summary>
        /// <param name="recipe">The recipe for which a path is searched.</param>
        /// <param name="path">The current path.</param>
        /// <param name="prefixLength">The length of the path prefix that should be considered valid.</param>
        /// <param name="station">The station which should be next on the path.</param>
        /// <returns>True if choosing station as next path entry would not exceed its capabilities.</returns>
        private bool CanSatisfyNext(Recipe recipe, int[] path, int prefixLength, int station)
        {
            var capabilities = from index in Enumerable.Range(0, prefixLength + 1)
                               where index == prefixLength || path[index] == station
                               select recipe.RequiredCapabilities[index];

            return(Capability.IsSatisfiable(capabilities.ToArray(), _availableStations[station].AvailableCapabilities));
        }
Beispiel #2
0
        /// <summary>
        ///   Checks if all required capabilities are available and
        ///   the output station is alive, and reconfigures recipes
        ///   for which this is not the case.
        /// </summary>
        protected void CheckConfigurationConsistency()
        {
            var inconsistentRecipes = (from role in AllocatedRoles
                                       where !Capability.IsSatisfiable(role.CapabilitiesToApply.ToArray(), AvailableCapabilities) ||
                                       !(role.PostCondition.Port?.IsAlive ?? true)
                                       select role.Recipe)
                                      .Distinct()
                                      // in an array, as AllocatedRoles may be modified by reconfiguration below
                                      .ToArray();

            if (inconsistentRecipes.Length > 0)
            {
                ObserverController.Configure(inconsistentRecipes);
            }
        }
        /// <summary>
        ///   Finds a sequence of connected stations that are able to fulfill the
        ///   <param name="recipe" />
        ///   's capabilities.
        /// </summary>
        /// <returns>
        ///   An array of station identifiers, one for each capability. This array does not include stations
        ///   that only transport a resource from one to the next.
        /// </returns>
        private int[] FindStationPath(Recipe recipe)
        {
            var path = new int[recipe.RequiredCapabilities.Length];

            for (var first = 0; first < _availableStations.Length; ++first)
            {
                if (Capability.IsSatisfiable(new[] { recipe.RequiredCapabilities[0] }, _availableStations[first].AvailableCapabilities))
                {
                    path[0] = first;
                    if (FindStationPath(recipe, path, 1))
                    {
                        return(path);
                    }
                }
            }

            return(null);
        }