match_test.c
上传用户:gzelex
上传日期:2007-01-07
资源大小:707k
文件大小:1k
开发平台:

MultiPlatform

  1. #include <LEDA/graph.h>
  2. #include <LEDA/graph_alg.h>
  3. edge_array<int>* W;
  4. int EDGE_CMP(edge& e1, edge& e2)
  5. { return (*W[e1]-*W[e2]); }
  6. main()
  7. {
  8. GRAPH<int,int> G;
  9. list<node> A,B;
  10. edge e;
  11. test_bigraph(G,A,B);
  12. edge_array<int> weight(G);
  13. W = &weight;
  14. if (Yes("random edge weights from [a..b] ? "))
  15.  { int a = read_int("a = ");
  16.    int b = read_int("b = ");
  17.    forall_edges(e,G) G[e] = rand_int(a,b);
  18.   }
  19. else
  20.  forall_edges(e,G)
  21.    { G.print_edge(e);
  22.      G[e] = read_int("  w = ");
  23.     }
  24. forall_edges(e,G) weight[e] = G[e];
  25. if (Yes("show graph ? ")) G.print();
  26. list<edge> M1 = MAX_WEIGHT_BIPARTITE_MATCHING(G,A,B,weight);
  27. forall(e,M1) { G.print_edge(e); newline; }
  28. newline;
  29. G.sort_edges(EDGE_CMP);
  30. int i = 0;
  31. forall_edges(e,G) G[e] = weight[e] = i++;
  32. if (Yes("show graph? ")) G.print();
  33. list<edge> M2 = MAX_WEIGHT_BIPARTITE_MATCHING(G,A,B,weight);
  34. forall(e,M2) { G.print_edge(e); newline; }
  35. newline;
  36. return 0;
  37. }