Grafalgo
Library of useful data structures and algorithms
/Users/jst/src/grafalgo/cpp/graphAlgorithms/sPath/sptRep.cpp
00001 // usage:
00002 //      sptRep method reps n m lo hi
00003 //
00004 // sptRep repeatedly generates a random graph and computes
00005 // its shortest path tree using the specified method.
00006 // Reps is the number of repetitions.
00007 // n is the number of vertices, m is the number of edges
00008 // [lo,hi] is the range of edge lengths
00009 //
00010 
00011 #include "stdinc.h"
00012 #include "Wdigraph.h"
00013 
00014 using namespace grafalgo;
00015 
00016 extern void dijkstra(Wdigraph&, vertex, vertex*, int*);
00017 extern void bfScan(Wdigraph&, vertex, vertex*, int*);
00018 
00019 int main(int argc, char *argv[]) {
00020         int i, reps, n, m, lo, hi;
00021 
00022         if (argc != 7 ||
00023             sscanf(argv[2],"%d",&reps) != 1 ||
00024             sscanf(argv[3],"%d",&n) != 1 ||
00025             sscanf(argv[4],"%d",&m) != 1 ||
00026             sscanf(argv[5],"%d",&lo) != 1 ||
00027             sscanf(argv[6],"%d",&hi) != 1)
00028                 Util::fatal("usage: mstRep method reps n m span lo hi");
00029 
00030         vertex *p = new vertex[n+1]; vertex *d = new vertex[n+1];
00031         Wdigraph dig; Wdigraph *sptree;
00032         for (i = 1; i <= reps; i++) {
00033                 dig.rgraph(n,m); 
00034                 dig.randLength(lo,hi);
00035                 sptree = new Wdigraph(dig.n(),dig.n()-1);
00036                 if (strcmp(argv[1],"dijkstra") == 0)
00037                         dijkstra(dig,1,p,d);
00038                 else if (strcmp(argv[1],"bfScan") == 0)
00039                         bfScan(dig,1,p,d);
00040                 else
00041                         Util::fatal("sptRep: undefined method");
00042                 delete sptree;
00043         }
00044 }
 All Classes Files Functions Variables Typedefs Friends