Beispiel #1
0
static void lavfi_process(struct mp_filter *f)
{
    struct lavfi *c = f->priv;

    if (!c->initialized)
        init_graph(c);

    while (c->initialized) {
        bool a = read_output_pads(c);
        bool b = feed_input_pads(c);
        if (!a && !b)
            break;
    }

    // Start over on format changes or EOF draining.
    if (c->draining_recover) {
        // Wait until all outputs got EOF.
        bool all_eof = true;
        for (int n = 0; n < c->num_out_pads; n++)
            all_eof &= c->out_pads[n]->buffer_is_eof;

        if (all_eof) {
            MP_VERBOSE(c, "recovering all eof\n");
            free_graph(c);
            mp_filter_internal_mark_progress(c->f);
        }
    }

    if (c->failed)
        mp_filter_internal_mark_failed(c->f);
}
Beispiel #2
0
static void
freeChannel (Dt_t* d, channel* cp, Dtdisc_t* disc)
{
    free_graph (cp->G);
    free (cp->seg_list);
    free (cp);
}
Beispiel #3
0
graph_t * new_graph (unsigned int n, char **lbl){

graph_t *grafo;
unsigned int i;

if( (n <= ZERO) || !lbl || !check_node(lbl,n)) {
					errno = EINVAL; 
		   			return NULL; }

MALLOC_IF(grafo, sizeof(graph_t), UNO) 


if( !( MALLOC(grafo->node, sizeof(node_t), n)) ) {
					free(grafo);						
					return NULL; }

grafo->size = n;				 

for(i = ZERO; i<n; i++){
	((grafo-> node)+i) -> adj = NULL;
	if( !( MALLOC( ((grafo-> node)+i)->label, sizeof(char), LLABEL+UNO ) ) ){
									free_graph(&grafo);	
									return NULL; }						 
	
	strcpy( (((grafo-> node)+i) -> label) , lbl[i]); 
		}

return grafo;	
}
Beispiel #4
0
static void
print_graph(intf_t *i)
{
	int w;

	graph_t *g = create_configued_graph(&i->i_bytes_hist, c_graph_height);

	printf("%s\n", i->i_name);

	printf("RX   %s\n", g->g_rx.t_y_unit);
	
	for (w = (c_graph_height - 1); w >= 0; w--)
		printf("%8.2f %s\n", g->g_rx.t_y_scale[w], (char *) g->g_rx.t_data + (w * (HISTORY_SIZE + 1)));
	
	printf("         1   5   10   15   20   25   30   35   40   " \
		"45   50   55   60 %s\n", g->g_rx.t_x_unit);

	printf("TX   %s\n", g->g_tx.t_y_unit);
	
	for (w = (c_graph_height - 1); w >= 0; w--)
		printf("%8.2f %s\n", g->g_tx.t_y_scale[w], (char *) g->g_tx.t_data + (w * (HISTORY_SIZE + 1)));
	
	printf("         1   5   10   15   20   25   30   35   40   " \
		"45   50   55   60 %s\n", g->g_tx.t_x_unit);

	free_graph(g);
}
Beispiel #5
0
void release_graph (GRAPH** gr)
{
   assert(gr != NULL);
   assert(*gr != NULL);
   (*gr)->nuses--;
   if( (*gr)->nuses == 0 )
      free_graph(gr);
   *gr = NULL;
}
Beispiel #6
0
static void lavfi_reset(struct mp_filter *f)
{
    struct lavfi *c = f->priv;

    free_graph(c);

    for (int n = 0; n < c->num_in_pads; n++)
        mp_frame_unref(&c->in_pads[n]->pending);
}
int main(int argc,char *argv[]) {


	int num_houses,num_schools;
	int u,v,weight;
	

	if(scanf("%d %d",&num_houses,&num_schools) != 2) {
		printError();
	}

	
	Graph *g = graph_new(num_houses+num_schools);
	g->num_houses = num_houses;
	g->num_schools = num_schools;
	g->number_of_vertices = num_houses+num_schools;

	while(scanf("%d %d %d",&u,&v,&weight) == 3) {

		if(u < 0 || v < 0 
		|| u>=(g->number_of_vertices) || v>=(g->number_of_vertices) || weight < 0){
			printError();
		}
		else {
			// the 0 represents unvisted 
			graph_add_edge(g,u,v,0);
			graph_add_edge(g,v,u,0);
			//adding weights 
			g->vertices[u].edges[g->vertices[u].num_edges-1].weight = weight;
			g->vertices[v].edges[g->vertices[v].num_edges-1].weight = weight;
		}

	}
	// checking if graph is connected 
	if(!graph_check_connected(g,0)) {
		fprintf(stderr, "Graph is not connected\n");
		exit(EXIT_FAILURE);
	}

	
	Universe *Uni = create_all_sets(g->num_schools,g->num_houses);

	//running Dijkstra on each school vertex
	for(int i=num_houses;i<g->number_of_vertices;i++) {

		Dijkstra(g,i,Uni,min_func);

	}

	setCover(Uni,g->num_houses);



	free_graph(g);
	
	return 0;
}
Beispiel #8
0
/**
 * Resize method that calls Dijkstra algorithm for each Vertex inside
 * the Vertexes set of the Graph
 */
