Esempio n. 1
0
File: main.c Progetto: gioknx/AEDS-3
int main(int argc, char **argv) {

	int s_x, s_y, f_x, f_y, d_x, d_y;
	char *arquivo_entrada;
	if(argc != 8)
		return 1;
	arquivo_entrada = argv[1];
	s_x = atoi(argv[2]);
	s_y = atoi(argv[3]);
	f_x = atoi(argv[4]);
	f_y = atoi(argv[5]);
	d_x = atoi(argv[6]);
	d_y = atoi(argv[7]);	

	FILE* fp;
	fp = fopen (arquivo_entrada, "r");

	Mapa *map = ler_entrada(fp);
	Grafo *grafo = calloc(1, sizeof(Grafo));
	grafo->lista = calloc(map->N * map->M, sizeof(Vertice*));
	grafo->tamanho = map->N*map->M;

	aloca_lista(grafo);

	int indice_inicial = (s_y * map->M) + s_x;
	int indice_final = (f_y * map->M) + f_x;

	// Uma vez tendo nossa matriz de valores, devemos transformá-la no grafo
	matriz_para_grafo(map->matriz_mapa, grafo->lista, map->N, map->M, d_x, d_y );
	// Conectamos os atalhos
	conecta_atalhos(grafo, map);


	// Rodamos Djkistra a partir do nosso vertice inicial
	Djkistra(grafo, indice_inicial);

	int resultado;
	resultado = grafo->lista[indice_final]->d;
	// Se o resultado é o número máximo, significa que não existe caminho
	// logo printamos -1
	if(resultado ==  99999999)
		resultado = -1;
	printf("%d\n", resultado);

	libera_grafo(grafo);
	libera_mapa(map);
	fclose(fp);

	return 0;
}
Esempio n. 2
0
int main (int argc, char *argv[]) {

  Indice *Ml,*Mh,*CW;
  Indice *arestaT;    /* Armazena as arestas de T ao inves do grafo */
  Grafo *Gh, *T;
  Arvoreb *R, *U;     
  int i;

  Ml = NULL;
  Mh = NULL;
  if(argc < 2) erro(SEM_ARQUIVO);
  ler_entrada(argv[1],&Ml,&Mh);
  if(!checa_entrada(Ml,Mh)) erro(MLMAIOR);

  /** Construir GH a partir de MH **/
  Gh = GRAFOInit(n);
  for(i = 0; i < tamanho_M; i++) {
    GRAFOinsereE(Gh,get_M_objeto_linha(Mh,i),get_M_objeto_coluna(Mh,i),(double)get_M_peso(Mh,i));
  }
  free(Mh);

  /* Construir T a partir de GH */
  arestaT = malloc((n-1)*sizeof(Indice));
  if(arestaT == NULL) erro(MALLOC_lh);
  T = prism_MST(Gh,arestaT);
  if(!checa_existencia_U(T,arestaT,Ml)) erro(UNAOEXISTE);
  GRAFODel(Gh);
  GRAFODel(T);

  /* Construir R a partir de T(ArestaT)*/
  R = construir_R(arestaT);
  /* Computar CW a partir de ML, T, e R*/
  CW = computacao_CW(Ml,arestaT,R);
  free(arestaT);
  free(Ml);
  ARVOREBDel(R);
  /* Computar U a partir de CW(R,T e CW inbutido)*/
  U = construir_U(CW);
  printf("Impressao de U:\n[NO] ------------- PESO -------------- [NO_PAI]\n");
  ARVOREBImprimeW(U);

  /** FREES **/
  free(CW);
  ARVOREBDel(U);
  return 0;
}