match_test.c
资源名称:leda.tar.gz [点击查看]
上传用户:gzelex
上传日期:2007-01-07
资源大小:707k
文件大小:1k
源码类别:
数值算法/人工智能
开发平台:
MultiPlatform
- #include <LEDA/graph.h>
- #include <LEDA/graph_alg.h>
- edge_array<int>* W;
- int EDGE_CMP(edge& e1, edge& e2)
- { return (*W[e1]-*W[e2]); }
- main()
- {
- GRAPH<int,int> G;
- list<node> A,B;
- edge e;
- test_bigraph(G,A,B);
- edge_array<int> weight(G);
- W = &weight;
- if (Yes("random edge weights from [a..b] ? "))
- { int a = read_int("a = ");
- int b = read_int("b = ");
- forall_edges(e,G) G[e] = rand_int(a,b);
- }
- else
- forall_edges(e,G)
- { G.print_edge(e);
- G[e] = read_int(" w = ");
- }
- forall_edges(e,G) weight[e] = G[e];
- if (Yes("show graph ? ")) G.print();
- list<edge> M1 = MAX_WEIGHT_BIPARTITE_MATCHING(G,A,B,weight);
- forall(e,M1) { G.print_edge(e); newline; }
- newline;
- G.sort_edges(EDGE_CMP);
- int i = 0;
- forall_edges(e,G) G[e] = weight[e] = i++;
- if (Yes("show graph? ")) G.print();
- list<edge> M2 = MAX_WEIGHT_BIPARTITE_MATCHING(G,A,B,weight);
- forall(e,M2) { G.print_edge(e); newline; }
- newline;
- return 0;
- }