Je voudrais que tu modifies cet algorithme afin qu'il attribué des tables en fonction de…
- User
Je voudrais que tu modifies cet algorithme afin qu'il attribué des tables en fonction de la couleur du sommet using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using TavernManagerMetier.Metier.Algorithmes; using TavernManagerMetier.Metier.Algorithmes.Graphes; using TavernManagerMetier.Metier.Tavernes;
namespace TavernManagerMetier.Metier.Algorithmes.Realisations { public class AlgorithmeColorationCroissante : IAlgorithme { public string Nom => "ColorationCroissante";
private long tempsExecution = -1; public long TempsExecution => tempsExecution; public static class ColorationCroissante { public static Dictionary<Sommet, int> Colorier(Graphe graphe) { Dictionary<Sommet, int> couleurDict = new Dictionary<Sommet, int>(); foreach (Sommet sommet in graphe.Sommets) { int couleur = 1; while (CouleurInvalide(sommet, couleurDict, couleur)) { couleur++; } couleurDict[sommet] = couleur; } return couleurDict; } private static bool CouleurInvalide(Sommet sommet, Dictionary<Sommet, int> couleurDict, int couleur) { foreach (Sommet voisin in sommet.Voisins) { if (couleurDict.TryGetValue(voisin, out int voisinCouleur) && voisinCouleur == couleur) { return true; } } return false; } } public void Executer(Taverne taverne) { Stopwatch sw = new Stopwatch(); sw.Start(); // Créer une instance de la classe Graphe Graphe graphe = new Graphe(taverne); // Colorer le graphe en utilisant l'heuristique de coloration croissante Dictionary<Sommet, int> couleurDict = ColorationCroissante.Colorier(graphe); // Afficher les couleurs attribuées à chaque sommet foreach (var kvp in couleurDict) { Sommet sommet = kvp.Key; int couleur = kvp.Value; Console.WriteLine($"Sommet {sommet} - Couleur {couleur}"); } sw.Stop(); tempsExecution = sw.ElapsedMilliseconds; } }}
Voici des classes qui peuvent t'aider, la classe Taverne using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using TavernManagerMetier.Exceptions.Realisations.GestionTaverne;
namespace TavernManagerMetier.Metier.Tavernes {
public class Taverne { /// <summary> /// Liste des clients de la taverne /// </summary> public Client[] Clients => clients.ToArray(); private List<Client> clients; /// <summary> /// Liste des tables de la taverne /// </summary> public Table[] Tables => tables.ToArray(); private List<Table> tables; //Capacite des tables public int CapactieTables => capaciteTables; private int capaciteTables; /// <summary> /// Nombre de table de la taverne /// </summary> public int NombreTables => tables.Count; /// <summary> /// Constructeur d'une taverne vide avec des tables /// </summary> /// <param name="capaciteTable">Capacité des tables de la taverne</param> public Taverne(int capaciteTable, List<Client> listeClients) { this.clients = listeClients; this.capaciteTables = capaciteTable; this.tables = new List<Table>(); } /// <summary> /// Ajoute une nouvelle table /// </summary> public void AjouterTable() { this.tables.Add(new Table(this.capaciteTables,this.tables.Count)); } /// <summary> /// Ajoute un client à une table /// </summary> /// <param name="numeroClient">Numéro du client</param> /// <param name="numeroTable">Numéro de la table</param> /// <exception cref="ExceptionNumeroClientInconnu">Levée si le client n'existe pas</exception> /// <exception cref="ExceptionNumeroTableInconnu">Levée si la table n'existe pas</exception> public void AjouterClientTable(int numeroClient, int numeroTable) { //On lève une exception si le numéro client n'a pas de sens if (numeroClient < 0 || numeroClient > this.clients.Count || this.clients[numeroClient] == null) throw new ExceptionNumeroClientInconnu(numeroClient); //On lève une exception si le numéro de table n'a pas de sens if (numeroTable < 0 || numeroTable > this.tables.Count || this.tables[numeroTable] == null) throw new ExceptionNumeroTableInconnu(numeroTable); //On change le client de table this.clients[numeroClient].ChangerTable(this.tables[numeroTable]); } } - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.