void graph_shortest_path(PPMImage *image, int *path)
{
    Graph graph;
    init_graph(&graph, image);
    pri_queue_t priq_s;
    priq_init(&priq_s, graph.list_size);

    int i, x, y, dest;
    Energy *distance = calloc(graph.list_size, sizeof(Energy));
    int *previous = calloc(graph.list_size, sizeof(int));
    Energy shortest_distance;
    shortest_distance = ENERGY_MAX;

    for(x = 0; x < image->width; x++)
    {
        i = XY2POS(image, x, image->height - 1);

        dest = dijkstra(&graph, i, &priq_s,
                distance, previous, shortest_distance);

#ifdef OPT_GRAPH_SHORTEST_PATH_BREAK
        if(dest == BREAK)
            continue;
        else
#endif
            if(dest < 0)
            {
                fprintf(stderr, "There is no path\n");
                exit(EXIT_FAILURE);
            }

        if (distance[dest] < shortest_distance)
        {
            shortest_distance = distance[dest];
            y = 0;
            while(dest != i)
            {
                path[y++] = POS2X(dest, image);
                dest = previous[dest];
            }
            path[y] = POS2X(i, image);
            // assert path length
            ASSERT_TRUE(y == image->height - 1,
                    fprintf(stderr,
                            "ASSERT: Path length error (must to be %d): %d\n",
                            image->height - 1, y)
            );
        }
    }

    priq_free(&priq_s);
    free_graph(&graph);
    free(distance);
    free(previous);
}
Beispiel #9
0
void free_graph(graph_elem_t graph) {
    graph_elem_t tmp;

    while(graph != NULL) {
	free_graph(graph->neighbours_head);

	tmp = graph->neighbour_next;
	free(graph->id);
	free(graph);
	graph = tmp;
    }
}
Beispiel #10
0
int silent_list_all_chains(Graph* graph)
{
    int total = 0, i;
    Graph* copy = make_graph_copy(graph);

    for(i = 0; i < graph->verts; i++)
        total += silent_find_chains_from(copy, copy->vertex_list[i].id);

    free_graph(&copy);

    return total;
}
Beispiel #11
0
void free_board (Board *b)
{
  if (b->graph)
    free_graph(b->graph);
  if (b->moves)
    free(b->moves);
  if (b->level_title)
    free(b->level_title);
  if (b->collection_title)
    free(b->collection_title);
  free(b);
}
Beispiel #12
0
int main(int argc, char **argv)
{
    int **graph; /// graph in a whole
    int **wccs;
    int ret = -EINVAL; /// returned value
    int fd = 0;
    timeval begin, end;
    //    fd = open("sample_data6.txt", O_RDONLY);

    if (argv[1] &&
            (strcmp(argv[1], "-h") || strcmp(argv[1], "--help")))
        goto exit_help;

    ret = read_graph(fd, &graph);
    close(fd);
    if (ret < 0)
        goto exit_help;

    gettimeofday(&begin, NULL);

    wccs = generate_wccs(graph, ret);
    if (!wccs) {
        ret = -EINVAL;
        goto out;
    }

    gettimeofday(&end, NULL);
    saveResults(begin, end, get_number_vertices(graph), get_number_edges(graph));

    //    print_graph(wccs);

    free_graph(wccs);
out:
    free_graph(graph);
    return ret;
exit_help:
    print_help();
    return ret;
}
Beispiel #13
0
Graph* get_best_candidate(Graph** candidates, int candidates_len, char** conflict_vt, 
        int conflict_len, int* best_cost){
    Graph* best = NULL;
    int conflict_best = INT_MAX;
    for (int i = 0; i < candidates_len; i++){
        if (candidates[i] == NULL) continue;
        
        int conflict_c = conflict_cost(candidates[i], conflict_vt, conflict_len);
        
        if (best == NULL){
            best = candidates[i];
            conflict_best = conflict_c;
        }
        else if (conflict_best > conflict_c){
            free_graph(best);
            best = candidates[i];
            conflict_best = conflict_c;
        }
        else free_graph(candidates[i]);
    }
    *best_cost = conflict_best;
    return best;
}
Beispiel #14
0
void free_metric(void)
{
  long i;

  for (i = 0; i < n; i++) {
    if (visited[i]) {
      VEC_DESTROY(*ancestors[i]);
      free(ancestors[i]);
    }
  }
  free(ancestors);
  free(depth);
  free(visited);
  free_graph(&gi);
}
Beispiel #15
0
int main(void)
{
    struct graph * graph = initialiser_Graph();

    analyse_cmd(graph, "load test_files/test.gv");
    analyse_cmd(graph, "show topology");
    analyse_cmd(graph, "add link N1 N4 5");
    analyse_cmd(graph, "del link N1 N4");
    analyse_cmd(graph, "disconnect N3");
    analyse_cmd(graph, "update link N1 N2 1");
    analyse_cmd(graph, "save Topology2.txt");

    free_graph(graph);

    return 0;
}
Beispiel #16
0
int		main(int ac, char **av)
{
  t_pars	*parser;

  if (ac < 2)
    return (my_put_error(USAGE), 1);
  if (!(parser = recup_graph(av[1])))
    return (1);
  if (!solve_by_length(parser->cas, parser->width))
    {
      free_graph(parser);
      return (0);
    }
  free(parser);
  return (1);
}
Beispiel #17
0
int
main(int argc, char *argv[])
{
  UINT i;

  unsigned int N;
  UINT NSTATES;

  unsigned int rule;
  CA *ca;

  char *graph;

  if (argc != 3)
  {
    fprintf(stderr, "usage: %s rule ca-size\n", PROGRAM_NAME);
    exit(EXIT_FAILURE);
  }

  sscanf(argv[1], "%u", &rule);

  sscanf(argv[2], "%u", &N);

  if (DEBUG)
    fprintf(stderr, "rule %u\nN=%u\n", rule, N);

  ca = ca_create(N, rule);

  NSTATES =  2;
  NSTATES <<= (N - 1);

  graph = create_graph(NSTATES);

  for (i = 0; i < NSTATES; ++i)
    flags_unset(graph, i, STATE_ALL_SET_MASK);

  for (i = 0; i < NSTATES; ++i)
    if (!flags_test(graph, i, STATE_HAS_BEEN_VISITED))
      search_cycle(ca, graph, i);

  free_graph(graph);
  ca_destroy(ca);

  return EXIT_SUCCESS;
}
Beispiel #18
0
graph_t *  copy_graph (graph_t *g){

graph_t *newg = NULL;
char **app;	/* array di stringhe per la chiamata a new_graph */
int i, j, error = FALSE;

if( !g ){	/* se il grafo da copiare non esiste è inutile continuare */
     errno = EINVAL; 
     return NULL; }

if( !(g->node) ){
	MALLOC_IF( newg, sizeof(graph_t), UNO)
	
	newg->size = g->size;
	return newg; }

MALLOC_IF( app, sizeof(char *), g->size)

for(i = ZERO; i < (g->size); i++){		
	if( !(MALLOC( app[i], sizeof(char), LLABEL) ) ){
				for(j = ZERO; j < i; j++)
						free(app[j]);
				free(app);  
				return NULL; }
	
	strcpy( app[i], ((g->node)+i)->label );  }
						

if( (newg = new_graph(g->size,app)) ){	/* se la copia del grafo (copia dell'array di nodi) avviene con successo */
			
		if( !(newg = copy_adj(newg,g)) ){		/* faccio una copia delle liste di adiacenza di g */
						error = TRUE;	
						free_graph(&newg); }   /*  per non lasciare a metà la copia del grafo*/						
						
						}

for(i = ZERO; i < (g->size); i++)	/* app non mi serve più */
			free(app[i]);
free(app);

if(error)
	return NULL;
 	
return newg;
}
Beispiel #19
0
void * run_program(void * program_stat)
{
	graph_t c_graph;
	int memkey, i;
	status client_program;
	process_t process_type;
	mstack_t instruction_stack;
	
	thread_status_t thread_info = (thread_status_t)program_stat;

	instruction_stack = parse_file((char*)thread_info->file);	

	if (instruction_stack != NULL){
	
		c_graph = build_graph(instruction_stack);

		if (c_graph != NULL)
		{
			create_sh_graph(c_graph, get_graph_size(c_graph), 
							&memkey, &client_program.g_header);
			client_program.cursor = 0;
			client_program.flag = FALSE;
			client_program.client_id = thread_info->client_id;
			
			for(i = 0; i < MEM_SIZE; i++){
				client_program.mem[i] = 0;
			}
			
			process_type = c_graph->first->instruction_process->instruction_type;
			client_program.mtype = process_type->params->unique_mq_id;
			free_graph(c_graph);
			free_stack(instruction_stack);
			printf("Sending first instruction...\n");
			ipc_send(process_type->params, &client_program, sizeof(struct status));
		}else{
			answer_error_to_client(UNABLE_TO_BUILD_GRAPH, thread_info->client_id); 
		}
	}else{
		
		answer_error_to_client(errno, thread_info->client_id);
		errno = 0;
	}
	pthread_exit(NULL);
}
Beispiel #20
0
static void __draw_graphic(stat_attr_hist_t *a, int selected, int xunit)
{
	int w;
	graph_t *g;
	g = create_configued_graph(&a->a_hist, c_graph_height, a->a_unit, xunit);

	NEXT_ROW;
	putl("RX    %s                        [%s]",
	     g->g_rx.t_y_unit, type2desc(a->a_type));

	if (selected) {
		move(row, 72);
		attron(A_BOLD);
		addstr("(sel)");
		attroff(A_BOLD);
		move(row, 0);
	}

	for (w = (c_graph_height - 1); w >= 0; w--) {
		NEXT_ROW;
		putl(" %8.2f %s\n", g->g_rx.t_y_scale[w], (char *) g->g_rx.t_data + (w * (HISTORY_SIZE + 1)));
	}

	move(row, 71);
	putl("[%.2f%%]", rtiming.rt_variance.v_error);
	NEXT_ROW;
	putl("          1   5   10   15   20   25   30   35   40   45   50   55   60 %s", g->g_rx.t_x_unit);

	NEXT_ROW;
	putl("TX    %s", g->g_tx.t_y_unit);

	for (w = (c_graph_height - 1); w >= 0; w--) {
		NEXT_ROW;
		putl(" %8.2f %s\n", g->g_tx.t_y_scale[w], (char *) g->g_tx.t_data + (w * (HISTORY_SIZE + 1)));
	}

	move(row, 71);
	putl("[%.2f%%]", rtiming.rt_variance.v_error);
	NEXT_ROW;
	putl("          1   5   10   15   20   25   30   35   40   45   50   55   60 %s", g->g_tx.t_x_unit);

	free_graph(g);
}
void free_hashtable(struct hashtable *h)
{
	unsigned int i;

	for (i = 0; i < h->currentsize; ++i)
	{
		struct hashnode *chain = h->buckets[i];
		while (chain != h->sentinels[i])
		{
			struct hashnode *tmp = chain->next;
			if (chain->string)
			{
				free(chain->string);
				chain->string = NULL;
			}
			free_graph(chain->data);
			chain->data = NULL;
			free(chain);
			chain = tmp;
		}
		free(h->sentinels[i]);
		h->sentinels[i] = NULL;
	}

	/* free the dummy heads and sentinels that the table
	 * doesn't currently use - it doubles bucket count
	 * every time the "load" gets too high */
	for (i = h->currentsize; i < h->allocated; ++i)
	{
		free(h->buckets[i]);
		h->buckets[i] = NULL;
		free(h->sentinels[i]);
		h->sentinels[i] = NULL;
	}

	free(h->buckets);
	free(h->sentinels);
	h->buckets = NULL;
	h->sentinels = NULL;

	free(h);
	h = NULL;
}
Beispiel #22
0
void free_ir_graph(ir_graph *irg)
{
	assert(irg->kind == k_ir_graph);

	remove_irp_irg(irg);
	confirm_irg_properties(irg, IR_GRAPH_PROPERTIES_NONE);

	free_irg_outs(irg);
	del_identities(irg);
	if (irg->ent) {
		set_entity_irg(irg->ent, NULL);  /* not set in const code irg */
	}

	free_End(get_irg_end(irg));
	obstack_free(&irg->obst, NULL);
	if (irg->loc_descriptions)
		free(irg->loc_descriptions);
	irg->kind = k_BAD;
	free_graph(irg);
}
Beispiel #23
0
static void
draw_graphic(void)
{
	int w;
	graph_t *g;
	intf_t *intf = get_current_intf();

	if (NULL == intf)
		return;
	
	g = create_configued_graph(&intf->i_bytes_hist, c_graph_height);

	NEXT_ROW;
	putl("RX    %s", g->g_rx.t_y_unit);

	for (w = (c_graph_height - 1); w >= 0; w--) {
		NEXT_ROW;
		putl(" %8.2f %s\n", g->g_rx.t_y_scale[w], (char *) g->g_rx.t_data + (w * (HISTORY_SIZE + 1)));
	}

	move(row, 71);
	putl("[%.2f%%]", rtiming.rt_variance.v_error);
	NEXT_ROW;
	putl("          1   5   10   15   20   25   30   35   40   45   50   55   60 %s", g->g_rx.t_x_unit);

	NEXT_ROW;
	putl("TX    %s", g->g_tx.t_y_unit);

	for (w = (c_graph_height - 1); w >= 0; w--) {
		NEXT_ROW;
		putl(" %8.2f %s\n", g->g_tx.t_y_scale[w], (char *) g->g_tx.t_data + (w * (HISTORY_SIZE + 1)));
	}

	move(row, 71);
	putl("[%.2f%%]", rtiming.rt_variance.v_error);
	NEXT_ROW;
	putl("          1   5   10   15   20   25   30   35   40   45   50   55   60 %s", g->g_tx.t_x_unit);

	free_graph(g);
}
Beispiel #24
0
// Initialize the graph if all inputs have formats set. If it's already
// initialized, or can't be initialized yet, do nothing.
static void init_graph(struct lavfi *c)
{
    assert(!c->initialized);

    if (!c->graph)
        precreate_graph(c, false);

    if (init_pads(c)) {
        struct mp_stream_info *info = mp_filter_find_stream_info(c->f);
        if (info && info->hwdec_devs) {
            struct mp_hwdec_ctx *hwdec = hwdec_devices_get_first(info->hwdec_devs);
            for (int n = 0; n < c->graph->nb_filters; n++) {
                AVFilterContext *filter = c->graph->filters[n];
                if (hwdec && hwdec->av_device_ref)
                    filter->hw_device_ctx = av_buffer_ref(hwdec->av_device_ref);
            }
        }

        // And here the actual libavfilter initialization happens.
        if (avfilter_graph_config(c->graph, NULL) < 0) {
            MP_FATAL(c, "failed to configure the filter graph\n");
            free_graph(c);
            c->failed = true;
            mp_filter_internal_mark_failed(c->f);
            return;
        }

        // The timebase is available after configuring.
        for (int n = 0; n < c->num_out_pads; n++) {
            struct lavfi_pad *pad = c->out_pads[n];

            pad->timebase = pad->buffer->inputs[0]->time_base;
        }

        c->initialized = true;

        if (!c->direct_filter) // (output uninteresting for direct filters)
            dump_graph(c);
    }
}
/*
 * Computes the longest path on a directed graph
 */
