WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

Strongly Connected Components using Tarjan Algorithm

 

JarsOfClay
Forum-Newbie

Forum-Newbie


Beiträge: 2
Anmeldedatum: 30.05.13
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 30.05.2013, 15:36     Titel: Strongly Connected Components using Tarjan Algorithm
  Antworten mit Zitat      
Hello Guys,
I actually wanted to extract Strongly Connected Components using Matlab and Tarjan Algorithm. For that i have been provided with Petrinets from the institute. I have converted Pseudocode to Matlab Codes exactly how it should be . I have attatched my petrinets and matlab code . My institutes dean says that there should be 7 strongly connected components after an implementation of algorithm but i cant get the result at all. If anyone who has dealt with same problem could just take a look at the code and let me know the problem would be very very greatful . Thanking you Jarsofclay

Code:
function [scnt,C] = graphSCC(G)

global S


n = length(G);
Adj = cell(n,1);

for ivert = 1:n
    Adj{ivert} = find(G(ivert,:)>0);
end

scnt=0;
cnt = 0;

S.nel=0;
S.stack = {};
S.isIn = zeros(1,n);

low = -ones(1,n);
number = -ones(1,n);
C = -ones(1,n);

for iv = 1:n
    if (number(iv)==-1)
        strongConnect(iv);
    end
end

    function strongConnect(v)
        cnt = cnt+1;
        low(v)=cnt;
        number(v)=cnt;
        add(v);
       
        for w = Adj{v}
            if (number(w)==-1)
                strongConnect(w);
                low(v) = min(low(v),low(w));
            elseif (number(w)<number(v))
                if (S.isIn(w))
                    low(v) = min(low(v),number(w));
                end
            end
        end
        if (low(v) == number(v))
            cont = 1;
            scnt = scnt+1;
           
            while (S.nel ~= 0 && cont)
                top = S.stack{1};
                if (number(top) >= number(v) )
                    w = pop();
                    C(w) = scnt;
                else
                    cont = 0;
                end
            end
        end
    end
end

function add(v)
global S
  S.nel = S.nel+1;
  S.stack = [{v} S.stack];
  S.isIn(v)=1;
end

function  v = pop()
global S
  if (S.nel~=0)
      v = S.stack{1};
      S.nel = S.nel-1;
      S.stack(1) = [];
      S.isIn(v)=0;
  else
      v = [];
  end
   
end
Private Nachricht senden Benutzer-Profile anzeigen


JarsOfClay
Themenstarter

Forum-Newbie

Forum-Newbie


Beiträge: 2
Anmeldedatum: 30.05.13
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 30.05.2013, 15:38     Titel:
  Antworten mit Zitat      
http://www.file-upload.net/download-7656423/pnet.mat.html << here is by the way the petrinet that is being provided
Private Nachricht senden Benutzer-Profile anzeigen
 
Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2025 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.