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 :

Implémentation de l'algorithme Dijkstra


Sujet :

MATLAB

  1. #1
    Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Février 2014
    Messages
    110
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2014
    Messages : 110
    Points : 51
    Points
    51
    Par défaut Implémentation de l'algorithme Dijkstra
    Bonsoir a tous
    je veux implémenter l'algorithme Dijkstra sous matlab
    je trouve ce code à l'internet et j'ai essayé de l'exécuter
    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
    function [sp, spcost] = dijkstra(matriz_costo, s, d)
    % This is an implementation of the dijkstras algorithm, wich finds the 
    % minimal cost path between two nodes. Its supoussed to solve the problem on 
    % possitive weighted instances.
     
    % the inputs of the algorithm are:
    %farthestNode: the farthest node to reach for each node after performing
    % the routing;
    % n: the number of nodes in the network;
    % s: source node index;
    % d: destination node index;
     
    %For information about this algorithm visit:
    %http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
     
    %This implementatios is inspired by the Xiaodong Wang's implememtation of
    %the dijkstra's algorithm, available at
    %http://www.mathworks.com/matlabcentral/fileexchange
    %file ID 5550
     
    %Author: Jorge Ignacio Barrera Alviar. April/2007
     
     
    n=size(matriz_costo,1);
    S(1:n) = 0;     %s, vector, set of visited vectors
    dist(1:n) = inf;   % it stores the shortest distance between the source node and any other node;
    prev(1:n) = n+1;    % Previous node, informs about the best previous node known to reach each  network node 
     
    dist(s) = 0;
     
     
    while sum(S)~=n
        candidate=[];
        for i=1:n
            if S(i)==0
                candidate=[candidate dist(i)];
            else
                candidate=[candidate inf];
            end
        end
        [u_index u]=min(candidate);
        S(u)=1;
        for i=1:n
            if(dist(u)+matriz_costo(u,i))<dist(i)
                dist(i)=dist(u)+matriz_costo(u,i);
                prev(i)=u;
            end
        end
    end
     
     
    sp = [d];
     
    while sp(1) ~= s
        if prev(sp(1))<=n
            sp=[prev(sp(1)) sp];
        else
            error;
        end
    end;
    spcost = dist(d);
    Mais j'ai obtenu cet erreur:
    ??? Input argument "matriz_costo" is undefined.
    
    Error in ==> dijkstra at 24
    n=size(matriz_costo,1);
    pouvez vous m'aider svp
    cordialement

  2. #2
    Rédacteur/Modérateur

    Avatar de Jerome Briot
    Homme Profil pro
    Freelance mécatronique - Conseil, conception et formation
    Inscrit en
    Novembre 2006
    Messages
    20 302
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance mécatronique - Conseil, conception et formation

    Informations forums :
    Inscription : Novembre 2006
    Messages : 20 302
    Points : 52 884
    Points
    52 884
    Ingénieur indépendant en mécatronique - Conseil, conception et formation
    • Conception mécanique (Autodesk Fusion 360)
    • Impression 3D (Ultimaker)
    • Développement informatique (Python, MATLAB, C)
    • Programmation de microcontrôleur (Microchip PIC, ESP32, Raspberry Pi, Arduino…)

    « J'étais le meilleur ami que le vieux Jim avait au monde. Il fallait choisir. J'ai réfléchi un moment, puis je me suis dit : "Tant pis ! J'irai en enfer" » (Saint Huck)

  3. #3
    Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Février 2014
    Messages
    110
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2014
    Messages : 110
    Points : 51
    Points
    51
    Par défaut
    Citation Envoyé par Jerome Briot Voir le message
    il est un input argument comment je vais le définir?

  4. #4
    Modérateur
    Avatar de le fab
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    1 882
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2005
    Messages : 1 882
    Points : 3 432
    Points
    3 432
    Par défaut
    Salut

    Citation Envoyé par zeinab ali Voir le message
    je trouve ce code à l'internet et j'ai essayé de l'exécuter
    comment as tu essayé de l'exécuter ??

  5. #5
    Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Février 2014
    Messages
    110
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2014
    Messages : 110
    Points : 51
    Points
    51
    Par défaut
    Citation Envoyé par le fab Voir le message
    Salut


    comment as tu essayé de l'exécuter ??
    salut
    j'ai essayé de l'exécuter avec le logiciel matlab

  6. #6
    Modérateur
    Avatar de le fab
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    1 882
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2005
    Messages : 1 882
    Points : 3 432
    Points
    3 432
    Par défaut
    certes, mais comment ?

  7. #7
    Nouveau membre du Club
    Femme Profil pro
    université constantine
    Inscrit en
    Novembre 2014
    Messages
    23
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 29
    Localisation : Algérie

    Informations professionnelles :
    Activité : université constantine

    Informations forums :
    Inscription : Novembre 2014
    Messages : 23
    Points : 26
    Points
    26
    Par défaut
    Bonjour

    voici un exemple simple d'utilisation de fonctions :

    Dans un fichier nommé stat.m, on écrit le texte suivant Dans un fichier nommé stat.m
    Etape 1 : Création de la fonction

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     function [mean,stdev] = stat(x)
    n = length(x);
    mean = sum(x)/n;
    stdev = sqrt(sum((x-mean).^2/n));
    Etape 2 : Création d'un script qui utilise la fonction :
    Dans un fichier nommé monscript.m (qui se trouve dans le même répertoire que stat.m), on écrit le texte suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    [mean stdev] = stat([12.7 45.4 98.9 26.6 53/1])

    pour vous ce qui manque c'est la deuxième étape , il faut un programme principale qui appele cette fonction .
    qui se trouve dans le même répertoire que main.m
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    s= 1;   % par exemple la source  = 1 
    d= 4;   % par exemple destination = 4
    matriz_costo = [0 8 0 0 11 0 0;
            0 0 2 0 0 0 0 ;
            0 0 0 5 0 0 14;
            0 0 0 0 3 0 0;
            11 0 0 0 0 2 0;
            0 0 0 7 0 0 9;
            0 6 0 0 0 0 0 ;];  %  je n'ai pas lu l code mais je pense c'est la matrice de distances    . 
    [sp, spcost] = dijkstra(matriz_costo, s, d)
    Je vous donne un autre code plus simple , si tu n'as pas compris je peux t'expliquer le code .
    Fichiers attachés Fichiers attachés

Discussions similaires

  1. [Turbo Pascal] Implémentation de l'algorithme de Dijkstra
    Par sparklegi dans le forum Turbo Pascal
    Réponses: 8
    Dernier message: 08/05/2009, 11h38
  2. Implémentation de l'algorithme de kmeans
    Par kevin2008 dans le forum C++
    Réponses: 0
    Dernier message: 18/04/2008, 11h29
  3. Implémentation d'un algorithme foireuse
    Par khazna dans le forum C++
    Réponses: 15
    Dernier message: 05/03/2008, 14h29
  4. Implémentation de l'algorithme FCM en C
    Par hoolaka dans le forum Algorithmes et structures de données
    Réponses: 1
    Dernier message: 11/02/2008, 22h57
  5. Réponses: 1
    Dernier message: 07/03/2007, 09h28

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