public IMovieList ChooseBest() { var earningsAdjustment = EARNINGS_ADJUSTMENT * 1000000; var maxValue = _baselineMovies.Max(movie => movie.Earnings); var tentPoleMovie = _baselineMovies.First(movie => movie.Earnings == maxValue); _moviePicker.AddMovies(_baselineMovies); var best = _moviePicker.ChooseBest(); TotalComparisons += _moviePicker.TotalComparisons; TotalSubProblems += _moviePicker.TotalSubProblems; while (best.Movies.FirstOrDefault(movie => movie.Id == tentPoleMovie.Id) != null) { maxValue = tentPoleMovie.Earnings; // Keep changing the tentPoleMovie until it is no longer in the list. tentPoleMovie.Earnings -= earningsAdjustment; best = _moviePicker.ChooseBest(); TotalComparisons += _moviePicker.TotalComparisons; TotalSubProblems += _moviePicker.TotalSubProblems; } tentPoleMovie.Earnings = maxValue; return(_moviePicker.ChooseBest()); }
public IMovieList ChooseBest() { int exponent = _baselineMovies.Count(item => item.AdjustEarnings); int toRaise = (int)(EarningsAdjustmentMax / EarningsAdjustment) * 2 + 1; _elapsed.Max = Math.Pow(toRaise, exponent); var movieLists = GenerateMovieLists(new List <IMovie>(), _baselineMovies); _logMessagesCount = 0; TotalMovieLists = movieLists.Count; _elapsed.Current = 0; _elapsed.Max = TotalMovieLists; _elapsed.Start(); // Walk through the movie list adjusting the movies by the variant and then choose the best. foreach (var movieList in movieLists) { _moviePicker.AddMovies(movieList); if (CanLog) { // Only display this progress every LogMessagesMax time LogMovieList($"{nameof(ChooseBest)} - {_logMessagesCount}/{TotalMovieLists} - ", movieList); } _logMessagesCount++; _elapsed.Current = _logMessagesCount; var best = _moviePicker.ChooseBest(); var hashCode = best.GetHashCode(); int value; TotalComparisons += _moviePicker.TotalComparisons; TotalSubProblems += (_moviePicker.TotalSubProblems == 0) ? 1 : _moviePicker.TotalSubProblems; // Increment (or add to) the best list counts if (_bestListCounts.TryGetValue(hashCode, out value)) { _bestListCounts[hashCode] = value + 1; } else { _bestListCounts.Add(hashCode, 1); _bestLists.Add(hashCode, best); } } // Sort through the MOST times a list is counted. var bestHash = _bestListCounts.OrderByDescending(item => item.Value).First().Key; return(_bestLists[bestHash]); }
private IMovieListModel MakePick(bool enableBonus) { var clonedList = CloneList(Movies); _moviePicker.Clear(); _moviePicker.AddMovies(clonedList); if (!enableBonus) { _moviePicker.EnableBestPerformer = enableBonus; } var picks = _moviePicker.ChooseBest(); return(new MovieListModel(enableBonus ? "Bonus ON" : "Bonus OFF", picks)); }
public void AddMovies(IEnumerable <IMovie> movies) { _moviePicker.AddMovies(movies); }