-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMap.cpp
More file actions
115 lines (100 loc) · 2.78 KB
/
Map.cpp
File metadata and controls
115 lines (100 loc) · 2.78 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
#include<iostream>
#include<cstdlib>
#include"Map.h"
CityNodeAttr& GeoMap::operator[](const string &c_name)
{
return Nodes[c_name];
}
CitiesNext& GeoMap::GetNextNodes(const string &c_name)
{
return Nodes[c_name].second;
}
CitiesNext GeoMap::GetNodesAva(const string &c_name)
{
CitiesNext cities_temp;
for(auto temp:Nodes[c_name].second)
if(!IsVisited(temp.first))
cities_temp.insert(temp);
return cities_temp;
}
Sem_Dst& GeoMap::GetInfo(const string &c_name_src,const string &c_name_dst)
{
if(IsNext(c_name_src,c_name_dst))
return GetNextNodes(c_name_src)[c_name_dst];
else {
std::cout << c_name_dst
<< " is not next to "
<< c_name_src << std::endl;
exit(-1);
}
}
double& GeoMap::GetSem(const string &c_name_src,const string &c_name_dst)
{
return GetInfo(c_name_src,c_name_dst).first;
}
double& GeoMap::GetDst(const string &c_name_src,const string &c_name_dst)
{
return GetInfo(c_name_src,c_name_dst).second;
}
void GeoMap::AddCityNode(const string &c_name)
{
CitiesNext EmptyNext;
Nodes.insert({c_name,{false,EmptyNext}});
CityNames.insert(c_name);
}
void GeoMap::AddNextCity(const string &c_name_src,const string &c_name_dst,double d,double sem)
{
if(IsNext(c_name_src,c_name_dst))
return;
if(CityNames.find(c_name_src) == CityNames.end())
AddCityNode(c_name_src);
if(CityNames.find(c_name_dst) == CityNames.end())
AddCityNode(c_name_dst);
GetNextNodes(c_name_src).insert({c_name_dst,{sem,d}});
GetNextNodes(c_name_dst).insert({c_name_src,{sem,d}});
}
bool GeoMap::IsNext(const string &c_name_src,const string &c_name_dst)
{
CitiesNext temp_cities = GetNextNodes(c_name_src);
return (temp_cities.find(c_name_dst) != temp_cities.end());
}
bool GeoMap::IsVisited(const string &c_name)
{
if(Nodes.find(c_name) == Nodes.end()) {
std::cout << "No such city " << c_name << std::endl;
exit(-1);
}
return Nodes[c_name].first;
}
bool GeoMap::IsNode(const string &c_name)
{
return CityNames.find(c_name) != CityNames.end();
}
void GeoMap::UpdateSem(const double Q)
{
for(string c_name:CityNames) {
CitiesNext Cities = GetNextNodes(c_name);
for(auto temp:Cities)
temp.second.first *= Q;
}
}
void GeoMap::Show(const string &c_name)
{
CitiesNext Cities = GetNextNodes(c_name);
for(auto temp:Cities)
std::cout << temp.first << " "
<< temp.second.second << "km ";
std::cout << std::endl;
}
void GeoMap::SetVisited(const string& c_name)
{
if(!Nodes[c_name].first)
Nodes[c_name].first = true;
}
std::ostream& operator<<(std::ostream& os,GeoMap& map)
{
for(auto it:map.CityNames)
os << it << " ";
// os << std::endl;
return os;
}