ll_node* longest_path_da(graph* g,int* len_dest) {

   graph* f = flip(g);
   ll_node* cyc = cycles(g);
   cycle_counter counter = build_cycle_counter(cyc,g,f);
   init_cut_cycles(counter,g,f);



   int best_len = -1;
   ll_node* best_path = NULL;

   do {
      printf("g: \n");
      print_graph(g);
      printf("\nf: \n");
      print_graph(f);
      printf("\ncycle_counter: \n");
      print_cycle_counter(counter);
      printf("\n\n");

      int new_len;
      ll_node* new_path = longest_path_dag(g,f,&new_len);

      if(new_len > best_len) {
         free_ll(best_path);
         best_len = new_len;
         best_path = new_path;
      }
   } while(inc_cycles(counter,g,f));

   *len_dest = best_len;

   free_cycle_counter(counter);
   free_ll(cyc);
   free_graph(f);

   return best_path;
}
Beispiel #26
0
static void __print_graph(stat_attr_t *a, void *arg)
{
	item_t *i = (item_t *) arg;
	stat_attr_hist_t *h;
	graph_t *g;
	int w;

	if (!(a->a_flags & ATTR_FLAG_HISTORY))
		return;

	h = (stat_attr_hist_t *) a;

	g = create_configued_graph(&h->a_hist, c_graph_height,
				    h->a_unit, get_x_unit());

	printf("Item: %s\nAttribute: %s\n", i->i_name, type2desc(a->a_type));

	printf("RX   %s\n", g->g_rx.t_y_unit);
	
	for (w = (c_graph_height - 1); w >= 0; w--)
		printf("%8.2f %s\n", g->g_rx.t_y_scale[w],
		    (char *) g->g_rx.t_data + (w * (HISTORY_SIZE + 1)));
	
	printf("         1   5   10   15   20   25   30   35   40   " \
		"45   50   55   60 %s\n", g->g_rx.t_x_unit);

	printf("TX   %s\n", g->g_tx.t_y_unit);
	
	for (w = (c_graph_height - 1); w >= 0; w--)
		printf("%8.2f %s\n", g->g_tx.t_y_scale[w],
		    (char *) g->g_tx.t_data + (w * (HISTORY_SIZE + 1)));
	
	printf("         1   5   10   15   20   25   30   35   40   " \
		"45   50   55   60 %s\n", g->g_tx.t_x_unit);

	free_graph(g);
}
Beispiel #27
0
int main(int argc, char** argv) {
	
	// parse command line options
	Options options = get_options(argc, argv);

	// build graph from data file
	Graph* graph = read_graph(options.filename);

	// validate vertex ids now that we know graph size
	validate_vertex_ids(options, graph->n);

	// branch to relevant function depending on execution mode
	switch (options.part) {
		case PRINT_DFS:
			print_dfs(graph, options.source);
			break;
		case PRINT_BFS:
			print_bfs(graph, options.source);
			break;
		case DETAILED_PATH:
			detailed_path(graph, options.source, options.dest);
			break;
		case ALL_PATHS:
			all_paths(graph, options.source, options.dest);
			break;
		case SHORTEST_PATH:
			shortest_path(graph, options.source, options.dest);
			break;
	}

	// clean up
	free_graph(graph);

	// done!
	exit(EXIT_SUCCESS);
}
Beispiel #28
0
void 
coarsen (
/* Coarsen until nvtxs <= vmax, compute and uncoarsen. */
    struct vtx_data **graph,	/* array of vtx data for graph */
    int nvtxs,		/* number of vertices in graph */
    int nedges,		/* number of edges in graph */
    int using_vwgts,		/* are vertices weights being used? */
    int using_ewgts,		/* are edge weights being used? */
    float *term_wgts[],		/* terminal weights */
    int igeom,		/* dimension for geometric information */
    float **coords,		/* coordinates for vertices */
    double **yvecs,		/* eigenvectors returned */
    int ndims,		/* number of eigenvectors to calculate */
    int solver_flag,		/* which eigensolver to use */
    int vmax,			/* largest subgraph to stop coarsening */
    double eigtol,		/* tolerence in eigen calculation */
    int nstep,		/* number of coarsenings between RQI steps */
    int step,			/* current step number */
    int give_up		/* has coarsening bogged down? */
)
{
    extern FILE *Output_File;	/* output file or null */
    extern int DEBUG_COARSEN;	/* debug flag for coarsening */
    extern int PERTURB;		/* was matrix perturbed in Lanczos? */
    extern double COARSEN_RATIO_MIN;	/* min vtx reduction for coarsening */
    extern int COARSEN_VWGTS;	/* use vertex weights while coarsening? */
    extern int COARSEN_EWGTS;	/* use edge weights while coarsening? */
    extern double refine_time;	/* time for RQI/Symmlq iterative refinement */
    struct vtx_data **cgraph;	/* array of vtx data for coarsened graph */
    struct orthlink *orthlist;	/* list of lower evecs to suppress */
    struct orthlink *newlink;	/* lower evec to suppress */
    double   *cyvecs[MAXDIMS + 1];	/* eigenvectors for subgraph */
    double    evals[MAXDIMS + 1];	/* eigenvalues returned */
    double    goal[MAXSETS];	/* needed for convergence mode = 1 */
    double   *r1, *r2, *work;	/* space needed by symmlq/RQI */
    double   *v, *w, *x, *y;	/* space needed by symmlq/RQI */
    double   *gvec;		/* rhs vector in extended eigenproblem */
    double    evalest;		/* eigenvalue estimate returned by RQI */
    double    maxdeg;		/* maximum weighted degree of a vertex */
    float   **ccoords;		/* coordinates for coarsened graph */
    float    *cterm_wgts[MAXSETS];	/* coarse graph terminal weights */
    float    *new_term_wgts[MAXSETS];	/* terminal weights for Bui's method*/
    float   **real_term_wgts;	/* one of the above */
    float    *twptr;		/* loops through term_wgts */
    float    *twptr_save;	/* copy of twptr */
    float    *ctwptr;		/* loops through cterm_wgts */
    double   *vwsqrt = NULL;	/* square root of vertex weights */
    double    norm, alpha;	/* values used for orthogonalization */
    double    initshift;	/* initial shift for RQI */
    double    total_vwgt;	/* sum of all the vertex weights */
    double    w1, w2;		/* weights of two sets */
    double    sigma;		/* norm of rhs in extended eigenproblem */
    double    term_tot;		/* sum of all terminal weights */
    int    *space;		/* room for assignment in Lanczos */
    int      *morespace;	/* room for assignment in Lanczos */
    int      *v2cv;		/* mapping from vertices to coarse vtxs */
    int       vwgt_max;		/* largest vertex weight */
    int       oldperturb;	/* saves PERTURB value */
    int       cnvtxs;		/* number of vertices in coarsened graph */
    int       cnedges;		/* number of edges in coarsened graph */
    int       nextstep;		/* next step in RQI test */
    int       nsets;		/* number of sets being created */
    int       i, j;		/* loop counters */
    double    time;		/* time marker */

    double   dot(), ch_normalize(), find_maxdeg(), seconds();
    struct orthlink *makeorthlnk();
    void      makevwsqrt(), eigensolve(), coarsen1(), orthogvec(), rqi_ext();
    void      ch_interpolate(), orthog1(), rqi(), scadd(), free_graph();

    if (DEBUG_COARSEN > 0) {
	printf("<Entering coarsen, step=%d, nvtxs=%d, nedges=%d, vmax=%d>\n",
	       step, nvtxs, nedges, vmax);
    }

    nsets = 1 << ndims;

    /* Is problem small enough to solve? */
    if (nvtxs <= vmax || give_up) {
	if (using_vwgts) {
	    vwsqrt = smalloc((nvtxs + 1) * sizeof(double));
	    makevwsqrt(vwsqrt, graph, nvtxs);
	}
	else
	    vwsqrt = NULL;
	maxdeg = find_maxdeg(graph, nvtxs, using_ewgts, (float *) NULL);

	if (using_vwgts) {
	    vwgt_max = 0;
	    total_vwgt = 0;
	    for (i = 1; i <= nvtxs; i++) {
		if (graph[i]->vwgt > vwgt_max)
		    vwgt_max = graph[i]->vwgt;
		total_vwgt += graph[i]->vwgt;
	    }
	}
	else {
	    vwgt_max = 1;
	    total_vwgt = nvtxs;
	}
	for (i = 0; i < nsets; i++)
	    goal[i] = total_vwgt / nsets;

	space = smalloc((nvtxs + 1) * sizeof(int));

	/* If not coarsening ewgts, then need care with term_wgts. */
	if (!using_ewgts && term_wgts[1] != NULL && step != 0) {
	    twptr = smalloc((nvtxs + 1) * (nsets - 1) * sizeof(float));
	    twptr_save = twptr;
	    for (j = 1; j < nsets; j++) {
	        new_term_wgts[j] = twptr;
	        twptr += nvtxs + 1;
	    }

	    for (j = 1; j < nsets; j++) {
	        twptr = term_wgts[j];
	        ctwptr = new_term_wgts[j];
	        for (i = 1; i <= nvtxs; i++) {
		    if (twptr[i] > .5) ctwptr[i] = 1;
		    else if (twptr[i] < -.5) ctwptr[i] = -1;
		    else ctwptr[i] = 0;
		}
	    }
	    real_term_wgts = new_term_wgts;
	}
	else {
	    real_term_wgts = term_wgts;
	    new_term_wgts[1] = NULL;
	}

	eigensolve(graph, nvtxs, nedges, maxdeg, vwgt_max, vwsqrt,
		   using_vwgts, using_ewgts, real_term_wgts, igeom, coords,
		   yvecs, evals, 0, space, goal,
		   solver_flag, FALSE, 0, ndims, 3, eigtol);

	if (real_term_wgts != term_wgts && new_term_wgts[1] != NULL) {
	    sfree(real_term_wgts[1]);
	}
	sfree(space);
	if (vwsqrt != NULL)
	    sfree(vwsqrt);
	return;
    }

    /* Otherwise I have to coarsen. */

    if (coords != NULL) {
	ccoords = smalloc(igeom * sizeof(float *));
    }
    else {
	ccoords = NULL;
    }
    coarsen1(graph, nvtxs, nedges, &cgraph, &cnvtxs, &cnedges,
	     &v2cv, igeom, coords, ccoords, using_ewgts);

    /* If coarsening isn't working very well, give up and partition. */
    give_up = FALSE;
    if (nvtxs * COARSEN_RATIO_MIN < cnvtxs && cnvtxs > vmax ) {
	printf("WARNING: Coarsening not making enough progress, nvtxs = %d, cnvtxs = %d.\n",
	    nvtxs, cnvtxs);
	printf("         Recursive coarsening being stopped prematurely.\n");
	if (Output_File != NULL) {
	    fprintf(Output_File,
		"WARNING: Coarsening not making enough progress, nvtxs = %d, cnvtxs = %d.\n",
	        nvtxs, cnvtxs);
	    fprintf(Output_File,
		"         Recursive coarsening being stopped prematurely.\n");
	}
	give_up = TRUE;
    }

    /* Create space for subgraph yvecs. */
    for (i = 1; i <= ndims; i++) {
	cyvecs[i] = smalloc((cnvtxs + 1) * sizeof(double));
    }

    /* Make coarse version of terminal weights. */
    if (term_wgts[1] != NULL) {
	twptr = smalloc((cnvtxs + 1) * (nsets - 1) * sizeof(float));
	twptr_save = twptr;
	for (i = (cnvtxs + 1) * (nsets - 1); i ; i--) {
	    *twptr++ = 0;
	}
	twptr = twptr_save;
	for (j = 1; j < nsets; j++) {
	    cterm_wgts[j] = twptr;
	    twptr += cnvtxs + 1;
	}
	for (j = 1; j < nsets; j++) {
	    ctwptr = cterm_wgts[j];
	    twptr = term_wgts[j];
	    for (i = 1; i < nvtxs; i++){
	        ctwptr[v2cv[i]] += twptr[i];
	    }
	}
    }
    else {
	cterm_wgts[1] = NULL;
    }

    /* Now recurse on coarse subgraph. */
    nextstep = step + 1;
    coarsen(cgraph, cnvtxs, cnedges, COARSEN_VWGTS, COARSEN_EWGTS, cterm_wgts,
	    igeom, ccoords, cyvecs, ndims, solver_flag, vmax, eigtol,
	    nstep, nextstep, give_up);

    ch_interpolate(yvecs, cyvecs, ndims, graph, nvtxs, v2cv, using_ewgts);

    sfree(cterm_wgts[1]);
    sfree(v2cv);

    /* I need to do Rayleigh Quotient Iteration each nstep stages. */
    time = seconds();
    if (!(step % nstep)) {
	oldperturb = PERTURB;
	PERTURB = FALSE;
	/* Should I do some orthogonalization here against vwsqrt? */
	if (using_vwgts) {
	    vwsqrt = smalloc((nvtxs + 1) * sizeof(double));
	    makevwsqrt(vwsqrt, graph, nvtxs);

	    for (i = 1; i <= ndims; i++)
		orthogvec(yvecs[i], 1, nvtxs, vwsqrt);
	}
	else
	    for (i = 1; i <= ndims; i++)
		orthog1(yvecs[i], 1, nvtxs);

	/* Allocate space that will be needed in RQI. */
	r1 = smalloc(7 * (nvtxs + 1) * sizeof(double));
	r2 = &r1[nvtxs + 1];
	v = &r1[2 * (nvtxs + 1)];
	w = &r1[3 * (nvtxs + 1)];
	x = &r1[4 * (nvtxs + 1)];
	y = &r1[5 * (nvtxs + 1)];
	work = &r1[6 * (nvtxs + 1)];

	if (using_vwgts) {
	    vwgt_max = 0;
	    total_vwgt = 0;
	    for (i = 1; i <= nvtxs; i++) {
		if (graph[i]->vwgt > vwgt_max)
		    vwgt_max = graph[i]->vwgt;
		total_vwgt += graph[i]->vwgt;
	    }
	}
	else {
	    vwgt_max = 1;
	    total_vwgt = nvtxs;
	}
	for (i = 0; i < nsets; i++)
	    goal[i] = total_vwgt / nsets;

	space = smalloc((nvtxs + 1) * sizeof(int));
	morespace = smalloc((nvtxs) * sizeof(int));

	initshift = 0;
	orthlist = NULL;
	for (i = 1; i < ndims; i++) {
	    ch_normalize(yvecs[i], 1, nvtxs);
	    rqi(graph, yvecs, i, nvtxs, r1, r2, v, w, x, y, work,
		eigtol, initshift, &evalest, vwsqrt, orthlist,
		0, nsets, space, morespace, 3, goal, vwgt_max, ndims);

	    /* Now orthogonalize higher yvecs against this one. */
	    norm = dot(yvecs[i], 1, nvtxs, yvecs[i]);
	    for (j = i + 1; j <= ndims; j++) {
		alpha = -dot(yvecs[j], 1, nvtxs, yvecs[i]) / norm;
		scadd(yvecs[j], 1, nvtxs, alpha, yvecs[i]);
	    }

	    /* Now prepare for next pass through loop. */
	    initshift = evalest;
	    newlink = makeorthlnk();
	    newlink->vec = yvecs[i];
	    newlink->pntr = orthlist;
	    orthlist = newlink;

	}
	ch_normalize(yvecs[ndims], 1, nvtxs);

	if (term_wgts[1] != NULL && ndims == 1) {
	    /* Solve extended eigen problem */

	    /* If not coarsening ewgts, then need care with term_wgts. */
	    if (!using_ewgts && term_wgts[1] != NULL && step != 0) {
	        twptr = smalloc((nvtxs + 1) * (nsets - 1) * sizeof(float));
	        twptr_save = twptr;
	        for (j = 1; j < nsets; j++) {
	            new_term_wgts[j] = twptr;
	            twptr += nvtxs + 1;
	        }

	        for (j = 1; j < nsets; j++) {
	            twptr = term_wgts[j];
	            ctwptr = new_term_wgts[j];
	            for (i = 1; i <= nvtxs; i++) {
		        if (twptr[i] > .5) ctwptr[i] = 1;
		        else if (twptr[i] < -.5) ctwptr[i] = -1;
		        else ctwptr[i] = 0;
		    }
	        }
	        real_term_wgts = new_term_wgts;
	    }
	    else {
	        real_term_wgts = term_wgts;
	        new_term_wgts[1] = NULL;
	    }

	    /* Following only works for bisection. */
	    w1 = goal[0];
	    w2 = goal[1];
	    sigma = sqrt(4*w1*w2/(w1+w2));
	    gvec = smalloc((nvtxs+1)*sizeof(double));
	    term_tot = sigma;	/* Avoids lint warning for now. */
	    term_tot = 0;
	    for (j=1; j<=nvtxs; j++) term_tot += (real_term_wgts[1])[j];
	    term_tot /= (w1+w2);
	    if (using_vwgts) {
	        for (j=1; j<=nvtxs; j++) {
		    gvec[j] = (real_term_wgts[1])[j]/graph[j]->vwgt - term_tot;
		}
	    }
	    else {
	        for (j=1; j<=nvtxs; j++) {
		    gvec[j] = (real_term_wgts[1])[j] - term_tot;
		}
	    }

	    rqi_ext();

	    sfree(gvec);
	    if (real_term_wgts != term_wgts && new_term_wgts[1] != NULL) {
		sfree(new_term_wgts[1]);
	    }
	}
	else {
	    rqi(graph, yvecs, ndims, nvtxs, r1, r2, v, w, x, y, work,
	        eigtol, initshift, &evalest, vwsqrt, orthlist,
	        0, nsets, space, morespace, 3, goal, vwgt_max, ndims);
	}
	refine_time += seconds() - time;

	/* Free the space allocated for RQI. */
	sfree(morespace);
	sfree(space);
	while (orthlist != NULL) {
	    newlink = orthlist->pntr;
	    sfree(orthlist);
	    orthlist = newlink;
	}
	sfree(r1);
	if (vwsqrt != NULL)
	    sfree(vwsqrt);
	PERTURB = oldperturb;
    }
    if (DEBUG_COARSEN > 0) {
	printf(" Leaving coarsen, step=%d\n", step);
    }

    /* Free the space that was allocated. */
    if (ccoords != NULL) {
	for (i = 0; i < igeom; i++)
	    sfree(ccoords[i]);
	sfree(ccoords);
    }
    for (i = ndims; i > 0; i--)
	sfree(cyvecs[i]);
    free_graph(cgraph);
}
Beispiel #29
0
int 
interface (
    int nvtxs,		/* number of vertices in full graph */
    int *start,		/* start of edge list for each vertex */
    int *adjacency,		/* edge list data */
    int *vwgts,		/* weights for all vertices */
    float *ewgts,		/* weights for all edges */
    float *x,
    float *y,
    float *z,		/* coordinates for inertial method */
    char *outassignname,	/* name of assignment output file */
    char *outfilename,		/* output file name */
    int *assignment,		/* set number of each vtx (length n) */
    int architecture,		/* 0 => hypercube, d => d-dimensional mesh */
    int ndims_tot,		/* total number of cube dimensions to divide */
    int mesh_dims[3],		/* dimensions of mesh of processors */
    double *goal,			/* desired set sizes for each set */
    int global_method,	/* global partitioning algorithm */
    int local_method,		/* local partitioning algorithm */
    int rqi_flag,		/* should I use RQI/Symmlq eigensolver? */
    int vmax,			/* how many vertices to coarsen down to? */
    int ndims,		/* number of eigenvectors (2^d sets) */
    double eigtol,		/* tolerance on eigenvectors */
    long seed			/* for random graph mutations */
)
{
    extern char *PARAMS_FILENAME;	/* name of file with parameter updates */
    extern int MAKE_VWGTS;	/* make vertex weights equal to degrees? */
    extern int MATCH_TYPE;      /* matching routine to use */
    extern int FREE_GRAPH;	/* free graph data structure after reformat? */
    extern int DEBUG_PARAMS;	/* debug flag for reading parameters */
    extern int DEBUG_TRACE;	/* trace main execution path */
    extern double start_time;	/* time routine is entered */
    extern double reformat_time;/* time spent reformatting graph */
    FILE     *params_file=NULL;	/* file for reading new parameters */
    struct vtx_data **graph;	/* graph data structure */
    double    vwgt_sum;		/* sum of vertex weights */
    double    time;		/* timing variable */
    float   **coords;		/* coordinates for vertices if used */
    int      *vptr;		/* loops through vertex weights */
    int       flag;		/* return code from balance */
    int       nedges;		/* number of edges in graph */
    int       using_vwgts;	/* are vertex weights being used? */
    int       using_ewgts;	/* are edge weights being used? */
    int       nsets_tot=0;	/* total number of sets being created */
    int       igeom;		/* geometric dimension for inertial method */
    int       default_goal;	/* using default goals? */
    int       i;		/* loop counter */
    double    seconds();
    int       reformat();
    void      free_graph(), read_params(), strout();

    if (DEBUG_TRACE > 0) {
	printf("<Entering interface>\n");
    }

    flag = 0;
    graph = NULL;
    coords = NULL;

    if (!Using_Main) {		/* If not using main, need to read parameters file. */
	start_time = seconds();
	params_file = fopen(PARAMS_FILENAME, "r");
	if (params_file == NULL && DEBUG_PARAMS > 1) {
	    printf("Parameter file `%s' not found; using default parameters.\n",
		   PARAMS_FILENAME);
	}
	read_params(params_file);
    }

    if (goal == NULL) {	/* If not passed in, default goals have equal set sizes. */
	default_goal = TRUE;
	if (architecture == 0)
	    nsets_tot = 1 << ndims_tot;
	else if (architecture == 1) 
	    nsets_tot = mesh_dims[0];
	else if (architecture == 2) 
	    nsets_tot = mesh_dims[0] * mesh_dims[1];
	else if (architecture > 2) 
	    nsets_tot = mesh_dims[0] * mesh_dims[1] * mesh_dims[2];

	if (MAKE_VWGTS && start != NULL) {
	    vwgt_sum = start[nvtxs] - start[0] + nvtxs;
	}
	else if (vwgts == NULL) {
	    vwgt_sum = nvtxs;
	}
	else {
	    vwgt_sum = 0;
	    vptr = vwgts;
	    for (i = nvtxs; i; i--)
		vwgt_sum += *(vptr++);
	}

	vwgt_sum /= nsets_tot;
	goal = smalloc_ret(nsets_tot * sizeof(double));
	if (goal == NULL) {
	    strout("\nERROR: No room to make goals.\n");
	    flag = 1;
	    goto skip;
	}
	for (i = 0; i < nsets_tot; i++)
	    goal[i] = vwgt_sum;
    }
    else {
	default_goal = FALSE;
    }

    if (MAKE_VWGTS) {
	/* Generate vertex weights equal to degree of node. */
	if (vwgts != NULL) {
	    strout("WARNING: Vertex weights being overwritten by vertex degrees.");
	}
	vwgts = smalloc_ret(nvtxs * sizeof(int));
	if (vwgts == NULL) {
	    strout("\nERROR: No room to make vertex weights.\n");
	    flag = 1;
	    goto skip;
	}
	if (start != NULL) {
	    for (i = 0; i < nvtxs; i++)
	        vwgts[i] = 1 + start[i + 1] - start[i];
	}
	else {
	    for (i = 0; i < nvtxs; i++)
	        vwgts[i] = 1;
	}
    }

    using_vwgts = (vwgts != NULL);
    using_ewgts = (ewgts != NULL);

    if (start != NULL || vwgts != NULL) {	/* Reformat into our data structure. */
	time = seconds();
	flag = reformat(start, adjacency, nvtxs, &nedges, vwgts, ewgts, &graph);

	if (flag) {
	    strout("\nERROR: No room to reformat graph.\n");
	    goto skip;
	}

	reformat_time += seconds() - time;
    }
    else {
	nedges = 0;
    }

    if (FREE_GRAPH) {		/* Free old graph data structures. */
        free(start);
	free(adjacency);
	if (vwgts != NULL)
	    free(vwgts);
	if (ewgts != NULL)
	    free(ewgts);
	start = NULL;
	adjacency = NULL;
	vwgts = NULL;
	ewgts = NULL;
    }


    if (global_method == 3 ||
        (MATCH_TYPE == 5 && (global_method == 1 || 
			     (global_method == 2 && rqi_flag)))) {
	if (x == NULL) {
	    igeom = 0;
	}
	else {			/* Set up coordinate data structure. */
	    coords = smalloc_ret(3 * sizeof(float *));
	    if (coords == NULL) {
		strout("\nERROR: No room to make coordinate array.\n");
		flag = 1;
		goto skip;
	    }
	    /* Minus 1's are to allow remainder of program to index with 1. */
	    coords[0] = x - 1;
	    igeom = 1;
	    if (y != NULL) {
		coords[1] = y - 1;
		igeom = 2;
		if (z != NULL) {
		    coords[2] = z - 1;
		    igeom = 3;
		}
	    }
	}
    }
    else {
	igeom = 0;
    }

    /* Subtract from assignment to allow code to index from 1. */
    assignment = assignment - 1;
    flag = submain(graph, nvtxs, nedges, using_vwgts, using_ewgts, igeom, coords,
		   outassignname, outfilename,
		   assignment, goal,
		   architecture, ndims_tot, mesh_dims,
		   global_method, local_method, rqi_flag, vmax, ndims,
		   eigtol, seed);

skip:
    if (coords != NULL)
	sfree(coords);

    if (default_goal)
	sfree(goal);

    if (graph != NULL)
	free_graph(graph);

    if (flag && FREE_GRAPH) {
	sfree(start);
	sfree(adjacency);
	sfree(vwgts);
	sfree(ewgts);
    }

    if (!Using_Main && params_file != NULL)
	fclose(params_file);

    return (flag);
}
Beispiel #30
0
int
main (int argc, char** argv)
{
  char *kfile, *tfile, *cfile, *tafile, *lfile;
  size_t ksize, tsize, iter, depth;
 // FILE *kout, *tout;
  char opt;
  graph_t **gtrain; int* target;
  FILE* fileTrain, *fileResult, *fileTarget;
  core_t core;
  gtrain = NULL;
  lfile = tafile = cfile = kfile = NULL;
  depth = 3;
  CLEAR_FLAGS();
  SET_RUNNABLE();
  ksize = tsize = 0;
  core = TanimotoCore;
  while((opt = getopt(argc, argv, "mvihd:k:t:c:a:l:")) != -1) {
    switch(opt){
    case 'v':
      SET_VERBOSE();
      break;
    case 'i':
      SET_INFO();
      break;
    case 'd':
      depth = strtol((const char*) optarg, 0, 10);
      break;
    case 'k':
      SET_K_FILE();
      kfile = optarg;
      break;
    case 't':
      SET_T_FILE();
      tfile = optarg;
      break;      
    case 'c':
      SET_C_FILE();
      cfile = optarg;
      break;
    case 'a':
      SET_TA_FILE();
      tafile = optarg;
      break;
    case 'l':
      SET_L_FILE();
      lfile = optarg;
      break;
    case 'h':
      SET_HELP();
      break;
      
    case 'm':
      SET_PROVA_MINMAX();
      break;
      
    default:
      SET_HELP();
    }
  }
  if(HELP()) {
    usage();
    CLEAR_FLAGS();
  }
  if(INFO()) {
    info();
    CLEAR_FLAGS();
  }
  if(optind < argc) {
    if(!strcmp(argv[optind], "tanimoto")) {
      printf("tanimoto kernel\n");    	
    } else if(!strcmp(argv[optind], "minmax")) {
      printf("minmax kernel\n");
      core = MinMaxCore;
    } else
      printf("unavailable core ...\ndefault core: tanimoto\n");
  } //else
    //printf("default core: tanimoto\n");
  if(RUNNABLE()) {
    if(K_FILE() && T_FILE()) {
      if((fileTrain = fopen(kfile, "r")) && (fileTarget = fopen(tfile, "r"))) {
    	  gtrain = parse(fileTrain, &ksize);
    	  fclose(fileTrain);
    	  
    	  target=parseTarget(fileTarget, ksize);
    	  fclose(fileTarget);
    	  
    	  if(target==0)
    		  printf("\ncheck training file and target file");
    	  else
    		  FoldCrossValidation(core, gtrain, target, ksize, depth);

    	  for(iter = 0; iter < ksize; iter++)
    		  free_graph(gtrain[iter]);

    	  XFREE(gtrain);
    	  XFREE(target);  
      	}else fatal("unable to open training file");
    }
    
    if(TA_FILE() && C_FILE()) {
      fileResult = fopen(cfile, "r");
      fileTarget = fopen(tafile, "r");
      printf("\nAccuratezza: %f\n", getAccuracy(fileTarget, fileResult));
      fclose(fileResult);
      fclose(fileTarget);
    }
    /*
    if(L_FILE()) {
      file = fopen(lfile, "r");
      printf("\nLeaveOneOut: %f\n", getLeaveOneOut(file));
      fclose(file);
    }
    */

    if(K_FILE() && !T_FILE()) {
      if((fileTrain = fopen(kfile, "r"))) {
    	  gtrain = parse(fileTrain, &ksize);
    	  fclose(fileTrain);

    	print_graph(gtrain[0]);
    	print_graph(gtrain[1]);
    	  
    	  if(gtrain==0)
    		  printf("\ncheck training file");
    	  else
    		  WriteKernelMatrix(core, gtrain, ksize, depth);
    		  
    	  for(iter = 0; iter < ksize; iter++)
    		  free_graph(gtrain[iter]);

    	  XFREE(gtrain);  
      	}else fatal("unable to open training file");
    }
    
    if(PROVA_MINMAX()) {
    	printf("\nPROVA MIN MAX\n");
    	
    	fileTrain = fopen("./minmax.mol2", "r");
    	gtrain = parse(fileTrain, &ksize);
    	//print_graph(gtrain[0]);
    	//print_graph(gtrain[1]);
    	
    	print_graph(gtrain[0]);
    	print_graph(gtrain[1]);
    	
    	printf("\nMinMax: %f", MinMaxCore(gtrain[0], gtrain[1], 3));
    	//printf("\nTanimoto: %f", TanimotoCore(gtrain[0], gtrain[1], 3));
    	
    	fclose(fileTrain);
     }

    
  } //else usage();
  return EXIT_SUCCESS;
}