-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstruction.cpp
More file actions
168 lines (152 loc) · 4.03 KB
/
construction.cpp
File metadata and controls
168 lines (152 loc) · 4.03 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <string>
#include <vector>
#include <regex>
#include <fstream>
#include <iostream>
#include "construction.h"
using namespace std;
void criaDotMaterias(vector<Materia> materias)
{
ofstream myfile("graphviz.dot");
if (myfile.is_open())
{
myfile << "graph G {\n";
for (auto curso : materias)
{
for (unsigned int i = 0; i < curso.conflitos.size(); i++)
{
myfile << " " << curso.nome;
myfile << " -- ";
myfile << curso.conflitos[i] << ";"
<< "\n";
}
if (materias.size() == 0)
{
cout << "--";
}
cout << endl;
}
}
else
cout << "Unable to open file";
myfile << "}";
myfile.close();
}
// for (unsigned int i = 0; i < grafo.size(); i++) {
// for (auto v : grafo[i]) {
// myfile << " " << nome[i];
// myfile << " -> ";
// myfile << nome[v] << ";" << "\n";
// }
// if (grafo[i].size() == 0) {
// cout << "--";
// }
// }
//Substitui um caractere por outro, usado para separar string
string replaceChar(string str, char ch1, char ch2)
{
for (unsigned int i = 0; i < str.length(); ++i)
{
if (str[i] == ch1)
str[i] = ch2;
}
return str;
}
//usado para separar string
vector<string> split(string s, char delim)
{
vector<string> flds;
if (!flds.empty())
{
flds.clear();
}
string work = s;
string buf = "";
unsigned int i = 0;
while (i < work.length())
{
if (work[i] != delim)
{
buf += work[i];
}
else if (buf.length() > 0)
{
flds.push_back(buf);
buf = "";
}
i++;
}
if (!buf.empty())
{
flds.push_back(buf);
}
return flds;
}
//cria vetor de materias com listas de materias vizinhas
void criaMateria(const string &fileName, vector<Materia> &materias)
{
fstream fileStream(fileName);
string buffer;
if (!fileStream.is_open())
return;
while (getline(fileStream, buffer))
{ //Cria as materias sem as listas
if (buffer.find("(") != string::npos)
{
int numero, credito;
char nome[100];
sscanf(buffer.c_str(), "(%d / %s / %d)", &numero, nome, &credito);
materias.push_back(Materia(numero, nome, credito));
}
//insere as materias conflito na lista de conflitos
if (buffer.find("[") != string::npos)
{
char teste[200];
string delim1 = ":";
string delim2 = "/";
string token;
vector<string> Steste;
sscanf(buffer.c_str(), "[%s", teste);
string teste2 = teste;
teste2 = replaceChar(teste2, ':', ' ');
teste2 = replaceChar(teste2, '/', ' ');
Steste = split(teste2, ' '); //[Calc, Apc, Isc, F]
string MateriaAtual = Steste[0];
int i = 0;
for (auto curso : materias)
{
if (curso.nome == MateriaAtual)
{
for (unsigned int j = 1; j < Steste.size(); j++)
{
materias[i].conflitos.push_back(Steste[j]);
}
}
else
i++;
}
}
}
}
void imprimeGrafo(vector<Materia> &materias)
{
for (auto curso : materias)
{
cout << "NomeCurso: " << curso.nome;
for (unsigned int i = 0; i < curso.conflitos.size(); i++)
{
cout << " " << curso.conflitos[i];
}
}
}
// void colorMateria(vector<Materia> &materias, vector<int> &CoresMaterias)
// {
// for (auto curso : materias)
// {//inicializa o vetor de cores nao iniciadas
// for (unsigned int i = 0; i < materias.size(); i++)
// {
// //inicializando o vetor cores com unassigned
// CoresMaterias[i] = -1;
// }
// }
// };