Esempio n. 1
0
int main(int argc, char **argv){
    if((argc != 2) || (strcmp(argv[1],"-h") == 0) || (strcmp(argv[1],"--help") == 0) ){
        usage(argv[0]);
    }

    Graph::VertexWeightedGraph *G;

    Graph::GraphCreatorFile creator;
    creator.set_file_name(argv[1]);
    creator.set_graph_type("DIMACS");
    G = creator.create_weighted_mutable_graph();
    G->complement();
    Graph::GraphWriter writer;

    char comp_DIMACS_file[200];
    char normalized_comp_DIMACS_file[200];
    sprintf(comp_DIMACS_file,"%s.comp",argv[1]);
    writer.write_graph(G,comp_DIMACS_file,"DIMACS",true,false);
    // Now normalize it
    sprintf(normalized_comp_DIMACS_file,"%s.norm",comp_DIMACS_file);
    normalize_DIMACS_file(comp_DIMACS_file,normalized_comp_DIMACS_file);
    fprintf(stderr,"Complement graph of %s written to %s in normalized DIMACS form\n",
            argv[1],normalized_comp_DIMACS_file);

    delete G;
    return 1;
} // main
Esempio n. 2
0
int main(int argc, char **argv){
    // This is a utility to generate partial k-trees with specified parameters for use in other applications.

    // 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(-1);
    }

    ORB_t t1=0, t2=0, t3=0;
    int i;
    int t = 1;
    int ktree_n = -1, ktree_k = -1, ktree_p = -1;
    int seed = 0;
    Graph::VertexWeightedGraph *G = NULL, *H = NULL;
    time_t start, stop;
    char filename[100];
    char *prefix = (char *)"pkt";
    string out_format = "DIMACS";

    bool random = false;
    bool timings = false;
    bool exact_filename = false;
    char lfname[100];
    char efname[100];
    sprintf(lfname, "genpkt.log");
    sprintf(efname, "genpkt.log");
    //0: debug, 5: critical
    LOG_INIT(lfname, efname, 0);

    // Parse arguments
    for(i = 0; i < argc; i++){
        if(strcmp(argv[i],"-t") == 0){
            t = atoi(argv[i + 1]);
        }
        if(strcmp(argv[i],"-k") == 0){
            ktree_k = atoi(argv[i + 1]);
        }
        if(strcmp(argv[i],"-n") == 0){
            ktree_n = atoi(argv[i + 1]);
        }
        if(strcmp(argv[i],"-p") == 0){
            ktree_p = atoi(argv[i + 1]);
        }
        if(strcmp(argv[i],"-o") == 0){
            out_format = string(argv[i + 1]);
        }
        if(strcmp(argv[i],"-s") == 0){
            seed = atoi(argv[i + 1]);
        }
        if(strcmp(argv[i],"-fn") == 0){
            prefix = argv[i + 1];
        }
        if(strcmp(argv[i],"-fe") == 0){
            prefix = argv[i + 1];
            exact_filename = true;
        }
        if(strcmp(argv[i],"-m") == 0){
            timings = true;
        }
        if(strcmp(argv[i],"-r") == 0){
            random = true;
        }
    }

    if((true == exact_filename) && (t != 1)){
        cerr << "Error: cannot specify both -t and -fe flags\n";
        exit(1);
    }

    if(("adjlist" != out_format) && ("dimacs" != out_format)){
        cerr << "Error: only allowed output formats are: adjlist, dimacs\n";
        exit(1);
    }

    // Spin the RNG seed times
    for(int ss = 0; ss < seed; ss++){
        Graph::lcgrand(0);
    }

    //Make sure we set all the parameters to viable values.
    if((ktree_k < 0) || (ktree_n < 0) || (ktree_p < 0)){
        fatal_error("Failed to input viable parameters for n, k, p (%d,%d,%d)\n",
                    ktree_k, ktree_n, ktree_p);
    }

    Graph::GraphCreatorFile creator;
    Graph::GraphProperties prop;
    Graph::GraphWriter writer;

    //ORB_calibrate();

    DEBUG("Graph generation loop\n");
    DEBUG("n : %d k: %d\n", ktree_n, ktree_p);
    for(i = 0; i < t; i++){
        // Create the Ktree
        //H = new Graph::Graph(ktree_n, ktree_k);
        cout << "Generating k-tree\n";
        H = creator.initialize_ktree(ktree_n, ktree_k);
        // Generate an n-node Graph G that is a partial k-tree derived from the k-tree
        start = clock();
        cout << "Deriving partial k-tree\n";
        //ORB_read(t1);
        G = creator.create_random_edge_subgraph(H, ktree_p);
        //ORB_read(t2);
        stop = clock();
        if(timings){
            print_time("Generation time", t1, t2);
        }
        fprintf(stderr,"Generated random partial k-tree (%d,%d) in %f sec.\n",
                ktree_n, ktree_k, ((double)(stop - start)) / CLOCKS_PER_SEC);
        //write it to a file
        if(!exact_filename){
            sprintf(filename, "%s.%d.%d.%d_%d.dimacs", prefix, ktree_n,ktree_k,ktree_p, i);
        }
        else {
            strncpy(filename,prefix, 99);
        }

        print_message(0,"Writing file %s\n",filename);

        //writer->set_out_file_name(filename);

        if(random){
            writer.set_shuffle(true);
            writer.set_shuffle_seed(seed);
        }

        //ORB_read(t2);
        writer.write_graph(G,filename, out_format);
        //ORB_read(t3);
        if(timings){
            print_time("Output time", t2, t3);
            print_time("Total time", t1, t3);
            cout << "Output edges: " << G->get_num_edges() << "\nOutput vertices: " << G->get_num_nodes();
            cout << "\nOutput format: " << out_format << "\nOutput filename: " << filename << "\n";
        }

        delete G;
        delete H;
    }

    LOG_CLOSE();
    exit(0);
} // main
Esempio n. 3
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
Esempio n. 4
0
int main(int argc, char **argv)
{
    // This is a utility to generate partial k-trees with specified parameters for use in other applications.

    // 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(-1);
    }

    int i;
    int t = 1;
    int ktree_n=-1, ktree_k=-1, ktree_p=-1;
    int seed=0;
	Graph::WeightedMutableGraph *G=NULL, *H=NULL; 
    time_t start, stop;
    char filename[100];
    char *prefix= (char *)"pkt";
    
    bool random = false, write_scotch=false;
    char lfname[100];
    char efname[100];
    sprintf(lfname, "genpkt.log");
    sprintf(efname, "genpkt.log");
    //0: debug, 5: critical
    LOG_INIT(lfname, efname, 0);

    // Parse arguments
    for(i=0;i<argc;i++)
    {
        if(strcmp(argv[i],"-t")==0)
        {
            t=atoi(argv[i+1]);
        }
        if(strcmp(argv[i],"-k")==0)
        {
            ktree_k=atoi(argv[i+1]);
        }
        if(strcmp(argv[i],"-n")==0)
        {
            ktree_n=atoi(argv[i+1]);
        }
        if(strcmp(argv[i],"-p")==0)
        {
            ktree_p=atoi(argv[i+1]);
        }
        if(strcmp(argv[i],"-s")==0)
        {
            seed=atoi(argv[i+1]);
        }
        if(strcmp(argv[i],"-fn")==0)
            prefix = argv[i+1];
        if(strcmp(argv[i],"-r")==0)
            random = true;
        if(strcmp(argv[i],"-scotch")==0)
            write_scotch = true;
    }

    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);

    //Make sure we set all the parameters to viable values. 
    if(ktree_k < 0 || ktree_n < 0 || ktree_p < 0)
	{
	    fatal_error("Failed to input viable parameters for n, k, p (%d,%d,%d)\n",
            ktree_k, ktree_n, ktree_p);
	}
    
    Graph::GraphCreatorFile creator;
    Graph::GraphWriter *writer;
    Graph::GraphReaderWriterFactory rwf;
    Graph::GraphProperties prop;

    writer = rwf.create_writer("DIMACS", "t");

    DEBUG("Graph generation loop\n");
    DEBUG("n : %d k: %d\n", ktree_n, ktree_p);
    for(i = 0; i < t; i++)
    {
	    // Create the Ktree
	    //H = new Graph::Graph(ktree_n, ktree_k);
        H = creator.initialize_ktree(ktree_n, ktree_k);
	    // Generate an n-node Graph G that is a partial k-tree derived from the k-tree
	    start=clock();
	    G= creator.create_random_edge_subgraph(H, ktree_p);
	    stop=clock();
	    fprintf(stderr,"Generated random partial k-tree (%d,%d) in %f sec.\n",
		   ktree_n, ktree_k, ((double)(stop-start))/CLOCKS_PER_SEC);
	    //write it to a file
	    sprintf(filename, "%s.%d.%d.%d_%d.dimacs", prefix, ktree_n,ktree_k,ktree_p, i);
        print_message(0,"Writing file %s\n",filename);

        writer->set_out_file_name(filename);

        if (random)
            writer->shuffle(G, seed);

        writer->write_graph(G);

 	    delete G; 
	    delete H; 
	}

    LOG_CLOSE();
    return 0;
}