3.txt

来自「function [r_path, r_cost] = dijkstra(pat」· 文本 代码 · 共 47 行

TXT
47
字号


% Create a transition matrix by hand
%
matrix =  ...
[ 1   2 Inf Inf
Inf Inf   3   3
  1 Inf Inf Inf
  1 Inf Inf Inf
];

n_node = size(matrix , 1);


% Convert the matrix to Graphviz source code
%
fid = fopen('graph.dot', 'w');
fprintf(fid, 'digraph{\n');

for i=1:n_node
  for j=1:n_node
    if matrix(i,j) ~= Inf
      fprintf(fid, '\"%d\" -> \"%d\" [label=\"%f\"] ; \n', ...
              i, j, matrix(i,j) );
    end
  end
end

fprintf(fid, '}\n');
fclose(fid);


% Draw the graph into an EPS file
%
system('dot -Tps graph.dot -o graph.eps');


% Found and print all cycles
% 
for i = 1:n_node
  [path, cost] = dijkstra(i,i,matrix);
  fprintf(2, 'Cycle from %d -> %d, cost=%f, path is:', ...
          i, i, cost);
  disp(path)
end
    

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?