dijtest.m

来自「Mathematical Methods by Moor n Stiling.」· M 代码 · 共 42 行

M
42
字号
% Test Sisjstras and Warshall's algorithms
% Copyright 1999 by Todd K. Moon

cost = [0 inf inf inf inf inf inf inf
        3 0 inf inf inf inf inf inf
        10 8 0 inf inf inf inf inf
        inf inf 12 0 inf inf inf inf
        inf inf inf 15 0 2.5 9 inf
        inf inf inf 10 inf 0 inf 14
        inf inf inf inf inf inf 0 10
        17 inf inf inf inf inf inf 0]
node = 5

[d,p] = dijkstra(5,cost)

% test Warshall
A = [1 1 0 0 0 1 1 0 0 0 0 0 0 
     0 1 0 0 0 0 0 0 0 0 0 0 0
     1 0 1 0 0 0 0 0 0 0 0 0 0
     0 0 0 1 0 1 0 0 0 0 0 0 0
     0 0 0 1 1 0 0 0 0 0 0 0 0
     0 0 0 0 1 1 0 0 0 0 0 0 0
     0 0 1 0 1 0 1 0 0 1 0 0 0
     0 0 0 0 0 0 1 1 1 0 0 0 0
     0 0 0 0 0 0 0 1 1 0 0 0 0
     0 0 0 0 0 0 0 0 0 1 1 1 1
     0 0 0 0 0 0 0 0 0 0 1 0 0
     0 0 0 0 0 0 1 0 0 0 0 1 1
     0 0 0 0
     0 0 0 0 0 0 0 1 1]
warshall(A);

cost = [0 0 0 0 0 0 0 0
        1 0 0 0 0 0 0 0
        1 1 0 0 0 0 0 0
        0 0 1 0 0 0 0 0
        0 0 0 1 0 1 1 0
        0 0 0 1 0 0 0 1
        0 0 0 0 0 0 0 1
        1 0 0 0 0 0 0 0];

warshall(cost)

⌨️ 快捷键说明

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