Problem finding minimal spanning tree from a graph

조회 수: 13 (최근 30일)
Matias Micheletto
Matias Micheletto 2018년 2월 26일
I have an undirected graph defined according to the following vectors s, t (nodes) and w (weights):
>> [s', t', w'] ans =
1.0000 2.0000 89.3384
1.0000 3.0000 169.9317
1.0000 4.0000 233.8909
1.0000 5.0000 274.9552
1.0000 6.0000 289.1050
1.0000 7.0000 274.9552
1.0000 8.0000 233.8909
1.0000 9.0000 169.9317
1.0000 10.0000 89.3384
1.0000 11.0000 441.2867
1.0000 12.0000 265.2386
1.0000 13.0000 348.1541
1.0000 14.0000 176.3313
2.0000 3.0000 89.3384
2.0000 4.0000 169.9317
2.0000 5.0000 233.8909
2.0000 6.0000 274.9552
2.0000 7.0000 289.1050
2.0000 8.0000 274.9552
2.0000 9.0000 233.8909
2.0000 10.0000 169.9317
2.0000 11.0000 427.2373
2.0000 12.0000 340.9336
2.0000 13.0000 268.0377
2.0000 14.0000 216.2818
3.0000 4.0000 89.3384
3.0000 5.0000 169.9317
3.0000 6.0000 233.8909
3.0000 7.0000 274.9552
3.0000 8.0000 289.1050
3.0000 9.0000 274.9552
3.0000 10.0000 233.8909
3.0000 11.0000 377.2657
3.0000 12.0000 388.6871
3.0000 13.0000 179.3822
3.0000 14.0000 302.9923
4.0000 5.0000 89.3384
4.0000 6.0000 169.9317
4.0000 7.0000 233.8909
4.0000 8.0000 274.9552
4.0000 9.0000 289.1050
4.0000 10.0000 274.9552
4.0000 11.0000 299.1372
4.0000 12.0000 401.9564
4.0000 13.0000 131.7714
4.0000 14.0000 385.9712
5.0000 6.0000 89.3384
5.0000 7.0000 169.9317
5.0000 8.0000 233.8909
5.0000 9.0000 274.9552
5.0000 10.0000 289.1050
5.0000 11.0000 210.1859
5.0000 12.0000 379.0808
5.0000 13.0000 181.8239
5.0000 14.0000 443.2259
6.0000 7.0000 89.3384
6.0000 8.0000 169.9317
6.0000 9.0000 233.8909
6.0000 10.0000 274.9552
6.0000 11.0000 154.0114
6.0000 12.0000 322.9582
6.0000 13.0000 270.6866
6.0000 14.0000 464.8621
7.0000 8.0000 89.3384
7.0000 9.0000 169.9317
7.0000 10.0000 233.8909
7.0000 11.0000 189.5304
7.0000 12.0000 241.6977
7.0000 13.0000 350.1975
7.0000 14.0000 447.6736
8.0000 9.0000 89.3384
8.0000 10.0000 169.9317
8.0000 11.0000 275.9059
8.0000 12.0000 153.5441
8.0000 13.0000 402.8703
8.0000 14.0000 394.1892
9.0000 10.0000 89.3384
9.0000 11.0000 359.1245
9.0000 12.0000 114.3876
9.0000 13.0000 420.8548
9.0000 14.0000 313.3939
10.0000 11.0000 417.4630
10.0000 12.0000 175.9297
10.0000 13.0000 401.7743
10.0000 14.0000 225.2560
I need to find the minimal spanning tree, so I run the following command:
>> [Tree, pred] = graphminspantree(sparse(s,t,w,size(s,1),size(s,1)),'Method','Prim');
And I get this result:
Tree =
All zero sparse: 14×14
pred =
0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
Why isn't the result the minimum spanning tree? Where is the problem?
Thanks in advance!

답변 (0개)

카테고리

Help CenterFile Exchange에서 Undirected Graphs에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by