- 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源码
neg_cycle.c
资源名称:leda.tar.gz [点击查看]
上传用户:gzelex
上传日期:2007-01-07
资源大小:707k
文件大小:1k
源码类别:
数值算法/人工智能
开发平台:
MultiPlatform
- #include <LEDA/graph.h>
- #include <LEDA/graph_alg.h>
- main()
- {
- GRAPH<int,int> G;
- node u;
- edge e;
- test_graph(G);
- edge_array<int> cost(G,0);
- node_array<int> dist(G,0);
- node_array<edge> pred(G,nil);
- node_array<int> label(G,0);
- int mi = read_int("min cost = ");
- int ma = read_int("max cost = ");
- forall_edges(e,G) cost[e] = G[e] = rand_int(mi,ma);
- node s = G.first_node();
- float T = used_time();
- cout << "BELLMAN_FORD <int> " << flush;
- bool b = BELLMAN_FORD(G,s,cost,dist,pred);
- cout << string("%6.2f sec ",used_time(T)) << endl;
- newline;
- if (b == false)
- { cout << "Negative cycle:" << endl;
- int count = 1;
- forall_nodes(u,G)
- { if (label[u] == 0)
- { while (label[u]==0)
- { label[u]=count;
- u=source(pred[u]);
- }
- if (label[u] == count) // cycle found
- { list<edge> cycle;
- for(e=pred[u]; source(e)!=u; e=pred[source(e)]) cycle.push(e);
- cycle.push(e);
- forall(e,cycle)
- { G.print_edge(e);
- newline;
- }
- newline;
- }
- }
- count++;
- }
- }
- else
- cout << "No negativ cycle found" << endl;
- return 0;
- }