| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System.Collections.Generic;
- namespace MetaheuristicsPCL
- {
- public abstract class TabuSearchAlgorithm : Algorithm
- {
- protected ISolution currentSolution;
- protected ISolution bestSoFarSolution;
- public override sealed void Solve(IProblem _pb, IHM _ihm)
- {
- base.Solve(_pb, _ihm);
- currentSolution = pb.RandomSolution();
- bestSoFarSolution = currentSolution;
- AddToTabuList(currentSolution);
- while (!Done())
- {
- List<ISolution> Neighbours = pb.Neighbourhood(currentSolution);
- if (Neighbours != null)
- {
- Neighbours = RemoveSolutionsInTabuList(Neighbours);
- ISolution bestSolution = pb.BestSolution(Neighbours);
- if (bestSolution != null)
- {
- UpdateSolution(bestSolution);
- }
- }
- Increment();
- }
- SendResult();
- }
- protected abstract void AddToTabuList(ISolution currentSolution);
- protected abstract List<ISolution> RemoveSolutionsInTabuList(List<ISolution> Neighbours);
- protected abstract bool Done();
- protected abstract void UpdateSolution(ISolution _bestSolution);
- protected abstract void Increment();
- }
- }
|