I have a code that reads items in a text file. It reads them line-by-line. When an item is read it will be added to a list that prevents it from revisited again. When the list is full (max size), it will be cleared. However, there is a need to check for the items added to the list in order to prevent re-visiting this specific item for a predefined value even though if the list was cleared.
Please help me to figure out how to do in C# 2012.
namespace SearchTechniques.Algorithms
{
using System;
using System.Collections.Generic;
public abstract class TSBase : SearchTechniquesBase
{
// if Tabu list reaches the size (MaximumTabuListSize), it will be cleared.
private readonly int MaximumTabuListSize = 8;
public TSBase()
{
_tabuList = new List<object>();
}
protected override void RunAlgorithm(List<object> solutions)
{
_solutions = new List<object>();
_tabuList.Clear();
var solution = solutions[0];
solutions.RemoveAt(0);
while (solution != null)
{
_logger.Log("\t" + solution.ToString() + " - considering as next best solution not in tabu list based on cost function\n");
_solutions.Add(solution);
UpdateTabuList(solution);
solution = FindNextBestSolution(solution, solutions);
if (null != solution)
{
solutions.Remove(solution);
}
}
}
// updating tabu list
private void UpdateTabuList(object solution)
{
_tabuList.Add(solution);
if (_tabuList.Count >= MaximumTabuListSize)
{
_logger.Log("clearing tabu list as already reached: " + MaximumTabuListSize.ToString() + "\n");
_tabuList.Clear();
}
}
// finding the next best solution
protected abstract object FindNextBestSolution(object solution, List<object> solutions);
// the _solutions are both the list of current solutions and the tabu list in our case
protected abstract bool SolutionExistsInTabuList(object solution);
protected List<object> _tabuList;
}
}
Thanks