-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
148 lines (119 loc) · 5.22 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "structures.hpp"
using namespace std;
int main()
{
unsigned short int size = SizeRecon();
string Line;
char string_generic[1];
char *CharPointer = string_generic;
int count = 1;
MatrixElement FinalMatrix[size][size];
unsigned short int MatrixLines = 0;
unsigned short int MatrixColumns = 0;
unsigned short int MatrixCounting = 0;
ifstream File("./dataset/input.data");
unsigned int GlobalSum = 0;
// Percorrendo arquivo linha por linha e armazenando em Line:
while (getline(File, Line))
{
// Criando um pointeiro de char do tamanho da linha do arquivo:
char *copy = new char[Line.length() + 1];
// Passando os dados de Line para copy e selecionando os dados desejados:
strcpy(copy, Line.c_str());
CharPointer = strtok(copy, " \n \0");
if (count >= 2)
{
if(MatrixLines==size)
{
MatrixLines=0;
MatrixColumns=0;
cout<<"\n\n\n\n Nova iteração \n\n\n\t"<<++MatrixCounting<<"ª"<<" Matriz Lida\n";
MatrixScanner(size,(MatrixElement *)FinalMatrix);
//Iníciando variáveis para pesquisa na matriz:
bool S,SW,SE,E,W;
vector<unsigned short int> StepsOni;
vector<unsigned short int> StepsOnj;
vector<MatrixElement> StepsWeight;
unsigned short int HowManySteps = 0;
unsigned short int i = 0;
unsigned short int j = 0;
CoordinateDefinition(&i,&j);
StepsOni.push_back(i);
StepsOnj.push_back(j);
StepsWeight.push_back(FinalMatrix[i][j]);
unsigned short int lasti=i;
unsigned short int lastj=j;
while(true)
{
CreatingCoordinates(size,i,j,&S,&SE,&SW,&W,&E);
unsigned short int IndexHigher = 0;
if((S) && (SE) && (E) && (SW) && (W)) //Possibilidade de ir Leste, Oeste, Sul, Sudeste ou Sudoeste:
{
FivePossibleWays((MatrixElement *)FinalMatrix,&i,&j,size,&lasti,&lastj);
StepsOni.push_back(i);
StepsOnj.push_back(j);
StepsWeight.push_back(FinalMatrix[i][j]);
HowManySteps++;
}
else if(S && SE && E && !W && !SW) //Possibilidade de ir para Sul, Sudeste ou Leste:
{
SouthEastPossibleWays((MatrixElement *)FinalMatrix,&i,&j,size,&lasti,&lastj);
StepsOni.push_back(i);
StepsOnj.push_back(j);
StepsWeight.push_back(FinalMatrix[i][j]);
HowManySteps++;
}
else if((S) && (SW) && (W) && !SE && !SE)//Possibilidade de ir para Sul, Sudoeste ou Oeste:
{
SouthWestPossibleWays((MatrixElement *)FinalMatrix,&i,&j,size,&lasti,&lastj);
StepsOni.push_back(i);
StepsOnj.push_back(j);
StepsWeight.push_back(FinalMatrix[i][j]);
HowManySteps++;
}
else if((E && W && !S && !SW && !SE) || (E && !W && !S && !SW && !SE)) //Caso especial de caminhada para o Leste:
{
lasti = i;
lastj = j;
i=i;
j = j+1;
StepsOni.push_back(i);
StepsOnj.push_back(j);
StepsWeight.push_back(FinalMatrix[i][j]);
HowManySteps++;
}
//Andando apenas para a esquerda, ou seja, chegada ao último elemento da matriz:
else if(!E && W && !S && !SW && !SE)
{
HowManySteps++;
StepsOni.push_back(i);
StepsOnj.push_back(j);
StepsWeight.push_back(FinalMatrix[i][j]);
unsigned short int *iRoute = RoadMapDefiner(StepsOni,HowManySteps);
unsigned short int *jRoute = RoadMapDefiner(StepsOnj,HowManySteps);
RoadMapViewer(iRoute,jRoute,HowManySteps,(MatrixElement *)FinalMatrix,size , &GlobalSum);
MapOfTheJourney(iRoute,jRoute,size,HowManySteps);
break;
}
}
}
else
{
MatrixColumns = 0;
MatrixLines += 1;
}
}
cout << "\n\n";
while (CharPointer != NULL)
{
MatrixColumns += 1;
int z = atoi(CharPointer);
FinalMatrix[MatrixLines-1][(MatrixColumns-1)].Element = z;
CharPointer = strtok(NULL, " \n \0");
}
count += 1;
}
JourneyMetrics(MatrixCounting, GlobalSum);
File.close();
return 0;
}