-
Notifications
You must be signed in to change notification settings - Fork 2
/
processFile.h
103 lines (94 loc) · 2.48 KB
/
processFile.h
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
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <algorithm>
#include <vector>
#include "Graph.h"
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
#include <cstdlib>
class processFile{
private:
double maxCost;
double minCost;
public:
processFile(){maxCost = 0; minCost = std::numeric_limits<double>::infinity();}
void processFileOld(Graph *g, ifstream &inFile);
void processEFile(Graph *g, ifstream &inFile);
void processRFile(Graph *g, ifstream &inFile);
void reset(){maxCost = 0; minCost = std::numeric_limits<double>::infinity();}
double getMax(){return maxCost;}
double getMin(){return minCost;}
};
void processFile::processFileOld(Graph *g, ifstream &inFile) {
int eCount, vCount;
int i, j;
double cost;
// Create each vertex after getting vertex count
inFile >> vCount;
cout << vCount << endl;
for(int i = 1; i <= vCount; i++) {
g->insertVertex(i);
}
// Create each edge after processing edge count
eCount = vCount*(vCount-1)/2;
for(int e = 0; e < eCount; e++) {
inFile >> i >> j >> cost;
g->insertEdge(i, j, cost);
if (cost > maxCost)
maxCost = cost;
if (cost < minCost)
minCost = cost;
}
}
void processFile::processEFile(Graph *g, ifstream &inFile) {
double x,y,cost;
int eCount, vCount;
// Create each vertex after getting vertex count
inFile >> vCount;
cout << vCount << endl;
for(int i = 1; i <= vCount; i++) {
inFile >> x >> y;
g->insertVertex(i, x, y);
}
// Create each edge after processing edge count
eCount = vCount*(vCount-1)/2;
for(int v1 = 1; v1 <= vCount; v1++) {
for(int j = 1; v1 + j <= vCount; j++) {
cost = g->insertEdge(v1, v1 + j);
if (cost > maxCost) {
maxCost = cost;
}
if (cost < minCost) {
minCost = cost;
}
}
}
}
void processFile::processRFile(Graph *g, ifstream &inFile) {
double cost;
int eCount, vCount;
// Create each vertex after getting vertex count
inFile >> vCount;
cout << vCount << endl;
for(int i = 1; i <= vCount; i++) {
g->insertVertex(i);
}
// Create each edge after processing edge count
eCount = vCount*(vCount-1)/2;
for(int v1 = 1; v1<= vCount; v1++) {
for(int j = 1; j <= vCount; j++){
inFile >> cost;
if(j > v1){
g->insertEdge(v1, j, cost);
if (cost > maxCost)
maxCost = cost;
if (cost < minCost)
minCost = cost;
}
}
}
}