TabuSearchAlgorithm.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Collections.Generic;
  2. namespace MetaheuristicsPCL
  3. {
  4. public abstract class TabuSearchAlgorithm : Algorithm
  5. {
  6. protected ISolution currentSolution;
  7. protected ISolution bestSoFarSolution;
  8. public override sealed void Solve(IProblem _pb, IHM _ihm)
  9. {
  10. base.Solve(_pb, _ihm);
  11. currentSolution = pb.RandomSolution();
  12. bestSoFarSolution = currentSolution;
  13. AddToTabuList(currentSolution);
  14. while (!Done())
  15. {
  16. List<ISolution> Neighbours = pb.Neighbourhood(currentSolution);
  17. if (Neighbours != null)
  18. {
  19. Neighbours = RemoveSolutionsInTabuList(Neighbours);
  20. ISolution bestSolution = pb.BestSolution(Neighbours);
  21. if (bestSolution != null)
  22. {
  23. UpdateSolution(bestSolution);
  24. }
  25. }
  26. Increment();
  27. }
  28. SendResult();
  29. }
  30. protected abstract void AddToTabuList(ISolution currentSolution);
  31. protected abstract List<ISolution> RemoveSolutionsInTabuList(List<ISolution> Neighbours);
  32. protected abstract bool Done();
  33. protected abstract void UpdateSolution(ISolution _bestSolution);
  34. protected abstract void Increment();
  35. }
  36. }