Grafalgo
Library of useful data structures and algorithms
/Users/jst/src/grafalgo/cpp/graphAlgorithms/match/matchRep.cpp
00001 // usage:
00002 //      matchRep {size|weight} {bipartite|general} method reps n m maxwt seed
00003 //
00004 // matchRep repeatedly generates a random graph and computes
00005 // a matching using the specified method. When bipartite
00006 // graphs are specified, it generates bipartite graphs.
00007 //
00008 // Reps is the number of repetitions.
00009 // n is the number of vertices, p is the edge probability,
00010 // maxwt is the maximum edge weight parameter.
00011 
00012 #include "stdinc.h"
00013 #include "Dlist.h"
00014 #include "Wgraph.h"
00015 #include "altPath.h"
00016 #include "faltPath.h"
00017 #include "edmonds.h"
00018 
00019 using namespace grafalgo;
00020 
00021 extern void flowMatch(Graph&,Dlist&,int&);
00022 extern void flowMatch(Wgraph&,Dlist&,int&,int&);
00023 
00024 int main(int argc, char* argv[]) {
00025         int i, reps, n, m, mSize, maxwt, seed;
00026         bool size, bipartite;
00027         Wgraph graf; Wgraph wg;
00028         Dlist *match;
00029         
00030         if (argc != 9 ||
00031             sscanf(argv[4],"%d",&reps) != 1 ||
00032             sscanf(argv[5],"%d",&n) != 1 ||
00033             sscanf(argv[6],"%d",&m) != 1 ||
00034             sscanf(argv[7],"%d",&maxwt) != 1 ||
00035             sscanf(argv[8],"%d",&seed) != 1)
00036                 Util::fatal("usage: match {size|weight} {bipartite|general} "
00037                       "method reps n p maxwt seed");
00038 
00039         if (strcmp(argv[1],"size") == 0)  size = true;
00040         else if (strcmp(argv[1],"weight") == 0)  size = false;
00041         else Util::fatal("usage: match {size|weight} {bipartite|general} method");
00042 
00043         if (strcmp(argv[2],"bipartite") == 0)  bipartite = true;
00044         else if (strcmp(argv[1],"general") == 0)  bipartite = false;
00045         else Util::fatal("usage: match {size|weight} {bipartite|general} method");
00046 
00047         srandom(seed);
00048         for (i = 1; i <= reps; i++) {
00049                 match = new Dlist(m);
00050                 if (size && bipartite) { 
00051                         graf.rbigraph(n,m);
00052                         if (strcmp(argv[3],"altPath") == 0) {
00053                                 altPath(graf,*match,mSize);
00054                         } else if (strcmp(argv[3],"faltPath") == 0) {
00055                                 faltPath(graf,*match,mSize);
00056                         } else if (strcmp(argv[3],"flowMatch") == 0) {
00057                                 flowMatch(graf,*match,mSize);
00058                         } else {
00059                                 Util::fatal("match: invalid method");
00060                         }
00061                 } else if (!size && bipartite) {
00062                         wg.rbigraph(n,m); wg.randWeight(0,maxwt);
00063                         if (strcmp(argv[3],"flowMatch") == 0) {
00064                                 flowMatch(wg,*match,mSize,mSize);
00065                         } else {
00066                                 Util::fatal("match: invalid method");
00067                         }
00068                 } else if (size & !bipartite) {
00069                         graf.rgraph(n,m);
00070                         if (strcmp(argv[3],"edmonds") == 0) {
00071                                 edmonds(graf,*match,mSize);
00072                         } else {
00073                                 Util::fatal("match: invalid method");
00074                         }
00075                 } else { // no algorithms for other cases (yet)
00076                         Util::fatal("match: invalid method");
00077                 }
00078                 delete match;
00079         }
00080 }
 All Classes Files Functions Variables Typedefs Friends