Ejemplo n.º 1
0
int searchController(Graph graph, int start, int stop, int option) {
	Dllist close;
	Dllist node;

	close = new_dllist();

	switch(option) {
		case BFS_SEARCH:
		breathFirstSearch(graph, start, stop, close);
		break;
		case BFS_TRAVERSE:
		traverseBFS(graph, start, close);
		break;
		case DFS_SEARCH:
		deepFirstSearch(graph, start, stop, close);
		break;
		case DFS_TRAVERSE:
		traverseDFS(graph, start, close);
		break;
		default:
		printf("This is not an option\n");
		free_dllist(close);
		return;
	}

	node = dll_first(close);
	printf("Visit %d\n", jval_i(node->val));

	free_dllist(close);
}
Ejemplo n.º 2
0
int main(void) {

	double start, end;
	double interval;

	int zoneCount = 5;

	short* graph;
	short* temp1, *temp2;
	short zone;

	graph = (short*)malloc(zoneCount * MAX_CONNECTIONS * sizeof(short));

	// some kind of queue and path and cost array
	temp1 = (short*)malloc(zoneCount * sizeof(short));
	// came_from reference
	temp2 = (short*)malloc(zoneCount * sizeof(short));

	for (int i = 0; i < zoneCount * MAX_CONNECTIONS; i++) {
		graph[i] = -1;
	}
	graph[0 * MAX_CONNECTIONS + 0] = 1;
	graph[1 * MAX_CONNECTIONS + 0] = 0; graph[1 * MAX_CONNECTIONS + 1] = 2; graph[1 * MAX_CONNECTIONS + 2] = 3;
	graph[2 * MAX_CONNECTIONS + 0] = 1; graph[2 * MAX_CONNECTIONS + 1] = 4;
	graph[3 * MAX_CONNECTIONS + 0] = 1; graph[3 * MAX_CONNECTIONS + 1] = 4;
	graph[4 * MAX_CONNECTIONS + 0] = 2; graph[4 * MAX_CONNECTIONS + 1] = 3;

	// pathfinding with weights
	start = clock();

	for (int i = 0; i < 1; i++)
		zone = breathFirstSearch(graph, zoneCount, 4, 0, temp1, temp2, 1);

	end = clock() - start;
	interval = end / (double)CLOCKS_PER_SEC;
	fprintf(stderr, "clock cycles: %f seconds elapsed: %f \n", end, interval);
	fprintf(stderr, "next zone towards %3hd from %3hd: %3hd \n", 0, 4, zone);
}