-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.cs
229 lines (169 loc) · 4.86 KB
/
Node.cs
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
using System;
using System.Collections.Generic;
using System.Collections;
//using System.Windows.Forms;
using System.Linq;
namespace GBusManager
{
// струкутра предназначенная для хранения
// пары соседний узел - номер маршрута
public struct AdjNode {
public Node node;
public int route;
Graph graph;
public AdjNode(Graph g, int nn, int rn){
graph = g;
node = g.GetNode(nn);
route = rn;
}
public override string ToString()
{
return "node "+ node.n + " ["+route+"]";
}
}
/// <summary>
/// Description of Node.
/// </summary>
[Serializable()]
public class Node
{
#region fields
// номер узла
public int n;
// минимальный автобусный маршрут
public int r = -1;
public Route route;
public Node prev;
public int prevn;
// длина минимального пути
public int len = int.MaxValue / 3;
Graph graph;
public Point point;
#endregion
int X;
int Y;
//Label label;
public ArrayList neighbors = new ArrayList();
//public List<AdjNode> neighbors2 = new List<AdjNode>();
public Dictionary<string, int> d = new Dictionary<string, int>();
public List<KeyValuePair<string, int>> h = new List<KeyValuePair<string, int>>();
//public Has
// посещена
public bool v;
//TODO:
// маршруты которые содержат эту точку
public HashSet<Route> routes = new HashSet<Route>();
public Dictionary<Route,int> routesValues = new Dictionary<Route,int>();
public bool NewRouteValue(Route r, int value){
if (routesValues.Keys.Contains(r)){
// уже есть с таким ключом
if (routesValues[r]>value){
routesValues[r] = value;
route = r;
len = value;
}
return false;
}
else {
routesValues.Add(r,value);
if (routesValues.Values.Min() > value)
{
Console.WriteLine("\tНо найдено меньшее значение");
route = r;
len = value;
}
return true;
}
}
public bool Visited
{
get
{
/*
foreach (int p in routesValues.Values)
{
if (p == int.MaxValue/2) return false;
}
return true;
*/
#if DEBUG
Console.WriteLine("Visited? {0}", n);
Console.WriteLine("_vc = {0} d.Count = {1} routes.Count = {2}", _vc,d.Count,routes.Count);
#endif
return (_vc >= d.Count && _vc >=routes.Count );
//return _vc == 1;
}
}
// visited counter
int _vc;
public void Visit(){
//if (_vc < .Count)
//{
_vc++;
//}
}
public void RouteVisit(Route r)
{
Console.WriteLine("у {0} route = {1}",this.n, r.n);
route = r;
}
public Node(Graph g, int bn)
{
graph = g;
n = bn;
len = int.MaxValue;
}
public Node(int bn, int x, int y)
{
//graph = g;
n = bn;
X = x;
Y = y;
//label = l;
len = int.MaxValue;
}
public Node(){
len = int.MaxValue;
}
// добавление смежного
public void AddAdj(int n, int r){
AdjNode an = new AdjNode(graph,n,r);
neighbors.Add(an);
//neighbors2.Add(an);
}
public Node Neighbor(int r, int d)
{
// r - route
// d - direction
return graph.GetNode(graph.routes[r].Near(n, d));
}
public override string ToString()
{
return n.ToString();
}
public string Info
{
get
{
string s = "Node " + n + " Info:\n\tСоседи:";
foreach (AdjNode an in neighbors)
{
s += "\n\t\t" + an.node.n + "[" + an.route + "]";
}
s += "\n\tМаршруты:";
foreach (Route r in routes)
{
s += "\n\t\t" + r.n;
}
s += "\n\tДлины путей:";
foreach (KeyValuePair<Route, int> kvp in routesValues)
{
s += "\n\t\t[" + kvp.Key.n+ "] " + kvp.Value;
}
return n + "\n" + s;
}
}
//public
}
}