Skip to content

Commit

Permalink
arquivos atualizados
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermecv committed Dec 9, 2019
1 parent 049ea3c commit d3cbd89
Show file tree
Hide file tree
Showing 16 changed files with 147 additions and 102 deletions.
25 changes: 0 additions & 25 deletions Makefile

This file was deleted.

24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ Aluno: Guilherme Camargo Valese (guilherme.valese@hotmail.com)



Árvore de espalhamento mínimo é definida como o caminho de menor custo que conecte todas as arestas de um grafo. O custo de cada aresta é seu peso associado, de forma que o custo total de um grafo é o somatório dos pesos das arestas.

![](https://upload.wikimedia.org/wikipedia/commons/thumb/d/d2/Minimum_spanning_tree.svg/300px-Minimum_spanning_tree.svg.png)

Existem diversos algoritmos para MST, sendo os mais comuns



- Kruskal (aplicado a este trabalho)

- Prim

- Sollin



### Algoritmos Utilizidados



------

## Instalação
Expand All @@ -23,7 +43,7 @@ Dependências
**Digite os comandos abaixo**

```bash
$ cd proj_final_prg22105
$ cd proj_final_prg22105/src
$ make
$ ./main
$ ./makegraph.sh
Expand All @@ -32,7 +52,7 @@ $ ./makegraph.sh
Para teste de acesso à memória, execute os comandos abaixo *(necessário ter o **valgrind** instalado)*

```bash
$ cd proj_final_prg22105
$ cd proj_final_prg22105/src
$ make
$ ./valgrind_test.sh # executa o teste de memória (opcional)
```
Expand Down
Binary file added img/300px-Minimum_spanning_tree.svg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions makegraph

This file was deleted.

37 changes: 37 additions & 0 deletions src/fake_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Aresta;Origem;Destino;Peso
1;1;2;126
2;1;3;99
3;1;4;189
4;2;3;99
5;3;5;81
6;4;5;76
7;2;6;80
8;2;7;85
9;3;8;85
10;5;8;85
11;6;7;81
12;7;8;117
13;7;9;135
14;7;10;120
15;8;9;49
16;8;11;180
17;9;10;54
18;9;12;99
19;9;13;162
20;10;13;171
21;11;14;117
22;12;14;153
23;12;13;108
24;13;17;414
25;13;15;162
26;14;15;180
27;14;16;243
28;15;16;189
29;15;18;81
30;15;20;279
31;15;21;315
32;16;18;90
33;17;20;378
34;18;19;180
35;19;21;189
36;20;21;135
23 changes: 20 additions & 3 deletions src/grafo.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ struct vertices {
};

struct arestas {
int adj; /*!< Valor booleando. Verdadeiro representa uma adjacência entre dois vértices */

/* Mais informações, se necessário */
int adj; /*!< Valor booleano. Verdadeiro representa uma adjacência entre dois vértices */
int origem;
int destino;
int peso;
int marcado;
};

struct grafos{
Expand Down Expand Up @@ -163,6 +165,21 @@ int adjacente(grafo_t *g, int u, int v){
return ((g->matriz_adj[u][v].adj));
}

/**
* @brief Retorna o peso de uma aresta
* @param u: índice do vértice u
* @param v: índice do vértice v
* @param *g: grafo
* @return int: peso da aresta
*/
int aresta_get_peso(grafo_t *g, int u, int v)
{
if (u > MAX_VERTICES || v > MAX_VERTICES)
return FALSE;

return(g->matriz_adj[u][v].peso);
}

/**
* @brief Exporta os dados em formato DOT
* @param filename: nome do arquivo
Expand Down
Binary file added src/graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions src/insertion_sort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @file insertion_sort.c
*
* @author Guilherme Camargo Valese
*/
#include "insertion_sort.h"

/**
* @brief Ordenação por inserção
* @param **dados: vetor de ponteiros
* @param *n: ponteiro para a quantidade total de dados
*/
void insertion_sort(dado_t **dados, int n)
{
int i, j;

for(i = 1; i < n; i++)
{
for(j = i; j > 0 && dados[j-1]->peso > dados[j]->peso; j--)
{
swap(&dados[j], &dados[j-1]);
}
}
}

/**
* @brief Faz a troca de dois elementos de um vetor
* @param a: ponteiro para o primeiro elemento
* @param b: ponteiro para o segundo elemento
*/
void swap(dado_t **a , dado_t **b)
{
dado_t *temp;
temp = *a;
*a = *b;
*b = temp;
}
9 changes: 9 additions & 0 deletions src/insertion_sort.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef INSERTION_SORT_H
#define INSERTION_SORT_H

#include "dados.h"

void insertion_sort(dado_t **dados, int n);
void swap(dado_t **a , dado_t **b);

#endif /* INSERTION_SORT_H */
6 changes: 6 additions & 0 deletions src/kruskal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @file kruskal.c
*
* @author Guilherme Camargo Valese
*/
#include "kruskal.h"
7 changes: 7 additions & 0 deletions src/kruskal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef KRUSKAL_H
#define KRUSKAL_H

#include "grafo.h"


#endif /* KRUSKAL_H */
14 changes: 9 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@
#include <stdlib.h>
#include "grafo.h"
#include "dados.h"
#include "selection_sort.h"
#include "insertion_sort.h"
#include "kruskal.h"

#define FILENAME "rede_optica.csv" // Nome do arquivo de dados
#define DEBUG_ON

int main(void)
{
int n_linhas;

dado_t **dados = ler_dados_csv(FILENAME, &n_linhas);
grafo_t *grafo = cria_grafo(n_linhas);

selection_sort(dados, n_linhas);
insertion_sort(dados, n_linhas); // Ordena os dados por peso das arestas

grafo_t *grafo = cria_grafo(n_linhas);

// CRIA O GRAFO ORIGINAL
int i;
Expand All @@ -41,3 +40,8 @@ int main(void)

return EXIT_SUCCESS;
}

void krusal_mst(grafo_t *grafo)
{

}
48 changes: 0 additions & 48 deletions src/selection_sort.c

This file was deleted.

11 changes: 0 additions & 11 deletions src/selection_sort.h

This file was deleted.

5 changes: 0 additions & 5 deletions valgrind_test.sh

This file was deleted.

Binary file modified Árvore de Espalhamento Mínimo.pptx
Binary file not shown.

0 comments on commit d3cbd89

Please sign in to comment.