SimulatedAnnealingAlgorithm.cs 1.2 KB

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