-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
130 lines (91 loc) · 4.48 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "funcoes.h"
#include "f_heuristics.h"
using namespace std;
int main(int argc, char *argv[])
{
double tempo;
chrono::duration<double> duracao;
int numeroIteracoes = 1000;
// # Manipulação do Arquivo
string instancia = argv[1];
string localArquivo = "./instancias/" + instancia;
cout << localArquivo << endl;
// Chamando a função para definir as informações do arquivo
tuple<int, int, vector<int>, vector<vector<int>>>
informacoes = definirInformacoesArquivo(localArquivo);
// Extraindo as informações retornadas pela função
int numeroLinhas = get<0>(informacoes);
int numeroProdutos = get<1>(informacoes);
vector<int> vetorProdutos = get<2>(informacoes);
vector<vector<int>> matrizPreparacao = get<3>(informacoes);
cout << "\n=============== \n"
<< endl;
// Imprimindo as informações extraídas
cout << "Numero de linhas: " << numeroLinhas << endl;
cout << "Numero de produtos: " << numeroProdutos << endl;
cout << "\n=============== \n"
<< endl;
// # Algoritmo Guloso
// Obter o tempo atual antes do início da execução
auto inicioGuloso = chrono::high_resolution_clock::now();
vector<vector<int>> solucaoGulosa = gerarSolucaoGulosa(numeroProdutos, numeroLinhas, matrizPreparacao, vetorProdutos);
// Obter o tempo atual após a execução
auto fimGuloso = chrono::high_resolution_clock::now();
// Calcular a duração em segundos
duracao = fimGuloso - inicioGuloso;
tempo = duracao.count();
vector<int> temposGuloso = temposProducao(solucaoGulosa, matrizPreparacao, vetorProdutos);
cout << "Guloso: ....... " << *max_element(temposGuloso.begin(), temposGuloso.end());
cout << " (" << tempo << "s)" << endl;
// * Guloso + VND
// Obter o tempo atual antes do início da execução
auto inicioVND = chrono::high_resolution_clock::now();
vector<vector<int>> solucaoMelhorada = melhorarLinhas(solucaoGulosa, matrizPreparacao, vetorProdutos, temposGuloso);
// Obter o tempo atual após a execução
auto fimVND = chrono::high_resolution_clock::now();
// Calcular a duração em segundos
duracao = fimVND - inicioVND;
tempo = duracao.count();
vector<int> temposMelhorados = temposProducao(solucaoMelhorada, matrizPreparacao, vetorProdutos);
cout << "Guloso + VND: . " << *max_element(temposMelhorados.begin(), temposMelhorados.end());
cout << " (" << tempo << "s)" << endl;
// * Guloso + RVND
// Obter o tempo atual antes do início da execução
auto inicioRVND = chrono::high_resolution_clock::now();
vector<vector<int>> solucaoMelhoradaRVND = melhorarLinhasRVND(solucaoGulosa, matrizPreparacao, vetorProdutos, temposGuloso);
// Obter o tempo atual após a execução
auto fimRVND = chrono::high_resolution_clock::now();
// Calcular a duração em segundos
duracao = fimRVND - inicioRVND;
tempo = duracao.count();
vector<int> temposMelhoradosRVND = temposProducao(solucaoMelhoradaRVND, matrizPreparacao, vetorProdutos);
cout << "Guloso + RVND: " << *max_element(temposMelhoradosRVND.begin(), temposMelhoradosRVND.end());
cout << " (" << tempo << "s)" << endl;
// | Meta-heurística: GRASP
// Obter o tempo atual antes do início da execução
auto inicioGRASP2 = chrono::high_resolution_clock::now();
vector<vector<int>> solucaoGRASP2 = grasp(matrizPreparacao, vetorProdutos, numeroLinhas, numeroIteracoes, 0.87);
// Obter o tempo atual após a execução
auto fimGRASP2 = chrono::high_resolution_clock::now();
// Calcular a duração em segundos
duracao = fimGRASP2 - inicioGRASP2;
tempo = duracao.count();
vector<int> temposGRASP2 = temposProducao(solucaoGRASP2, matrizPreparacao, vetorProdutos);
cout << "GRASP2: ....... " << *max_element(temposGRASP2.begin(), temposGRASP2.end());
cout << " (" << tempo << "s)" << endl;
// | Meta-heurística: ILS
// Obter o tempo atual antes do início da execução
auto inicioILS2 = chrono::high_resolution_clock::now();
vector<vector<int>> solucaoILS2 = ils(matrizPreparacao, vetorProdutos, numeroLinhas, numeroIteracoes);
// Obter o tempo atual após a execução
auto fimILS2 = chrono::high_resolution_clock::now();
// Calcular a duração em segundos
duracao = fimILS2 - inicioILS2;
tempo = duracao.count();
vector<int> temposILS2 = temposProducao(solucaoILS2, matrizPreparacao, vetorProdutos);
cout << "ILS2: ......... " << *max_element(temposILS2.begin(), temposILS2.end());
cout << " (" << tempo << "s)" << endl;
cout << "\n=============== \n"
<< endl;
return 0;
}