public int CompareTo(object obj) { Etat other = obj as Etat; if (other == null) { return(-1); } return(borneInf.CompareTo(other.borneInf)); }
static void MeilleurDAbord(List <int> visited, List <int> toVisit) { List <Etat> etats = new List <Etat>(); etats.Add(new Etat(0, visited, toVisit)); while (etats.Count > 0) { Etat current = etats[0]; //Console.WriteLine($"\nStudying path {PathToString(current.alreadyVisited)}"); etats.RemoveAt(0); if (current.borneInf > pccCost) { //Console.WriteLine($"Exiting as path {PathToString(current.alreadyVisited)} has a cost of {current.borneInf}"); break; } int previous = current.alreadyVisited[current.alreadyVisited.Count - 1]; foreach (int i in current.notVisited) { List <int> alreadyVisited = new List <int>(current.alreadyVisited); alreadyVisited.Add(i); List <int> notVisited = new List <int>(current.notVisited); notVisited.Remove(i); //Console.WriteLine($"Studying {PathToString(alreadyVisited)} - {PathToString(notVisited)}"); int borneInf = GetPathLength(alreadyVisited); borneInf += Bound(alreadyVisited[alreadyVisited.Count - 1], notVisited); if (notVisited.Count == 0) { //Console.WriteLine($"\nEnded path found : {PathToString(alreadyVisited)} with a cost of {borneInf} - pccCost is {pccCost}"); if (borneInf < pccCost) { pcc = alreadyVisited; pccCost = borneInf; //Console.WriteLine($"\nBetter path found : {PathToString(pcc)}"); } } else { etats.Add(new Etat(borneInf, alreadyVisited, notVisited)); } } etats.Sort(); } }