public FSPSolution GenerateNeighbor(TabuMemory explicitLocalTabuMemory) { var copyCurrentSolution = new FSPSolution(this); var selectedPhrases = copyCurrentSolution.ObtainSelectedPhrasesSortedByCoverageCosine(); // Remove the last sentence (phrases with low coverage) ... C = 1 copyCurrentSolution.InActivate(selectedPhrases[selectedPhrases.Count - 1].Position); var excludePhrases = new List <int> { selectedPhrases[selectedPhrases.Count - 1].Position }; var tries = 0; const int maxTries = 5; FSPSolution newCandidateSolution = null; do { newCandidateSolution = new FSPSolution(copyCurrentSolution); // Try to add one or more randomly selected phrases to complete the solution newCandidateSolution.AddValidPhrases(excludePhrases); if (tries++ < maxTries) { break; // avoid long time in the loop } } while (explicitLocalTabuMemory.IsTabu(newCandidateSolution.SelectedPhrases)); newCandidateSolution.CalculateFitness(); return(newCandidateSolution); }
public List <PositionValue> Execute() { CurrentFFEs = 0; var myParameters = (SFLAParameters)MyParameters; // Setup of Memeplexes Memeplex = new List <Frog> [myParameters.NumberOfMemeplexes]; for (var i = 0; i < myParameters.NumberOfMemeplexes; i++) { Memeplex[i] = new List <Frog>(); } FrogsByMemeplex = myParameters.PondSize / myParameters.NumberOfMemeplexes; // Calculate the ranking of the position of the phrases CalculateRankingPhrasePosition(); // Tabu memory of the specified type is created with the desired amount MyTabuMemory = new TabuMemory(myParameters.Tenure); // Initialize the Pond with frogs Pond = new List <Frog>(); while (Pond.Count < myParameters.PondSize) { var frog = new Frog(this); frog.RandomInitialization(); if (MyTabuMemory.IsTabu(frog.SelectedPhrases)) { continue; } Pond.Add(frog); MyTabuMemory.Include(frog.SelectedPhrases); } Pond.Sort((x, y) => - 1 * x.Fitness.CompareTo(y.Fitness)); GBest = new Frog(Pond[0]); while (CurrentFFEs < MaximumNumberOfFitnessFunctionEvaluations) { ShuffletheFrogs(); LocalSearch(); RegroupTheFrogs(); MutateTheFrogs(); Pond.Sort((x, y) => - 1 * x.Fitness.CompareTo(y.Fitness)); GBest = new Frog(Pond[0]); } var mostRepeated = SelectToCompleteSummary( new List <BaseSolution>(Pond), GBest); var listaFrases = SelectPhrasesFromFinalSummary( GBest.SelectedPhrases, mostRepeated); return(listaFrases); }
public override void Summarize(SummaryParameters mySummaryParameters, string newsDirectory, string cacheFileName) { MyParameters = (SFLAParameters)mySummaryParameters; MyTDM = new TDM(newsDirectory, MyParameters.MyTDMParameters, cacheFileName); MyExternalMDS = new SimilarityMatrix(MyTDM, cacheFileName); SolutionSize = MyTDM.PhrasesList.Count; MyTabuMemory = null; var phrasesList = Execute(); TextSummary = Util.SummarizeByCompressionRatio(MyTDM, phrasesList, mySummaryParameters.MySummaryType, MyParameters.MaximumLengthOfSummaryForRouge, out SummaryByPhrases); }