Пример #1
0
int main()
{
int i, j;
input();
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
stop[i][j] = -1;
for (i = 0; i<numofppl; i++) 
	{
	how_far[i]=0;
	map_maker(hm[i]->x,hm[i]->y);
	path_gen(hm[i]->x,hm[i]->y,i,0);
	}
sort();
for (i = 0; i<numofppl; i++)
	{
	printf("%d\n",length[i]);
	path_print(i);
	}
printf("\n");
//while (how_far[0]<=length[0]) 
while (are_gone()==0)
//for (j=0; j<5; j++)
	{
		for (i=0; i<numofppl; i++)	
		{	
		step(i);
		}
	print();
	}
return 0;
}
Пример #2
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;
}
Пример #3
0
void test(const char *path)
{
	PATHSPLIT f;
	char buf[1024];

	printf("> %s\n", path);
	path_split(path, &f);
	path_print(&f);
	path_normalize(&f, NULL);
	path_tostring(&f, buf);
	printf("< %s\n", buf);
}
Пример #4
0
void path_gen(int x, int y, int p, int extime)
{
int i,j,t,k,l,len;
t=0;
length[p]=n+m;
for (i=0; i<numofgates; i++)
{
if ( (map[gates[i]->x][gates[i]->y] < length[p] ) && (map[gates[i]->x][gates[i]->y]>0) )  
{
t=i;
length[p]=map[gates[i]->x][gates[i]->y];
}
}
len=length[p]; 
for (i = 0; i < len; i++) { px[i][p] = -1; py[i][p] = -1; }
i=gates[t]->x; j=gates[t]->y;
px[len][p]=i; py[len][p]=j;
while ( ((i!= x ) || (j!= y )) && (len>0))
{
k=0; l=0;
while ( !( ((i+dx[k])<n) && ((i+dx[k])>=0) && ((j+dx[l])<m) && ((j+dx[l])>=0) && (map[i+dx[k]][j+dx[l]]==map[i][j]-1) && (k<3) && 
(abs(dx[k]*dx[l])!=1) && (map[i+dx[k]][j+dx[l]]!=-1) ) )
if (l==2) {l=0; k++;}
else l++;
if (k<3)
{
	i=i+dx[k];
	j=j+dx[l];
	len=len-1;
	px[len][p]=i; 
	py[len][p]=j;
}

}
px[0][p]=x; py[0][p]=y;
path_print(p);
}