J'ai un code qui lit les éléments dans un fichier texte. Il les lit ligne par ligne. Lorsqu'un élément est lu, il sera ajouté à une liste qui l'empêchera de revenir à nouveau. Lorsque la liste est pleine (taille maximale), elle sera effacée. Cependant, il est nécessaire de vérifier les éléments ajoutés à la liste afin d'éviter de re-visiter cet élément spécifique pour une valeur prédéfinie même si la liste a été effacée.Rechercher les éléments visités dans le fichier texte
S'il vous plaît aidez-moi à comprendre comment faire en 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;
}
}
Merci
essayer google .. mot-clé lecteur de flux .. liste ajouter .. – matzone
merci u ... J'ai utilisé une liste mais j'ai besoin d'un compteur pour vérifier combien d'articles par ex. Dépôt (1). Dépôt (2). Dépôt (3). Dépôt (1). Dépôt (4), je veux éviter de visiter Dépôt (1) avant Dépôt (4) –
ajouter le code à la question .. j'espère peut vous aider (en fait je suis sur VB mais je vais essayer de ..) – matzone