Beispiel #1
0
        private static List<NeuralLink> BuildExternalLinksExisting_Prune(List<NeuralLink> links, ContainerInput[] containers, ContainerInput toContainer)
        {
            List<NeuralLink> retVal = new List<NeuralLink>();

            // Process each from container separately
            foreach (var group in links.GroupBy(o => o.FromContainer))
            {
                ContainerInput fromContainer = containers.Where(o => o.Container == group.Key).First();

                // Find the ratio that talks about this from container
                var ratio = toContainer.ExternalRatios.Where(o => o.Item1 == fromContainer.ContainerType).FirstOrDefault();
                if (ratio == null)
                {
                    // Links aren't allowed between these types of containers
                    continue;
                }

                NeuralLink[] groupLinks = group.ToArray();

                // Figure out how many links are supported
                int maxCount = BuildExternalLinks_Count(ratio.Item2, fromContainer.Container.Neruons_All.Count(), toContainer.Container.Neruons_All.Count(), ratio.Item3);
                if (groupLinks.Length <= maxCount)
                {
                    // No need to prune, keep all of these
                    retVal.AddRange(groupLinks);
                }
                else
                {
                    // Prune
                    var pruned = Prune(groupLinks.Select(o => o.Weight).ToArray(), maxCount);		// get the largest weights, and normalize them
                    retVal.AddRange(pruned.Select(o => new NeuralLink(groupLinks[o.Item1].FromContainer, groupLinks[o.Item1].ToContainer, groupLinks[o.Item1].From, groupLinks[o.Item1].To, o.Item2, groupLinks[o.Item1].BrainChemicalModifiers)));		// copy the referenced links, but use the altered weights
                }
            }

            // Exit Function
            return retVal;
        }
Beispiel #2
0
        /// <summary>
        /// The containers may not be in the same place that the links think they are.  So this method goes through all the container positions
        /// that all the links point to, and figures out which containers are closest to those positions
        /// </summary>
        private static Dictionary<Point3D, ClosestExistingResult[]> BuildExternalLinksExisting_ContainerPoints(ContainerInput[] containers, int maxIntermediateLinks)
        {
            Dictionary<Point3D, ClosestExistingResult[]> retVal = new Dictionary<Point3D, ClosestExistingResult[]>();		// can't use SortedList, because point isn't sortable (probably doesn't have IComparable)

            Point3D[] allPartPoints = containers.Select(o => o.Position).ToArray();

            foreach (ContainerInput container in containers.Where(o => o.ExternalLinks != null && o.ExternalLinks.Length > 0))
            {
                // Get a unique list of referenced parts
                foreach (var exist in container.ExternalLinks)
                {
                    if (!retVal.ContainsKey(exist.FromContainerPosition))
                    {
                        retVal.Add(exist.FromContainerPosition, GetClosestExisting(exist.FromContainerPosition, allPartPoints, maxIntermediateLinks));
                    }
                }
            }

            // Exit Function
            return retVal;
        }