필터 지우기
필터 지우기

Test directed graph for cycles, write them, and change paths to it become acyclic

조회 수: 1 (최근 30일)
Hi, I'm totally new to matlab, I need to write an algorithm where directed graph would be tested for cycles, cycles writed down and then their paths directions changed so that the graph becomes acyclic.
Here is my code so far..
clear all
clc
% Number of edges
n = input ('Kiek grafe virsuniu:');
% Create graph
A = round(rand(n));
no_el = n*n; % elementu sk.
dlg = 1:n+1:no_el; % isrinkti pagrindine istrizaine
A(dlg) = 0; % pagrindines istrizaines skaicius paversti nuluikais
testi_viska = 1;
testi = 1;
KelioIlgis = 1;
i = 1;
j = 1;
while i <= n && testi_viska == 1
%KelioIlgis = (KelioIlgis + 1);
Kelias(1,j) = i;
testi = 1;
j = 1;
while j <= n && testi == 1
if A(i,j) == 1
KelioIlgis = (KelioIlgis + 1);
Kelias(1, KelioIlgis) = j;
c = 1;
while c < KelioIlgis
if Kelias(1,c)==Kelias(1,KelioIlgis);
disp('CIKLAS!');
disp(Kelias);
A(i,j) = 0;
%A(j,i) = 1;
Kelias = Kelias - Kelias(1,KelioIlgis);
KelioIlgis = (KelioIlgis - 1);
testi = 1;
elseif Kelias(1,c)~=Kelias(1,KelioIlgis);
disp('CIKLO NĖRA');
testi = 0;
i = j;
c = c + 1;
end
end
end;
end;
end;
It looks like somewhere it becomes endless... Guys please help me out!
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 11월 22일
Does it display anything endlessly? Have you tried stepping through with the debugger?

댓글을 달려면 로그인하십시오.

답변 (0개)

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by