[分享]基于启发式的度约束最小生成树的算法研究
如题,我正在做毕设,课题是:基于启发式的度约束最小生成树的算法研究,倘若哪位仁兄见到过c/c++的源代码,请帮帮忙。谢了先~~~[此贴子已经被风花雪月于2006-5-15 10:26:27编辑过]
最小生成树 我知道。有什么prim 算法等。但那时给予网络拓扑数据的。我不晓得你这个和那个有什么关系。
回复:(sll1223)[分享]基于启发式的度约束最小生成树...
最小生成树prim算法<BR><BR>const intCNST_NumGrphNodes= 101 ;<BR> // 最小生成树元素 <BR>structTTreeEdge {<BR> intv1, v2; <BR> doublew;<BR>} ;<BR> // 候选集元素 <BR>structTCloseRec {<BR> doublelowCost;<BR> intvec;<BR>} ;<BR> intMST_prim( intg[],intn, TTreeEdge* minTree) {<BR> inti, j, k;<BR> TCloseRec* close= newTCloseRec; <BR> for(i = 1 ; i < n; i ++ ) {<BR> close.vec= 0 ;<BR> close.lowCost=g[ 0 ];<BR> } <BR> close[ 0 ].lowCost= - 1 ;<BR> for(i = 0 ; i < n - 1 ; i ++ ) {<BR> // 找图点 <BR> for(k = 1 ; k < n; k ++ ) {<BR> if(close.lowCost!= - 1 ) {<BR> break ;<BR> } <BR> } <BR> for(j = k + 1 ; j < n; j ++ ) {<BR> if(close.lowCost!= - 1 ) {<BR> if(close.lowCost<close.lowCost) {<BR> k=j;<BR> } <BR> } <BR> } <BR> // 加入树中 <BR> minTree.v1=k;<BR> minTree.v2=close.vec;<BR> minTree.w=close.lowCost;<BR> close.lowCost= - 1 ;<BR> // 调整候选集 <BR> for(j = 1 ; j < n; j ++ ) {<BR> if(close.lowCost>g) {<BR> close.lowCost=g;<BR> close.vec=k;<BR> } <BR> } <BR> } <BR> delete []close;<BR> return 0 ;<BR>}回复:(sll1223)[分享]基于启发式的度约束最小生成树...
另一个程序<BR><BR>#include<IOSTREAM.H><BR>#include<CONIO.H><BR>#include"graph.h"<BR>const int MAX_VERTEX_NUM=100;<BR>typedef char VertexType;<BR>typedef int ARType;<BR>typedef struct<BR>{<BR>VertexType adjvex;//定义顶点的类型;<BR>ARTypelowcost;//定义该边上的权;<BR>}minside;//村顶点和权<BR><BR>int Locatevex(Graph G,VertexType u)<BR>{//为U的顶点在邻接矩阵表示中的数组的下标<BR>for(int n=1;n<=G.vexnum;n++)<BR>{<BR>if(u==G.vex)<BR>return n;<BR>}<BR>return -1;<BR>}<BR>int minimum(minside SZ,Graph G)<BR>{<BR>int i=1,j,k,min;<BR>while(!SZ.lowcost) ++i;<BR>min=SZ.lowcost;<BR>k=i;<BR>for(j=i+1;j<=G.vexnum;j++)<BR>{<BR>if(SZ.lowcost>0)<BR>{<BR>if(min>SZ.lowcost)<BR>{<BR>min=SZ.lowcost;k=j;<BR>}<BR>}<BR>}<BR>return k;<BR>}<BR>void MiniSpanTree_PRIM(Graph G,VertexType u)//用普里姆算法从第u个顶点出发构造<B >最小生成树</B>T,输出T的各边。<BR>{<BR>int i,j,k;<BR>minside closedge;<BR>k=Locatevex(G,u);<BR>for(j=1;j<=G.vexnum;j++)<BR>{//closedge数组初始化<BR>if(j!=k)<BR>{closedge.adjvex=u;closedge.lowcost=G.arcs;}<BR>}<BR>closedge.lowcost=0;<BR>cout<<"最小代价生成树的各边:"<<ENDL;<BR> for(i=2;i<=G.vexnum;i++)<BR>{<BR>k=minimum(closedge,G);<BR>cout<<"("<<CLOSEDGE.ADJVEX<<"_"<<G.VEX<<")";<BR> closedge.lowcost=0;<BR>for(int m=1;m<=G.vexnum;++m)<BR>{<BR>if(G.arcs<CLOSEDGE.LOWCOST)<BR> {closedge.adjvex=G.vex;closedge.lowcost=G.arcs;}<BR>}<BR>}<BR>}<BR>int main()<BR>{<BR>Graph p;<BR>VertexType u='a'; <BR>int n,e;<BR>cout<<"以邻接矩阵存储图的相关操作"<<ENDL;<BR> cout<<"顶点数:";<BR>cin>>n;<BR>cout<<"边数:";<BR>cin>>e;<BR>Creat(p,n,e);<BR>cout<<"打印邻接矩阵:"<<ENDL;<BR> print(p);<BR>MiniSpanTree_PRIM(p,u);<BR>return 1;<BR>getch();<BR>}<BR>回复:(sll1223)[分享]基于启发式的度约束最小生成树...
你还可以参考<a href="http://course.cug.edu.cn/cugFirst/discrete_mathe/netClass/tree/contents/06-02-guid.htm" target="_blank" >http://course.cug.edu.cn/cugFirst/discrete_mathe/netClass/tree/contents/06-02-guid.htm</A>
页:
[1]