GradientDescentAlgorithm.cs 919 B

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