virtual void SetUp()
	{
		LOG_INIT("test.log", NULL, 0);
		gr = factory.create_reader("DIMACS");
		gr->read_graph("data/1dc.128.txt");

		creator.set_file_name("data/1dc.128.txt");
		creator.set_graph_type("DIMACS");
		g = creator.create_graph();
	}
Example #2
0
int main(int argc, char **argv){
    //usage check
    if((argc == 1) ||
       ((argc == 2) && (strcmp(argv[1],"-h") == 0)) ||
       ((argc == 2) && (strcmp(argv[1], "--help") == 0))){
        usage(argv[0]);
        exit(-1);
    }

    Graph::Graph *g;

    clock_t begin, end;

    Graph::GraphProperties prop;
    Graph::GraphReader ngr;

    //create the graph object
    g = new Graph::Graph();

    //read the graph from the filename, assume it is an edgelist
    ngr.read_graph(g, argv[1], "Edge", false);
    //ngr.read_graph(g, argv[1], "ADJLIST", false);
    printf("Read %d vertices and %d edges\n", g->get_num_nodes(), g->get_num_edges());

    printf("Simplifying graph\n");
    begin = clock();
    prop.make_simple(g);    //remove self loops and duplicate edges
    end = clock();
    printf("Time: %f\n", double(end - begin) / CLOCKS_PER_SEC);

    //compute normalized expansion
    begin = clock();
    vector<double> norm_hops;
    prop.expansion(g, norm_hops);
    end = clock();
    printf("Alg Time (expansion): %f\n", double(end - begin) / CLOCKS_PER_SEC);
} // main
Example #3
0
int main(int argc, char **argv){
    string infile;
    string outfilename;
    string outprefix;
    string apspinputfilename;
    string lcc_apspinputfilename;
    ofstream outfile;
    ofstream timing_file;
    bool record_timings = false;
    bool file_append = false;
    bool run_largest_cc = true;
    string intype ("edge");
    std::map<string, bool> req_methods;
    std::map<string, bool> val_methods;
    ORB_t t1, t2;
    int spectrum_spread = 0;
    create_map(allowed_methods, val_methods);
    parse_options(argc, argv, infile, intype, outfilename, outprefix, req_methods, record_timings, file_append, run_largest_cc, &spectrum_spread, apspinputfilename, lcc_apspinputfilename);
    if(outfilename.length() == 0){
        if(outprefix.length() != 0){
            outfilename = outprefix + ".stats";
        }
        else {
            outfilename = "graph-stats.txt";
        }
    }
    if(outprefix.length() == 0){
        outprefix = infile;
    }

    // we'd like higher precision when printing values
    std::cout.precision(10);
    #ifdef MPI_VERSION
    MPI_Init(&argc, &argv);
    int myrank;
    MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
    if(myrank == 0){
    #endif
    cout << "done parsing options" << endl;
    cout << "Input  file: " << infile << endl;
    cout << "Input  type: " << intype << endl;
    cout << "Output file: " << outfilename << endl;
    cout << "Appending  : ";
    cout << std::boolalpha << file_append << endl;
    cout << "Methods    :";
    for(map<string, bool>::iterator it = req_methods.begin(); it != req_methods.end(); ++it){
        cout << " " << it->first;
        if(val_methods[it->first] != true){
            cerr << "Error: " << it->first << " is not a valid method! " << endl;
        }
    }
    cout << endl;
    cout << "Calibrating timers" << endl;
    #ifdef MPI_VERSION
} // main

    #endif
    ORB_calibrate();

    // let's do some calculations

    Graph::Graph *g = new(Graph::Graph);
    Graph::GraphReader gr;
    Graph::GraphProperties gp;
    Graph::GraphUtil gu;

    #ifdef MPI_VERSION
    //int myrank;
    //MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
    if(myrank == 0){
    #endif

    // Set up output streams
    if(file_append == false){
        outfile.open(outfilename.c_str());
    }
    else {
        outfile.open(outfilename.c_str(), ios_base::out | ios_base::app);
    }
    if(!outfile.is_open()){
        cerr << "Error opening " << outfilename << " for writing, exiting" << endl;
        exit(1);
    }

    #ifdef MPI_VERSION
}
    #endif

    // Read in the graph and start recording things to output streams
    cout << "Reading graph" << endl;
    ORB_read(t1);
    if(gr.read_graph(g, infile, intype, false) == -1){
        exit(1);
    }
    ORB_read(t2);

    if(outfile.tellp() == 0){
        outfile << "filename " << infile << endl;
        outfile << "input_num_nodes " << g->get_num_nodes() << endl;
        outfile << "input_num_edges " << g->get_num_edges() << endl;
    }

    if(record_timings){
        string of = outfilename + ".timings";

        #ifdef MPI_VERSION
        if(0 == myrank){
        #endif
        if(file_append == false){
            timing_file.open(of.c_str());
        }
        else {
            timing_file.open(of.c_str(), ios_base::out | ios_base::app);
        }
        if(!timing_file.is_open()){
            cerr << "Error opening " << timing_file << " for writing, exiting" << endl;
            exit(1);
        }
        if(false == file_append){
            outfile << "timing_file " << of << endl;
        }
        #ifdef MPI_VERSION
    }
        #endif
    }

    print_time(timing_file, "Time(read_graph)", t1, t2);

    if(apspinputfilename.length() != 0){
        cout << "Reading APSP matrix from " << apspinputfilename << endl;
        vector< vector<int> > *apsp_dists = new vector< vector<int> >;
        ORB_read(t1);
        read_apsp_matrix(apspinputfilename, *apsp_dists);
        ORB_read(t2);
        print_time(timing_file, "Time(read_apsp_matrix)", t1, t2);
        g->set_shortest_path_dist(apsp_dists);
    }

    outfile.precision(16);
    vector<int> components;
    ORB_read(t1);
    gu.label_all_components(g, &components);
    ORB_read(t2);
    print_time(timing_file, "Time(label_all_components)", t1, t2);
    bool is_connected = gp.is_connected(g);
    cout << "Connected components: " << g->get_num_connected_components() << endl;
    //cout << "Graph is connected: " << std::boolalpha << is_connected << endl;

    run_all_methods(g, outfile, timing_file, outprefix, req_methods, file_append, spectrum_spread);
    outfile.close();
    timing_file.close();

    // some algorithms only make sense to run on a connected graph/component
    if(not is_connected and run_largest_cc){  // run everything against the other algorithms
        cout << "Graph is not connected, re-running stats on largest connected component" << endl;
        outfilename = outprefix + ".largest_component.stats";
        if(file_append == false){
            outfile.open(outfilename.c_str());
        }
        else {
            outfile.open(outfilename.c_str(), ios_base::out | ios_base::app);
        }
        if(!outfile.is_open()){
            cerr << "Error opening " << outfilename << " for writing, exiting" << endl;
            exit(1);
        }

        // get the largest component
        Graph::Graph *largest_component = gu.get_largest_component_graph(g);
        cerr << "Deleting g" << endl;
        delete(g);  // delete g here to save on memory
        cerr << "g deleted" << endl;
        if(outfile.tellp() == 0){
            #ifdef MPI_VERSION
            if(0 == myrank){
            #endif
            outfile << "largest_component_from " << infile << endl;
            outfile << "input_num_nodes " << largest_component->get_num_nodes() << endl;
            outfile << "input_num_edges " << largest_component->get_num_edges() << endl;
            #ifdef MPI_VERSION
        }
            #endif
        }
        if(record_timings){
            string of = outfilename + ".timings";
            if(file_append == false){
                timing_file.open(of.c_str());
                #ifdef MPI_VERSION
                if(0 == myrank){
                #endif
                outfile << "timing_file " << of << endl;
                #ifdef MPI_VERSION
            }
                #endif
            }
            else {
                timing_file.open(of.c_str(), ios_base::out | ios_base::app);
            }

            if(!timing_file.is_open()){
                cerr << "Error opening " << timing_file << " for writing, exiting" << endl;
                exit(1);
            }
        }
        if(lcc_apspinputfilename.length() != 0){
            cout << "Reading LCC APSP matrix from " << lcc_apspinputfilename << endl;
            vector< vector<int> > *apsp_dists = new vector< vector<int> >;
            ORB_read(t1);
            read_apsp_matrix(lcc_apspinputfilename, *apsp_dists);
            ORB_read(t2);
            print_time(timing_file, "Time(read_apsp_matrix)", t1, t2);
            largest_component->set_shortest_path_dist(apsp_dists);
        }

        outprefix = outprefix + ".largest_component";

        outfile.precision(16);
        cerr << "Running methods on largest component" << endl;
        run_all_methods(largest_component, outfile, timing_file, outprefix, req_methods, file_append, spectrum_spread);
        outfile.close();
        timing_file.close();
    }

    #ifdef MPI_VERSION
    MPI_Finalize();
    #endif

    exit(0);
} // main
Example #4
0
 virtual void SetUp(){
     LOG_INIT("test.log", NULL, 0);
     gr = new Graph::DIMACSGraphReader ();
     gr->read_graph("../data/1dc.128.txt");
 }
