-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
179 lines (172 loc) · 5.61 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include "Country.h"
using namespace std;
void prepareScene(vector<Scene>,vector<City>);
void prepareCity(vector<City>);
int main(){
//init
Country china;
vector<Scene> scenelist = china.initScene();//init provinces(SceneData.csv)/ init scenes in provinces
china.initProvinceDistance();//init distance between province(citycity.csv)
cout<<"Provinces: "<<china.provinces.size()<<endl;
vector<City> citylist = china.initCitylist();//init city list for ref(CityData.csv)
//prepareScene(scenelist,citylist);
//prepareCity(citylist);
//system("PAUSE");
china.initCity();//for all province:init cities(SceneDistance*.csv)/init sceneCity* Mat/init distance between cities(CityDistance.csv)/init shortest drive time between scenes
cout<<"Choose Start Province(default:26.XiAn):";
int start = 27;
//cin>>start;
china.setStartProvince(start);
for(int i=1;i<=31;i++) {
cout<<i<<":";
china.timeCalcTest(i);
cout<<china.split(i)<<endl;
}
china.compareTrainOrFlight();
bool *merged=new bool[china.provinces.size()];
for (int i=0;i<china.provinces.size();i++) {
merged[i]=false;
}
fstream fs("/Users/gyz/Workspaces/xcode/math/math/data/2.txt");
for(int i=0;i<china.realMergedCar.size();i++) {
fs<<"Merge Province: "<<china.realMergedCar[i].i<<" "<<china.realMergedCar[i].j<<endl;
fs<<china.provinces[china.realMergedCar[i].i].stMerge;
merged[china.realMergedCar[i].i]=true;
merged[china.realMergedCar[i].j]=true;
fs<<"Total price: "<<china.provinces[china.realMergedCar[i].i].costMerge<<endl;
}
for(int i=0;i<china.provinces.size();i++) {
if(!merged[i]) {
china.provinces[i].calcCar();
fs<<"Province: "<<i<<endl;
switch (china.provinces[i].choice()) {
case 0:
fs<<china.provinces[i].stCar;
fs<<"Total price: "<<china.provinces[i].costCar;
break;
case 1:
fs<<china.provinces[i].stTrain;
fs<<"Total price: "<<china.provinces[i].costTrain;
break;
case 2:
fs<<china.provinces[i].stFlight;
fs<<"Total price: "<<china.provinces[i].costFlight;
break;
case 3:
fs<<china.provinces[i].stTrainFlight;
fs<<"Total price: "<<china.provinces[i].costTrainFlight;
break;
case 4:
fs<<china.provinces[i].stFlightTrain;
fs<<"Total price: "<<china.provinces[i].costFlightTrain;
break;
}
}
}
fs.close();
// china.timeCalcTest(10);
// cout<<china.provinces[9].timeCalc(china.provinces[9].mina)<<endl;
//system("PAUSE");
return 0;
}
void prepareScene(vector<Scene> scenelist,vector<City> citylist){
cout<<"Start Scene data preparing..."<<endl;
int provinceNum = 31;
vector<vector<string> > provinces;
for(int i=0;i<provinceNum;i++){
vector<string> tmp;
provinces.push_back(tmp);
}
char buffer[1024];
int sceneidx,cityidx;
int belong;
ifstream infile("/Users/gyz/Workspaces/xcode/math/math/data/SceneDistance.csv");
while(infile>>buffer){
sscanf(buffer,"%d;%d;",&sceneidx,&cityidx);
for(int i=0;i<scenelist.size();i++){
if(scenelist[i].idx==sceneidx){
belong = scenelist[i].belong;
//cout<<"scene:"<<sceneidx<<" belong:"<<belong<<endl;
break;
}
}
for(int i=0;i<citylist.size();i++){
if(citylist[i].idx==cityidx){
if(belong==citylist[i].belong){
provinces[belong-1].push_back(string(buffer));
}
break;
}
}
}
infile.close();
//write
ofstream outfile;
for(int i=0;i<provinceNum;i++){
char filename[1024];
sprintf(filename,"/Users/gyz/Workspaces/xcode/math/math/data/SceneDistance%d.csv",i+1);
cout<<filename<<endl;
outfile.open(filename);
for(int j=0;j<provinces[i].size();j++){
cout<<provinces[i][j]<<endl;
outfile<<provinces[i][j]<<'\n';
}
outfile.close();
}
//system("PAUSE");
}
void prepareCity(vector<City> citylist){
cout<<"Start City data preparing..."<<endl;
int provinceNum = 31;
vector<vector<string> > provinces;
for(int i=0;i<provinceNum;i++){
vector<string> tmp;
provinces.push_back(tmp);
}
char buffer[1024];
int startcityidx,endcityidx;
int belong;
ifstream infile("/Users/gyz/Workspaces/xcode/math/math/data/CityDistance.csv");
while(infile>>buffer){
sscanf(buffer,"%d;%d;",&startcityidx,&endcityidx);
if(startcityidx==31) {
//system("PAUSE");
}
for(int i=0;i<citylist.size();i++){
//cout<<i<<endl;
if(citylist[i].idx==startcityidx){
belong = citylist[i].belong;
break;
}
}
for(int i=0;i<citylist.size();i++){
if(citylist[i].idx==endcityidx){
if(belong==citylist[i].belong){
provinces[belong-1].push_back(string(buffer));
cout<<startcityidx<<"->"<<endcityidx<<":"<<belong<<endl;
}
break;
}
}
}
infile.close();
cout<<provinces.size()<<endl;
cout<<provinces[0].size()<<endl;
//write
for(int i=0;i<provinceNum;i++){
char filename[1024];
sprintf(filename,"/Users/gyz/Workspaces/xcode/math/math/data/CityDistance%d.csv",i+1);
cout<<filename<<endl;
ofstream outfile(filename);
for(int j=0;j<provinces[i].size();j++){
outfile<<provinces[i][j]<<'\n';
}
outfile.close();
}
//system("PAUSE");
}