Exemple #1
0
weight_t graph_maxflow(graph_t*graph, node_t*pos1, node_t*pos2)
{
    int max_flow = 0;
    graphcut_workspace_t* w = graphcut_workspace_new(graph, pos1, pos2);

    graph_reset(graph);
    DBG check_graph(graph);
   
    posqueue_addpos(w->queue1, pos1); w->flags1[pos1->nr] |= ACTIVE|IN_TREE; 
    posqueue_addpos(w->queue2, pos2); w->flags2[pos2->nr] |= ACTIVE|IN_TREE; 
    DBG workspace_print(w);
  
    while(1) {
	path_t*path;
	while(1) {
	    char done1=0,done2=0;
	    node_t* p1 = posqueue_extract(w->queue1);
	    if(!p1) {
		graphcut_workspace_delete(w);
		return max_flow;
	    }
	    DBG printf("extend 1 from %d (%d edges)\n", NR(p1), node_count_edges(p1));
	    path = expand_pos(w, w->queue1, p1, 0, w->flags1, w->flags2);
	    if(path)
		break;
	    DBG workspace_print(w);
	   
#ifdef TWOTREES
	    node_t* p2 = posqueue_extract(w->queue2);
	    if(!p2) {
		graphcut_workspace_delete(w);
		return max_flow;
	    }
	    DBG printf("extend 2 from %d (%d edges)\n", NR(p2), node_count_edges(p2));
	    path = expand_pos(w, w->queue2, p2, 1, w->flags2, w->flags1);
	    if(path)
		break;
	    DBG workspace_print(w);
#endif

	}
	DBG printf("found connection between tree1 and tree2\n");
	DBG path_print(path);

	DBG printf("decreasing weights\n");
	max_flow += decrease_weights(graph, path);
	DBG workspace_print(w);

	DBG printf("destroying trees\n");
	combust_tree(w, w->queue1, w->queue2, path);
	DBG workspace_print(w);

	DBG check_graph(w->graph);

	path_delete(path);
    }
    graphcut_workspace_delete(w);
    return max_flow;
}
Exemple #2
0
/*
 * call-seq:
 *   Redleaf::Graph.new()          -> graph
 *   Redleaf::Graph.new( store )   -> graph
 *
 * Create a new Redleaf::Graph object. If the optional +store+ object is
 * given, it is used as the backing store for the graph. If none is specified
 * a new Redleaf::MemoryHashStore is used.
 *
 */
static VALUE
rleaf_redleaf_graph_initialize( int argc, VALUE *argv, VALUE self ) {
	if ( !check_graph(self) ) {
		rleaf_GRAPH *graph;
		VALUE store = Qnil;

		/* Default the store if one isn't given */
		if ( rb_scan_args(argc, argv, "01", &store) == 0 ) {
			rleaf_log_with_context( self, "debug", "Creating a new default store for graph 0x%x", self );
			store = rb_class_new_instance( 0, NULL, DEFAULT_STORE_CLASS );
		}

		if ( !IsStore(store) )
			rb_raise( rb_eTypeError, "wrong argument type %s (expected a Redleaf::Store)",
				rb_obj_classname(store) );

		DATA_PTR( self ) = graph = rleaf_graph_alloc( store );

	} else {
		rb_raise( rleaf_eRedleafError,
				  "Cannot re-initialize a graph once it's been created." );
	}

	return self;
}
Exemple #3
0
/*
 * Fetch the data pointer and check it for sanity.
 */
rleaf_GRAPH *
rleaf_get_graph( VALUE self ) {
	rleaf_GRAPH *graph = check_graph( self );

	if ( !graph )
		rb_fatal( "Use of uninitialized Graph." );

	return graph;
}
int main(int argc, char** argv)
{
	if (argc < 2) {
		printf("please indicate the file containing the list of graphs.\n");
		return 0;
	}
	FILE * fp = fopen(argv[1], "r");
	if (fp == NULL) {
		printf("cannot open file %s.\n", argv[1]);
		return 0;
	}
	int nloops;
	sparsegraph * sg;
	while((sg = read_sg_loops(fp, NULL, &nloops)) != NULL) { 
		count++; 
		//printf("Checking graph %d (e=%d).\n", count, sg->nde/2);
		check_graph(sg);
	}
	printf("Checked %d graphs, found %d configurations.\n", count, nTarget);
	fclose(fp);
	return 0;
}