Example #5
0
int main(int argc, char **argv){
#if !WIN32 & !CYGWIN
    ORB_t t1, t2;

    char *intype, *outtype, *infile, *outfile;

    // Check for a cry for help
    if((argc == 1) || ((argc == 2) && (strcmp(argv[1],"-h") == 0)) || ((argc == 2) && (strcmp(argv[1],"--help") == 0))
       || ((argc == 2) && (strcmp(argv[1],"--h") == 0) ) ){
        usage(argv[0]);
        exit(0);
    }

    if(argc != 5){
        usage(argv[0]);
        exit(1);
    }

    intype = argv[1];
    outtype = argv[2];
    infile = argv[3];
    outfile = argv[4];

    Graph::Graph *g;
    int seed = 0;

    cout << "calibrating timers\n";

    ORB_calibrate();
    if(!seed){
        // Set the seed to a rand int in 0,2^24
        seed = Graph::rand_int(0,0xffffff);
    }
    // Spin the RNG seed times
    for(int ss = 0; ss < seed; ss++){
        Graph::lcgrand(0);
    }

    Graph::GraphCreatorFile *gcf;

    Graph::GraphProperties prop;
    Graph::GraphReader ngr;
    Graph::GraphWriter writer;

    g = new Graph::Graph();

    cout << "Input type : " << intype << endl;
    cout << "Output type: " << outtype << endl;
    cout << "Reading graph" << endl;
    ORB_read(t1);
    ngr.read_graph(g, infile, intype, false);
    ORB_read(t2);
    print_time("Time(read_graph)", t1, t2);

    // if we don't get rid of duplicate edges, bad things happen
    // when trying to output the graph
    //prop.make_simple(g);

    fprintf(stderr, "edges read in: %d nodes read in: %d\n", g->get_num_edges(), g->get_num_nodes());

    cout << "Writing graph\n";
    ORB_read(t1);
    writer.write_graph(g, outfile, outtype);
    ORB_read(t2);
    print_time("Time(write_graph)", t1, t2);

    return 0;
#else
	fprintf(stderr,"Can't build under Cygwin or Windows\n");
	return 1;
#endif
} // main