Problème pour trouver un circuit dans une martice booleenne
marc_dd
Messages postés61Date d'inscriptiondimanche 30 octobre 2005StatutMembreDernière intervention 2 juillet 2009
-
10 août 2006 à 16:17
marc_dd
Messages postés61Date d'inscriptiondimanche 30 octobre 2005StatutMembreDernière intervention 2 juillet 2009
-
11 août 2006 à 11:06
Bonjour à tous,
Pour mon cours de math je dois faire une application sur des graphes, j'ai presque fini mais il me reste un problème je cherche un algorithme me permettant d'afficher tous les circuits qui se trouvent dans le graphe à partir de sa matrice booléenne.
J'ai cherché sur le net mais je n'ai pas trouvé, j'ai déja essayé plusieurs choses mais ca ne marche pas
Quelqu'un pourrait-il m'aider
cs_DARKSIDIOUS
Messages postés15814Date d'inscriptionjeudi 8 août 2002StatutMembreDernière intervention 4 mars 2013130 10 août 2006 à 16:51
Je présume que ta matrice représente les arêtes de ton graphes : un 1 si tu peux aller du sommet (colonne de ta matrice) jusqu'au sommet (ligne de ta matrice).
Fait une fonction récursive qui part d'un sommet et qui avance d'un sommet à chaque appel par exemple.
marc_dd
Messages postés61Date d'inscriptiondimanche 30 octobre 2005StatutMembreDernière intervention 2 juillet 2009 10 août 2006 à 17:48
Voilà mes 2 methode, je dois surement m'être embrouiller pas mal ca fait toute la journée que je suis sur les chemins et les circuits
1ere methode
public int Circuit ()
{
tmpcirc = new String [100];
arcirc = new ArrayList();
int n = 0;
Demarqué();
for (int a=0;a<count;a++)
{
if(matbool[0][a]==1 && a!=0)
n+=profcirc(0,a);
Demarqué();
arcirc.add(lignecircuit);
initcirctmp();
lignecircuit="";
}
Iterator it = arcirc.iterator();
while (it.hasNext())
{
String li = (String)it.next();
System.out.println(li+"\n");
}
return n; //nombre de chemin qu'il y a
}
2eme methode (la recursive)
public int profcirc(int l, int c)
{
int n=0;
int ind=0;
ind = chindice();
tmpcirc[n]= tabsommet[l].getNom();
tabsommet[l].setP(true);
for (int a=0;a<count;a++)
{
if (matbool[c][a]==1 )
{
if (tabsommet[a].getP() && tabsommet[a].getNom()!=tmpcirc[n])
{
int inttmp= chindice();
tmpcirc[inttmp]=tabsommet[a].getNom()+" ";
int indicech=0 ;
for (int i=inttmp;i>=0;i--)
{ if ( tmpcirc[i]==tmpcirc[inttmp])
indicech=i;
}
for (int i=indicech;i<=inttmp;i++)
lignecircuit+=tmpcirc[i]+" ";
return n=1;
}
else if (c!=a) profcirc(c,a);
}
}
return n;
}
voilà
merci d'avance pour votre aide
merci d'avance
Marc
Vous n’avez pas trouvé la réponse que vous recherchez ?
marc_dd
Messages postés61Date d'inscriptiondimanche 30 octobre 2005StatutMembreDernière intervention 2 juillet 2009 11 août 2006 à 11:06
bonjour à tous ,
j'ai réessayer un autre algorithme avec un arrylist temporaire mais marche toujours pas oilà mon code ;
public int Circuit ()
{
tmpcirc = new String [100];
artmp = new ArrayList();
arcirc = new ArrayList();
int n = 0;
Demarqué();
for (int a=0;a<count;a++)
{
if(matbool[0][a]==1 )
n+=profcirc(0,a);
Demarqué();
// if (lignecircuit!="")
//arcirc.add(lignecircuit);
initcirctmp();
lignecircuit="";
}
Iterator it = arcirc.iterator();
while (it.hasNext())
{
String li = (String)it.next();
System.out.println(li+"\n");
}
return n;
}
public int profcirc(int l, int c)
{
int n=0,k=0;
int ind=0;
ind = chindice();Iterator it ;
artmp.add( tabsommet[l].getNom());
tabsommet[l].setP(true);
for (int a=0;a<count;a++)
{
if (matbool[c][a]==1)
{it = artmp.iterator();
while (it.hasNext())
{
n++;
}
if (artmp.indexOf(tabsommet[a].getNom())==n-1)
;
else if (artmp.contains(tabsommet[a].getNom()))
{
int nb = artmp.indexOf(tabsommet[a].getNom());
it = artmp.iterator();
n=0;
while (it.hasNext()){
if (n>=nb){
lignecircuit+=it.next()+" ";