Ejemplo n.º 1
0
int main(int argc, char** argv) {
    GRAPH_L_ADJ graph;

    if (argc != 2) {
        printf("%s\n", "Veuillez specifier un fichier de graphe.");
        exit(-1);
    }

    graph = load_graph(argv[1]);

    //Marquage topologique
    printf("Nombre de predecesseur de chacun des noeuds du graphe : \n");
    for (int i = 0; i < graph.nbSom; i++) {
        printf("Noeud %d : %d\n", i, graph.predNumber[i]);
    }
    printf("\n");

    QUEUE_INT topologicalQueue = topologicalMarking(&graph);

    computeEarlyDate(&graph); //fournir date au plus tot
    computeLateDate(&graph); //date au plus tard
    computeTolerances(&graph); //marge de toutes les taches
    computeCritacalTasks(&graph, topologicalQueue); //liste des taches critiques
    //date de fin de travaux
    printf("Date de fin des travaux : %d\n", graph.nodeTab[graph.nbSom - 1]->lateDate); //Date au plus tard de omega.

    free(graph.predNumber);
    free(graph.nodeTab);
    free(graph.predTab);
    free(graph.succTab);

    return 0;
}
Ejemplo n.º 2
0
void test_core_layout(){
	int radius = 5, width=1;
	graph_t *g = load_graph("datasets/email/edges.txt", false);
	int n = graph_num_vertices(g);
	
	coord_t *p = malloc(n * sizeof(*p));
	graph_layout_core_shell(g, width+radius, true, p);
	
	color_t solid_red = {255, 0, 0, 255};
	color_t black     = {0,   0, 0, 255};
	
	circle_style_t point_style;
	point_style.radius = radius;
	point_style.width = width;
	color_copy(point_style.fill, solid_red);
	color_copy(point_style.stroke, black);
	
	path_style_t edge_style;
	edge_style.width = width;
	color_copy(edge_style.color, black);
	
	graph_print_svg_one_style("test/test_core_layout.svg", 0, 0, g, p, 
	                          point_style, edge_style);
	
	free(p);
	delete_graph(g);
}
Ejemplo n.º 3
0
//----------------------------------------------------------------------
//----------------------------------------------------------------------
Graph::Graph(const std::string& fname) {
	// init members
	graph_fname = fname;
	// load graph as is
	load_graph();
	// update label
	label = fname.substr(fname.find_last_of("/") + 1);
	label = label.substr(0, label.find_first_of("_"));
}
Ejemplo n.º 4
0
void setup()
{
	if (setup_done) {
		return;
	}

	graph = &the_graph;
	vertices = &graph->vertices[0];
	q = the_queue;

	load_graph("example.graph", &parse_simple_space_delimited_line, graph);

	setup_done = TRUE;
}
Ejemplo n.º 5
0
int main(int argc, char** argv) {
    if (argc == 2) {
        char* filename = argv[1];
        printf("Carregando...\n");
        Graph* graph = load_graph(filename);
        printf("Arquivo aberto: \"%s\".\n", filename);
        int node_count = graph->node_count;
        int edge_count = 0;
        printf("%d vertices encontrados.\n", node_count);
        for (int i = 0; i < node_count; i++) {
            for (int j = 0; j < node_count; j++) {
                if (contains_edge(graph, i, j)) {
                    edge_count++;
                }
                /*if(j == 0){
                        printf("Total edges found = %7d; checking edges from node %5d\r", edge_count >> 1, i);
                }*/
            }
        }
        printf("%d arestas encontradas.\n", edge_count >> 1);
        create_general_options(graph);
        return (EXIT_SUCCESS);
    } else {
Ejemplo n.º 6
0
/* Load the the command line options into opts */
static Options load_options(int argc, char *argv[]) {
    /* Uses the built-in C standard library function getopt to process the
     * command line arguments. */
    extern char *optarg;
    extern int optind;
    int c;
    Options opts = {
        .sort   = NONE,
        .method = NULL,
        .verify = false,
        .print  = false,
        .output = NULL,
        .exe    = argv[0],
        .input  = NULL,
    };

    while ((c = getopt(argc, argv, "m:ap:v")) != -1) {
        switch (c) {
        case 'm':
            opts.sort = atoi(optarg);
            switch (opts.sort) {
                case DFS : opts.method = "DFS" ; break;
                case KAHN: opts.method = "Kahn"; break;
                default:
                    fprintf(stderr, "Unrecognised sort method\n");
                    usage_exit(opts.exe);
            }
            break;
        case 'p':
            opts.print = true;
            opts.output = optarg;
            break;
        case 'v': opts.verify = true;  break;
        case '?':
        default: usage_exit(opts.exe);
        }
    }

    /* Check that one of -p, -m or -v is specified. */
    if (!(opts.print || opts.sort || opts.verify)) {
        fprintf(stderr, "One of -p, -v or -m must be specified\n");
        usage_exit(opts.exe);
    }

    /* Check that only one of -m or -v is specified. */
    if (opts.sort && opts.verify) {
        fprintf(stderr, "Only one of -v or -m may be specified\n");
        usage_exit(opts.exe);
    }

    /* Check that input is specified. */
    if (optind + 1 > argc) {
        fprintf(stderr, "Missing input file\n");
        usage_exit(opts.exe);
    } else {
        opts.input = argv[optind];
    }

    return opts;
}

/* Main driver for the program */
int main(int argc, char *argv[]) {
    List sorted = NULL;
    Options opts = load_options(argc, argv);
    Graph graph = load_graph(opts.input);

    if (opts.print)
        print_graph(opts.output, graph);

    clock_t start = clock();
    switch (opts.sort) {
        case DFS : sorted =  dfs_sort(graph); break;
        case KAHN: sorted = kahn_sort(graph); break;
    }
    clock_t end = clock();

    if (sorted) {
        char *performance = "%s sort: %d vertices, %d edges, %ld clock ticks\n";
        fprintf(stderr
                , performance
                , opts.method
                , graph->order
                , graph->size
                , end - start);

        print_list(print_vertex_id, stdout, sorted);
    }

    if (opts.verify) {
        sorted = load_vertex_sequence(stdin, graph);

        const char *sort_succ = "Valid topological ordering\n";
        const char *sort_fail = "Invalid topological ordering\n";
        printf(verify(graph, sorted) ? sort_succ : sort_fail);
    }

    free_list(sorted);
    free_graph(graph);

    exit(EXIT_SUCCESS);
}
void run(context_t& ctx, bool directed) {
    bool is_master = ctx.dc.procid() == 0;
    timer_start(is_master);

#ifdef GRANULA
    granula::operation powergraphJob("PowerGraph", "Id.Unique", "Job", "Id.Unique");
    granula::operation loadGraph("PowerGraph", "Id.Unique", "LoadGraph", "Id.Unique");
    if(is_master) {
        cout<<powergraphJob.getOperationInfo("StartTime", powergraphJob.getEpoch())<<endl;
        cout<<loadGraph.getOperationInfo("StartTime", loadGraph.getEpoch())<<endl;
    }
#endif

    // process parmaeters
    global_directed = directed;

    // load graph
    timer_next("load graph");
    graph_type graph(ctx.dc);
    load_graph(graph, ctx);
    graph.finalize();

#ifdef GRANULA
    if(is_master) {
        cout<<loadGraph.getOperationInfo("EndTime", loadGraph.getEpoch())<<endl;
    }
#endif

    // start engine
    timer_next("initialize engine");
    graphlab::omni_engine<triangle_count> engine(ctx.dc, graph, "synchronous", ctx.clopts);
    engine.signal_all();

#ifdef GRANULA
    granula::operation processGraph("PowerGraph", "Id.Unique", "ProcessGraph", "Id.Unique");
    if(is_master) {
        cout<<processGraph.getOperationInfo("StartTime", processGraph.getEpoch())<<endl;
    }
#endif

    // run algorithm
    timer_next("run algorithm");
    engine.start();

#ifdef GRANULA
    if(is_master) {
        cout<<processGraph.getOperationInfo("EndTime", processGraph.getEpoch())<<endl;
    }
#endif

#ifdef GRANULA
    granula::operation offloadGraph("PowerGraph", "Id.Unique", "OffloadGraph", "Id.Unique");
    if(is_master) {
        cout<<offloadGraph.getOperationInfo("StartTime", offloadGraph.getEpoch())<<endl;
    }
#endif

    // print output
    if (ctx.output_enabled) {
        timer_next("print output");
        vector<pair<graphlab::vertex_id_type, vertex_data_type> > data;
        collect_vertex_data(graph, data, is_master);

        for (size_t i = 0; i < data.size(); i++) {
            (*ctx.output_stream) << data[i].first << " " << data[i].second.clustering_coef << endl;
        }
    }

    timer_end();

#ifdef GRANULA
    if(is_master) {
        cout<<offloadGraph.getOperationInfo("EndTime", offloadGraph.getEpoch())<<endl;
        cout<<powergraphJob.getOperationInfo("EndTime", powergraphJob.getEpoch())<<endl;
    }
#endif

}
Ejemplo n.º 8
0
int main(int argc, char* argv[]){
  load_graph("");
  return 0;
}
Ejemplo n.º 9
0
int main(int argc, char* argv[])
{
	vis_graph g;

    load_graph(::g_filename + ".co", g);
    load_graph(::g_filename + ".gr", g);
    
    ::omp_set_num_threads(::g_nthreads);
    size_t real_nthreads = ::omp_get_max_threads();
    size_t offset = (g.v_count() + real_nthreads - 1) / real_nthreads;

#pragma omp parallel
    {
        size_t threadid = ::omp_get_thread_num();
        calculate_reaches (g, offset*threadid, std::min(offset*(threadid+1), g.v_count()), threadid);
    }


/*
    for (size_t i = 0; i < verts_arr.size(); ++i) 
    {
        calculate_reach(g, verts_arr[i], reaches);
        std::cout << "Visiting " << i << "...\n";
    }

    for (size_t i = 0; i < verts_arr.size(); ++i) 
    {
        std::cout << "Reach for " << i << ": " << reaches[verts_arr[i]] << "\n";
    }
*/

/*
    for (int i=0; i<100; ++i)
    {
        my_graph::vertex_id vid = (rand()*RAND_MAX + rand()) % g.v_count();
        std::cout << "Vertex: " << vid << "\n";

        calculate_reach (g, vid);
    }
*/
    
    //std::cout << "max depth: " << depth << "\n";
/*
    const size_t thread_size = 100;
    #pragma omp parallel num_threads(2)
    {
        const size_t thread_id = ::omp_get_thread_num ();
        const size_t offset = thread_size * thread_id;
        for (size_t i = offset; i < offset + thread_size && i < verts_arr.size(); ++i)
        {
            calculate_reach (g, verts_arr[i]);
            if ((i-offset) % 10 == 0)
            {
                #pragma omp critical
                {
                    std::cout << thread_id << ": " << i << "\n";
                }

            }

        }
    }
*/

    return 0;
}