Ejemplo n.º 1
0
int main()
{
	srand(time(NULL));
	int NVERTEX = 20;
	DirectedGraph * g = randgraph(NVERTEX);
	g->print();

	printf("Random Delete Vertex:\n");
	// random delete vertex 
	int i;
	for(i=0;i<NVERTEX;i++) {
		int n = rand()%NVERTEX;	
		printf("delete: %d\n", n);
		g->delete_vertex(n);
	}

	g->print();
	printf("Delete All Edges: \n");
	
	for(i=0;i<NVERTEX;i++) {
		int j;
		for(j=i+1;j<NVERTEX;j++) {
			g->delete_edge(i, j);
		}
	}

	g->print();
	return 0;
}
Ejemplo n.º 2
0
int main(void)
{
	using namespace alg;
	srand(time(NULL));
	int NVERTEX = 6;
	DirectedGraph * g = randgraph(NVERTEX);
	g->print();

	printf("finding Maximal Flow from 0 to 5: \n");	
	EdmondsKarp ek(*g);
	uint32_t maxflow = ek.run(0,5);

	printf("Max Flow is %d\n", maxflow);
	printf("the residual network\n");
	printf("\t");
	for(uint32_t i=0;i<g->vertex_count();i++) {
		printf("%d\t", ek.rmap()[i]);
	}
	printf("\n");

	for(uint32_t i=0;i<g->vertex_count();i++) {
		printf("%d\t",ek.rmap()[i]);
		for(uint32_t j=0;j<g->vertex_count();j++) {
			printf("%d\t", ek.residual()(i,j));
		}
		printf("\n");
	}

	delete g;

	return 0;
}