示例#1
0
 public static Boolean TestConnexite(Graphe graphe)
 {
     ParcoursLargeur(graphe);
     if (VerifierMarquage(graphe.listeSommet))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#2
0
        public void DessinerGraphe(Graphe graphe)
        {
            graphics.Clear(Color.White);
            foreach (Sommet som in graphe.listeSommet)
            {
                if (som.Position.HasValue)
                {
                    Color couleur;
                    if (som.Marque == EnumMarque.NonMarque)
                    {
                        couleur = Color.Black;
                    }
                    else
                    {
                        couleur = Color.Red;
                    }

                    Point     pos  = new Point(som.Position.Value.X * (this.Width - 20) / 1000, som.Position.Value.Y * (this.Height - 20) / 1000);
                    Rectangle rect = new Rectangle(pos, new Size(5, 5));
                    graphics.FillEllipse(new SolidBrush(couleur), rect);
                    graphics.DrawString(som.Libelle, new Font("Arial", 16), new SolidBrush(couleur), new PointF(pos.X + 10, pos.Y + 10));
                }
            }
            foreach (Arete ar in graphe.listeArete)
            {
                Pen couleur;
                if (!ar.Marque)
                {
                    couleur = new Pen(Color.Black);
                }
                else
                {
                    couleur = new Pen(Color.Black);
                }

                Point posA = new Point(ar.Destination.Position.Value.X * (this.Width - 20) / 1000, ar.Destination.Position.Value.Y * (this.Height - 20) / 1000);
                Point posB = new Point(ar.Origine.Position.Value.X * (this.Width - 20) / 1000, ar.Origine.Position.Value.Y * (this.Height - 20) / 1000);
                graphics.DrawLine(couleur, posA, posB);
            }
        }
示例#3
0
        private static void ParcoursLargeur(Graphe graphe)
        {
            List <Sommet> sommetsOuverts = new List <Sommet>()
            {
                graphe.listeSommet[0]
            };
            List <Sommet> sommetsAdjacents       = new List <Sommet>();
            List <Sommet> sommetsAdjacentAjouter = new List <Sommet>();

            graphe.listeSommet[0].Marque = EnumMarque.Ouvert;
            while (sommetsOuverts.Count > 0)
            {
                sommetsAdjacents = graphe.ObtenirSommetsAdjacents(sommetsOuverts[0]);
                foreach (var sommetAdjacent in sommetsAdjacents)
                {
                    graphe.listeSommet.Where(t => t == sommetAdjacent).First().Marque = EnumMarque.Ouvert;
                    sommetsOuverts.Add(sommetAdjacent);
                }
                graphe.listeSommet.Where(t => t == sommetsOuverts[0]).First().Marque = EnumMarque.Ferme;
                sommetsOuverts.Remove(sommetsOuverts[0]);
            }
        }
示例#4
0
        private void btGenerer_Click(object sender, EventArgs e)
        {
            graphe = new Graphe();
            uC_Graphe.Effacer();
            if (tbSommets.Value > 0)
            {
                ListeAttenteSommet = new List <Sommet>();
                listeAretes        = new List <Arete>();

                for (int i = 0; i < dgvMatrice.ColumnCount; i++)
                {
                    string nomSommet = dgvMatrice.Columns[i].Name;
                    ListeAttenteSommet.Add(new Sommet(nomSommet));
                    graphe.listeSommet.Add(new Sommet(nomSommet));
                }

                EcrireInstruction(ListeAttenteSommet.First());
                ArreterEcriture(true);
            }
            else
            {
                MessageBox.Show("Veuillez entrer un nombre de sommets supérieur à 0");
            }

            #region AncienFonctionnement
            //int fact = Fonctions.CalculAretes((int)tbSommets.Value - 1);
            //if (cbConnexe.Checked && tbAretes.Value > Fonctions.CalculAretes((int)tbSommets.Value - 1))
            //    MessageBox.Show("Le nombre d'arêtes choisies est trop grand, veuillez modifier le nombre d'arêtes.");
            //else if (cbConnexe.Checked && tbAretes.Value < tbSommets.Value - 1)
            //    MessageBox.Show("Le nombre d'arêtes choisies est trop petit, veuillez modifier le nombre d'arêtes.");
            //else if (!cbConnexe.Checked && tbAretes.Value > Fonctions.CalculAretes((int)tbSommets.Value - 2))
            //    MessageBox.Show("Le nombre d'arêtes choisies est trop grand, veuillez modifier le nombre d'arêtes.");
            //else
            //{
            //    graphe = new Graphe((int)tbSommets.Value, (int)tbAretes.Value, cbConnexe.Checked);
            //    uC_Graphe.DessinerGraphe(graphe);
            //}
            #endregion
        }
示例#5
0
        public static List <Sommet> SommetArticulation(Graphe graphe)
        {
            int           previsite;
            List <Sommet> pileSommets             = new List <Sommet>();
            List <Sommet> listeSommetArticulation = new List <Sommet>();
            List <Arete>  ensembleArcs            = new List <Arete>();
            List <Arete>  listeAretes             = graphe.listeArete;
            List <Sommet> listeSommets            = graphe.listeSommet.Where(t => t.Marque == EnumMarque.NonMarque).ToList();

            while (!VerifierMarquage(listeSommets))
            {
                previsite              = 1;
                listeSommets           = listeSommets.Where(t => t.Marque == EnumMarque.NonMarque).ToList();
                listeSommets[0].Marque = EnumMarque.Ouvert;
                pileSommets.Add(graphe.listeSommet[0]);
                listeSommets[0].Previsite = previsite;
                listeSommets[0].Hauteur   = previsite;
                previsite++;
                while (pileSommets.Count > 0)
                {
                    if (ExisteSommetAdjacent(pileSommets.Last(), listeSommets, listeAretes))
                    {
                        Sommet y = ObtenirSommetsAdjacents(pileSommets.Last(), listeSommets, listeAretes).First();
                        listeSommets.First(t => t == y).Marque = EnumMarque.Ouvert;
                        ensembleArcs.Add(new Arete(pileSommets.Last(), y));
                        pileSommets.Add(listeSommets.First(t => t == y));
                        //ensembleArcs.Add(listeAretes.First(t => t.Destination == y && t.Origine == pileSommets.Last()
                        //   || t.Destination == pileSommets.Last() && t.Origine == y));
                        listeSommets.First(t => t == y).Previsite = previsite;
                        previsite++;
                        listeSommets.First(t => t == y).Hauteur = listeSommets.First(t => t == y).Previsite;
                    }
                    else
                    {
                        listeSommets.First(t => t == pileSommets.Last()).Marque = EnumMarque.Ferme;

                        List <Sommet> listeSommetSuccesseur = ObtenirSommetsAdjacents(pileSommets.Last(), listeSommets, listeAretes, false);
                        List <Sommet> SommetsASupprimer     = new List <Sommet>();
                        foreach (Sommet item in listeSommetSuccesseur)
                        {
                            if (RechercherArc(item, pileSommets.Last(), ensembleArcs))
                            {
                                SommetsASupprimer.Add(item);
                            }
                        }

                        foreach (Sommet item in SommetsASupprimer)
                        {
                            listeSommetSuccesseur.Remove(item);
                        }

                        foreach (Sommet successeur in listeSommetSuccesseur)
                        {
                            listeSommets.First(t => t == pileSommets.Last()).Hauteur = (listeSommets.First(t => t == pileSommets.Last()).Hauteur < successeur.Hauteur) ? listeSommets.First(t => t == pileSommets.Last()).Hauteur : successeur.Hauteur;
                        }
                        pileSommets.Remove(pileSommets.Last());
                    }
                }
                if (ObtenirSommetsAdjacents(listeSommets[0], listeSommets, ensembleArcs, false).Count >= 2)
                {
                    listeSommetArticulation.Add(listeSommets[0]);
                }
                foreach (Sommet x in listeSommets)
                {
                    if (listeSommets.Count > 0 && Different(x, listeSommets[0]))
                    {
                        List <Arete> listeArcSuccesseur = RechercherArcsOrigine(x, ensembleArcs);
                        foreach (Arete y in listeArcSuccesseur)
                        {
                            if (y.Destination.Hauteur >= x.Previsite)
                            {
                                listeSommetArticulation.Add(x);
                            }
                        }
                    }
                }
            }

            return(listeSommetArticulation);
        }