IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MATLAB Discussion :

Algorithme de Ford-Fulkerson


Sujet :

MATLAB

  1. #21
    Candidat au Club
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Février 2012
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Février 2012
    Messages : 18
    Points : 2
    Points
    2
    Par défaut
    Voilà le code de la fonction:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    %WHITE =0;
    %GRAY=1;
    %BLACK=2
     
    function augmentpath=bfs_augmentpath(start,target,current_flow,capacity,n)
        n=10;
        WHITE =0;
        GRAY=1;
        BLACK=2;
        color(1:n)=WHITE;
        head=1;
        tail=1;
        q=[];
        augmentpath=[ ];
        start=2;
        bInf = 0.5 ;
        bSup = 5 ;
        M    =    10 ;
        N    =    10 ;
     
        capacity = bInf + (bSup-bInf).*rand(M, N);
     
        %ENQUEUE
     
        q=[start q];
     
        color(start)=GRAY;
     
        pred(start) = -1;
     
        pred=zeros(1,n);
     
        while ~isempty (q) 
          %  [u,q]=dequeue(q);
                u=q(end);
                q(end)=[];
                color(u)=BLACK;
        %     dequeue end here
     
                for v=1:n
                    if (color(v)==WHITE && capacity(u,v)>current_flow(u,v) )
        %enqueue(v,q)
                        q=[v q];
                        color(v)=GRAY;
        % enqueue end here
                        pred(v)=u;                        
     
                    end
                end
        end
     
        if color(target)==BLACK       %if target is accessible
           temp=target;
           while pred(temp)~=start
            augmentpath = [pred(temp) augmentpath];     %augment path doesnt containt the start point AND target point
            temp=pred(temp);
           end
           augmentpath=[start augmentpath target];
        else
            augmentpath=[];         % default resulte is empty
        end

  2. #22
    Candidat au Club
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Février 2012
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Février 2012
    Messages : 18
    Points : 2
    Points
    2
    Par défaut
    Il ne me donne pas encore l'erreur de définition de la fonction parce ce que j'ai renommé le fichier par le nom de la fonction

    voila la commande que je saisi sur MATLAB:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    augmentpath = bfs_augmentpath(1,5,12,31,6)
    ??? Index exceeds matrix dimensions.
    
    Error in ==> C:\MATLAB6p5\toolbox\grtheorie\bfs_augmentpath.m
    On line 42  ==>                 if (color(v)==WHITE && capacity(u,v)>current_flow(u,v) )
    
    mais ça c'est mon nouveau message d'erreur !

  3. #23
    Modérateur

    Homme Profil pro
    Ingénieur en calculs scientifiques
    Inscrit en
    Août 2007
    Messages
    4 639
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Ingénieur en calculs scientifiques

    Informations forums :
    Inscription : Août 2007
    Messages : 4 639
    Points : 7 614
    Points
    7 614
    Par défaut
    Ouf!! Déjà un problème en moins.

    La fonction principale est ff_max_flow (qui fera appel à bfs_augmentpath), pourquoi veux-tu faire appel directement à bfs_augmentpath? Que cherches-tu à faire?

    Dans tout les cas, je te suggère de bien relire la description :
    Main function is function max_flow=ff_max_flow(source,sink,capacity,nodes_number).
    The graph is expressed as N by N adjacency matrix. N is the number of vertices in the graph, i.e., "nodes_number". "source","sink" are identified by the node ID. "capacity" is an N by N matrix express the edge capacity. "max_flow" is output max flow found.
    Pour une bonne utilisation des balises code c'est ici!
    Petit guide du voyageur MATLABien : Le forum La faq Les tutoriels Les sources


    La nature est un livre écrit en langage mathématique. Galilée.

  4. #24
    Candidat au Club
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Février 2012
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Février 2012
    Messages : 18
    Points : 2
    Points
    2
    Par défaut
    SALUT,

    mais si je commence par la fonction ff_max_flow voila l'erreur que me donne aussi :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    max_flow=ff_max_flow(1,5,37,6)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    ??? Index exceeds matrix dimensions.
     
    Error in ==> C:\MATLAB6p5\toolbox\grtheorie\bfs_augmentpath.m
    On line 42  ==>                 if (color(v)==WHITE && capacity(u,v)>current_flow(u,v) )
     
    Error in ==> C:\MATLAB6p5\toolbox\grtheorie\ff_max_flow.m
    On line 9  ==> augmentpath = bfs_augmentpath(source,sink,current_flow,capacity,nodes_number);

    ca veut dire que il ya un probleme au niveau de la ligne 42 !!
    merci infinment .

  5. #25
    Candidat au Club
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Février 2012
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Février 2012
    Messages : 18
    Points : 2
    Points
    2
    Par défaut
    voila la 1 er fonction :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    function max_flow=ff_max_flow(source,sink,capacity,nodes_number)
     
     
    current_flow=zeros(nodes_number,nodes_number);
     
    max_flow=0;
     
    augmentpath = bfs_augmentpath(source,sink,current_flow,capacity,nodes_number);
     
         %bfs_augmentpath(2,6,current_flow,capacity,6)
     
    while ~isempty(augmentpath)
     
        % if there exits a augment path, update teh current_flow    
        increment = inf;
        for i=1:length(augmentpath)-1
            increment=min(increment, capacity(augmentpath(i),augmentpath(i+1))-current_flow(augmentpath(i),augmentpath(i+1)));
        end
     
        %now increase the current_flow
     
        for i=1:length(augmentpath)-1
            current_flow(augmentpath(i),augmentpath(i+1))=current_flow(augmentpath(i),augmentpath(i+1))+increment;
            current_flow(augmentpath(i+1),augmentpath(i))=current_flow(augmentpath(i+1),augmentpath(i))-increment;
        end
        max_flow=max_flow+increment;
        augmentpath = bfs_augmentpath(source,sink,current_flow,capacity,nodes_number);% try to find new augment path    
     
    end
    voila la 2ème fonction :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    %WHITE =0;
    %GRAY=1;
    %BLACK=2
     
    function augmentpath=bfs_augmentpath(start,target,current_flow,capacity,n)
        n=10;
        WHITE =0;
        GRAY=1;
        BLACK=2;
        color(1:n)=WHITE;
        head=1;
        tail=1;
        q=[];
        augmentpath=[ ];
        start=2;
        bInf = 0.5 ;
        bSup = 5 ;
        M    =    10 ;
        N    =    10 ;
     
        capacity = bInf + (bSup-bInf).*rand(M, N);
     
        %ENQUEUE
     
        q=[start q];
     
        color(start)=GRAY;
     
        pred(start) = -1;
     
        pred=zeros(1,n);
     
        while ~isempty (q) 
          %  [u,q]=dequeue(q);
                u=q(end);
                q(end)=[];
                color(u)=BLACK;
        %     dequeue end here
     
                for v=1:n
                    if (color(v)==WHITE && capacity(u,v)>current_flow(u,v) )
        %enqueue(v,q)
                        q=[v q];
                        color(v)=GRAY;
        % enqueue end here
                        pred(v)=u;                        
     
                    end
                end
        end
     
        if color(target)==BLACK       %if target is accessible
           temp=target;
           while pred(temp)~=start
            augmentpath = [pred(temp) augmentpath];     %augment path doesnt containt the start point AND target point
            temp=pred(temp);
           end
           augmentpath=[start augmentpath target];
        else
            augmentpath=[];         % default resulte is empty
        end
    moi je suis un peu nul en info donc :
    Svp je vous demande de me donner les commandes que je vais taper sur MATLAB en ordre prioritaire. merci

  6. #26
    Candidat au Club
    Homme Profil pro
    Ingénieur qualité méthodes
    Inscrit en
    Février 2012
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Ingénieur qualité méthodes
    Secteur : Industrie

    Informations forums :
    Inscription : Février 2012
    Messages : 2
    Points : 3
    Points
    3
    Par défaut
    Moi non plus je n'arrive pas à trouver une solution pour ce code, comment l'empiler ?
    ??? Index exceeds matrix dimensions.
    
    Error in ==> C:\MATLAB6p5\toolbox\grtheorie\bfs_augmentpath.m
    On line 42  ==>                 if (color(v)==WHITE && capacity(u,v)>current_flow(u,v) )
    il y a un problème au niveau de la ligne 42 ,il y a quelque chose qui ne va pas...

  7. #27
    Modérateur

    Homme Profil pro
    Ingénieur en calculs scientifiques
    Inscrit en
    Août 2007
    Messages
    4 639
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Ingénieur en calculs scientifiques

    Informations forums :
    Inscription : Août 2007
    Messages : 4 639
    Points : 7 614
    Points
    7 614
    Par défaut
    Il faut utiliser correctement la fonction ff_max_flow.

    Citation Envoyé par moujaprim Voir le message
    mais si je commence par la fonction ff_max_flow voila l'erreur que me donne aussi :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    max_flow=ff_max_flow(1,5,37,6)
    Citation Envoyé par magelan Voir le message
    Dans tout les cas, je te suggère de bien relire la description :
    Main function is function max_flow=ff_max_flow(source,sink,capacity,nodes_number).
    The graph is expressed as N by N adjacency matrix. N is the number of vertices in the graph, i.e., "nodes_number". "source","sink" are identified by the node ID. "capacity" is an N by N matrix express the edge capacity. "max_flow" is output max flow found.
    Dans ton cas tu mets nodes_number=6 donc N=6, donc capacity doit être une matrice de taille 6 lignes par 6 colonnes.
    Pour une bonne utilisation des balises code c'est ici!
    Petit guide du voyageur MATLABien : Le forum La faq Les tutoriels Les sources


    La nature est un livre écrit en langage mathématique. Galilée.

  8. #28
    Candidat au Club
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Février 2012
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Février 2012
    Messages : 18
    Points : 2
    Points
    2
    Par défaut
    voila j'ai crée ma matrice d'adjacence a . et voila ce qu'il me donne encore comme erreur ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    a
     
    a =
     
         0     1     0     1     0     1
         0     0     0     0     0     0
         0     1     0     0     1     0
         0     0     0     0     1     1
         0     0     0     0     0     0
         0     0     1     0     0     0
     
    >> max_flow=ff_max_flow(1,5,a,6)
    ??? Index exceeds matrix dimensions.
     
    Error in ==> C:\MATLAB6p5\toolbox\grtheorie\bfs_augmentpath.m
    On line 43  ==>                 if (color(v)==WHITE && capacity(u,v)>current_flow(u,v) )
     
    Error in ==> C:\MATLAB6p5\toolbox\grtheorie\ff_max_flow.m
    On line 10  ==> augmentpath = bfs_augmentpath(source,sink,current_flow,capacity,nodes_number);
    donc je crois que le problème il est dans la ligne 43 cette boucle for ca marche po ! svp essayez lire un peu avec moi cet algorithme et précisément la ligne 43, peut être que ya qlq chose qui manque

  9. #29
    Modérateur

    Homme Profil pro
    Ingénieur en calculs scientifiques
    Inscrit en
    Août 2007
    Messages
    4 639
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Ingénieur en calculs scientifiques

    Informations forums :
    Inscription : Août 2007
    Messages : 4 639
    Points : 7 614
    Points
    7 614
    Par défaut
    La fonction bfs_augmentpath que tu utilises contient effectivement des erreurs. Télécharge les fichiers d'origines sur le lien suivant :
    http://www.mathworks.com/matlabcentr...rson-algorithm
    et copie les fichiers dans ton répertoire grtheorie
    Pour une bonne utilisation des balises code c'est ici!
    Petit guide du voyageur MATLABien : Le forum La faq Les tutoriels Les sources


    La nature est un livre écrit en langage mathématique. Galilée.

  10. #30
    Candidat au Club
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Février 2012
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Février 2012
    Messages : 18
    Points : 2
    Points
    2
    Par défaut
    MERCIIIIIIIIIIIIIIIIIIIIIIIIII bcp c tres gentil de ta part ,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    E=[1 2 4 1;1 3 2 2;2 3 2 1;3 2 1 6;3 4 3 3;2 4 1 5;2 5 2 6;4 5 5 5];
    >> a=[0 4 2 0 0 ; 0 0 2 1 2;0 1 0 3 0; 0 0 0 0 5;0 0 0 0 0]
     
    a =
     
         0     4     2     0     0
         0     0     2     1     2
         0     1     0     3     0
         0     0     0     0     5
         0     0     0     0     0
     
    >> max_flow=ff_max_flow(1,5,a,5)
     
    max_flow =
     
         6

    j'ai reussie à trouver le flow max, maintenant si je veut par exemple qu'il me donne les détails ca veut dire , que chaque arc combien d'amélioration qu'il va avoir et qu'ils sont les changements qu'il va subir ? merciii encore une 2eme fois

  11. #31
    Candidat au Club
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Février 2012
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Février 2012
    Messages : 18
    Points : 2
    Points
    2
    Par défaut
    par ce qu j'ai constaté aussi que cet fonction ne prend pas en consediration les flot declarer, est ce que je vais les declarer aussi comme matrice au bien . merci infiniment

  12. #32
    Candidat au Club
    Homme Profil pro
    Ingénieur qualité méthodes
    Inscrit en
    Février 2012
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Ingénieur qualité méthodes
    Secteur : Industrie

    Informations forums :
    Inscription : Février 2012
    Messages : 2
    Points : 3
    Points
    3
    Par défaut
    oui enfin moi aussi ça marche sur mon programme mais il me reste de savoir le flux optimal de chaque arc après l'amélioration .

    merci M. moujaprim
    mercii M. magelan

Discussions similaires

  1. Algorithme de Ford Fulkerson
    Par camelia136 dans le forum MATLAB
    Réponses: 8
    Dernier message: 10/08/2011, 14h39
  2. Algorithme sur le flot maximal de Ford Fulkerson
    Par witch dans le forum Algorithmes et structures de données
    Réponses: 8
    Dernier message: 13/05/2011, 15h57
  3. Algorithme de Ford-Fulkerson
    Par Du Wassoulou dans le forum C++
    Réponses: 3
    Dernier message: 26/12/2010, 19h29
  4. Problème sur un réseau routier avec l'algo de Ford-Fulkerson
    Par Yakurena dans le forum Algorithmes et structures de données
    Réponses: 1
    Dernier message: 20/02/2006, 09h35
  5. algorithme de Ford (recherche chemin le plus court)
    Par abstraite dans le forum Algorithmes et structures de données
    Réponses: 2
    Dernier message: 19/05/2005, 10h39

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo