GradientDescentForKnapsack.cs 871 B

123456789101112131415161718192021222324252627282930313233
  1. 
  2. namespace MetaheuristicsPCL
  3. {
  4. public class GradientDescentForKnapsack : GradientDescentAlgorithm
  5. {
  6. int nbIterationsWithoutUpdate = 0;
  7. private const int MAX_ITERATIONS_WITHOUT_UPDATE = 50;
  8. protected override bool Done()
  9. {
  10. return nbIterationsWithoutUpdate >= MAX_ITERATIONS_WITHOUT_UPDATE;
  11. }
  12. protected override void Increment()
  13. {
  14. nbIterationsWithoutUpdate++;
  15. }
  16. protected override void UpdateSolution(ISolution _bestSolution)
  17. {
  18. if (_bestSolution.Value > currentSolution.Value)
  19. {
  20. currentSolution = _bestSolution;
  21. nbIterationsWithoutUpdate = 0;
  22. }
  23. }
  24. protected override void SendResult()
  25. {
  26. ihm.PrintMessage(currentSolution.ToString());
  27. }
  28. }
  29. }