-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
93 lines (79 loc) · 1.98 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
#include <iostream>
#include <cstring>
#include <cstdlib>
#include "Graph.h"
#include <ctime>
#include <string>
using namespace std;
enum algoritmo_t
{
dsatur, brown
};
int main(int argc, char **argv)
{
if (argc >= 2 && argc <= 5)
{
algoritmo_t algoritmo = dsatur;
int tmax = 15 * 60;
for (int i = 1; i < argc - 1; i++)
{
if (strcmp("-b", argv[i]) == 0)
{
algoritmo = brown;
}
else if (strcmp("-t", argv[i]) == 0)
{
int t = atoi(argv[i + 1]);
if (t > 0)
{
tmax = t;
i++;
}
else
{
cout << "El valor de tiempo indicado es invalido\n";
cout << "Sintaxis correcta: gsc1 [opciones] <instancia>\n";
return EXIT_FAILURE;
}
}
else if (strcmp("-d", argv[i]) != 0)
{
cout << "Sintaxis correcta: gsc1 [opciones] <instancia>\n";
return EXIT_FAILURE;
}
}
try
{
double executionTime;
Graph grafo(argv[argc - 1]);
if (algoritmo == dsatur)
{
executionTime = grafo.Dsatur(tmax);
}
else
{
executionTime = grafo.Brown(tmax);
}
if (executionTime !=-1)
{
grafo.printOutput(cout, executionTime);
}
else
{
cout << "El tiempo de ejecucion permitido fue excedido\n";
return EXIT_FAILURE;
}
}
catch (string mensaje)
{
cout << mensaje;
return EXIT_FAILURE;
}
}
else
{
cout << ("El numero de argumentos es incorrecto\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}