- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
subgraph.c
资源名称:leda.tar.gz [点击查看]
上传用户:gzelex
上传日期:2007-01-07
资源大小:707k
文件大小:1k
源码类别:
数值算法/人工智能
开发平台:
MultiPlatform
- #include <LEDA/graph.h>
- #include <LEDA/graph_alg.h>
- GRAPH<int,int> shortest_path_tree(GRAPH<int,int>& G, edge_array<int>& cost)
- {
- // returns a shortest-paths tree as a subgraph of G
- node_array<int> dist(G);
- node_array<edge> pred(G);
- node s = G.first_node();
- DIJKSTRA(G,s,cost,dist,pred);
- list<edge> el;
- node v;
- forall_nodes(v,G) if (pred[v]!=0) el.append(pred[v]);
- return GRAPH<int,int>(G,G.all_nodes(),el); // subgraph constructor
- }
- main()
- { GRAPH<int,int> G;
- test_graph(G);
- edge_array<int> cost(G);
- int a = read_int("a = ");
- int b = read_int("b = ");
- random_source ran(a,b);
- edge e;
- forall_edges(e,G) cost[e] = G[e] = ran();
- GRAPH<int,int> S = shortest_path_tree(G,cost);
- G.print("graph G");
- newline;
- S.print("subgraph S");
- newline;
- edge_array<int> cost1(S);
- forall_edges(e,S) cost1[e] = S[e];
- GRAPH<int,int> S1 = shortest_path_tree(S,cost1);
- S1.print("subgraph S1");
- newline;
- return 0;
- }