資源簡介
北京郵電大學計算機仿真作業。絕對能用 程序中的prim算法實現猶為有特色
代碼片段和文件信息
clear?all;
close?all;
Graph11;%調用以鄰接矩陣儲存的圖所在的M文件
%Graph22;
len=length(graph_adjacent);%計算圖中的頂點數
temp=graph_adjacent;%將原圖內容拷貝到temp中,以防對原圖做改動
superedge=zeros(len-12);%用于保存生成最小生成樹的邊
i=1;%指向superedge的下標
for?j=1:len
?tag(j)=j;%關聯標志初始化,將每個頂點的關聯標志設為其本身
end;
%以下的循環完成kruskal算法
while(superedge(len-11)==0)
????[YI]=sort(temp);%將temp的每列按從小到大排序,數組Y保存temp?排序后的結果,I中保存相應結果對應的在temp中的下標
????cost_min=min(Y(1:));%找出權值最小的邊
????index=find(Y(1:)==cost_min);%找出權值最小的邊對應的頂點
????index=index(1);%一條邊對應兩個節點,且不同的邊的權值可能一樣,這里為了方便處理人為規定了順序,取標號最小的頂點進行處理
????anotherpoint=I(1index);%找到該邊對應的另一個頂點
????%將該邊對應的權值修改為最大,防止該邊在下次循環中再次被選為最優邊
????temp(indexanotherpoint)=100;
????temp(anotherpointindex)=100;
????if(tag(anotherpoint)~=tag(index))%當兩個點不屬于一個連通集時,這兩個點之間的邊為最小生成樹的邊
????????superedge(i:)=[ind
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2026??2008-06-14?10:51??prim?and?kruskal\code\finallykruskal.m
?????文件???????2405??2008-06-14?10:51??prim?and?kruskal\code\finallyprim.m
?????文件????????321??2008-06-09?15:26??prim?and?kruskal\code\Graph1.m
?????文件????????333??2008-06-09?21:11??prim?and?kruskal\code\Graph11.m
?????文件????????392??2008-06-09?16:17??prim?and?kruskal\code\Graph2.m
?????文件????????408??2008-06-09?21:12??prim?and?kruskal\code\Graph22.m
?????文件???????2169??2008-06-14?13:08??prim?and?kruskal\code\kruskalenhance.m
?????文件?????????83??2008-06-14?13:29??prim?and?kruskal\code\Readme.txt
?????文件????????153??2008-06-14?10:21??prim?and?kruskal\code\test.m
?????文件????????187??2008-06-14?10:44??prim?and?kruskal\code\testsparse.m
?????文件?????600576??2008-09-16?18:31??prim?and?kruskal\計算機仿真final.doc
?????目錄??????????0??2008-11-17?22:23??prim?and?kruskal\code
?????目錄??????????0??2008-11-17?22:23??prim?and?kruskal
-----------?---------??----------?-----??----
???????????????609053????????????????????13
- 上一篇:matlab 光伏模糊控制 MPPT boost
- 下一篇:六位置法加速度計標定
評論
共有 條評論