예제 #1
0
        /// <summary>
        /// Clear the Population and SeedGenres entries
        /// </summary>
        public void Clear()
        {
            foreach (Population population in Populations)
            {
                GenrePopulations.RemovePopulation(population.SeedPopulation);
            }

            if (SeedGenres != null)
            {
                GenrePopulations.RemovePopulation(SeedGenres);
                SeedGenres = null;
            }

            Populations.Clear();
            GenresAlreadyIncluded.Clear();
            AlbumsAlreadyIncluded.Clear();
        }
예제 #2
0
        /// <summary>
        /// Find all the albums associated with a list of genre names
        /// </summary>
        /// <param name="genres"></param>
        /// <returns></returns>
        private List <Album> GetAlbumsFromGenres(IEnumerable <string> genres)
        {
            List <Album> albums = new List <Album>();

            // Get all the albums associated with the genres
            foreach (string genre in genres)
            {
                Tag genreTag = FilterManagementModel.GenreTags.Tags.SingleOrDefault(tag => tag.Name == genre);
                if (genreTag != null)
                {
                    albums.AddRange(FilterManagementModel.GenreTags.Tags.Single(tag => tag.Name == genre).TaggedAlbums
                                    .Where(alb => AlbumsAlreadyIncluded.Add(alb.AlbumId) == true).Select(ta => ta.Album));
                }
                else
                {
                }
            }

            return(albums);
        }
예제 #3
0
        /// <summary>
        /// Form the initial population from all the genres and albums that can be reached from the specified initial set of genres
        /// </summary>
        /// <param name="startingGenres"></param>
        public void AddAllReachableGenres(IEnumerable <string> startingGenres)
        {
            List <string> newGenres      = null;
            List <Album>  newAlbums      = null;
            int           expansionCount = 0;

            // Start with the initial genres
            List <string> currentGenres = startingGenres.ToList();

            do
            {
                // Are there any genres that have not been seen before
                newGenres = currentGenres.Where(gen => GenresAlreadyIncluded.Add(gen) == true).ToList();
                if (newGenres.Count > 0)
                {
                    // Are there any albums associated with these genres that have not been seen before
                    newAlbums = GetAlbumsFromGenres(newGenres);
                    if (newAlbums.Count > 0)
                    {
                        // Get all the genres associated with these new albums
                        currentGenres = newAlbums.SelectMany(alb => alb.Genre.Split(';')).ToList();
                    }
                }
            }while ((newGenres.Count > 0) && (newAlbums.Count > 0) && ((FastSpreadLimit == 0) || (++expansionCount < FastSpreadLimit)));

            // Unload the genres and albums from the HashSets and use to generate the first population
            Populations.Add(new Population(GenrePopulations.CreatePopulation(Id, Populations.Count, GenresAlreadyIncluded.ToList()),
                                           GenresAlreadyIncluded.ToList(), Albums.AlbumCollection.Where(alb => AlbumsAlreadyIncluded.Contains(alb.Id))));
        }