HOG2
absmapalgorithms
AbsMapPatrolUnit.cpp
Go to the documentation of this file.
1
// * patrolUnit.cpp
3
// * hog
4
// *
5
// * Created by Nathan Sturtevant on 3/23/06.
6
// * Copyright 2006 Nathan Sturtevant, University of Alberta. All rights reserved.
7
// *
8
// * This file is part of HOG.
9
// *
10
// * HOG is free software; you can redistribute it and/or modify
11
// * it under the terms of the GNU General Public License as published by
12
// * the Free Software Foundation; either version 2 of the License, or
13
// * (at your option) any later version.
14
// *
15
// * HOG is distributed in the hope that it will be useful,
16
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// * GNU General Public License for more details.
19
// *
20
// * You should have received a copy of the GNU General Public License
21
// * along with HOG; if not, write to the Free Software
22
// * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
// *
24
// */
25
//
26
//#include "AbsMapPatrolUnit.h"
27
//
28
//using namespace GraphAbstractionConstants;
29
//
30
//AbsMapPatrolUnit::AbsMapPatrolUnit(int _x, int _y, SearchAlgorithm* alg)
31
//:SearchUnit(_x,_y,NULL,alg)
32
//{
33
// std::cout<<"Being created\n";
34
// xyLoc l;
35
// l.x = _x;
36
// l.y = _y;
37
// Locs.push_back(l);
38
//
39
// //setObjectType(kWorldObject);
40
// currTarget = -1;
41
// nodesExpanded = nodesTouched = 0;
42
//}
43
//
60
//
61
//AbsMapPatrolUnit::~AbsMapPatrolUnit()
62
//{
63
//}
64
//
65
//bool AbsMapPatrolUnit::makeMove(MapProvider *mp, reservationProvider *, AbsMapSimulationInfo *, tDirection &dir)
66
//{
67
// std::cout<<"CurrTarget "<<currTarget<<std::endl;
68
// MapAbstraction *aMap = mp->GetMapAbstraction();
69
// if (moves.size() > 0)
70
// {
71
// dir = moves.back();
72
// moves.pop_back();
73
// return true;
74
// }
75
//
76
// if (currTarget != -1)
77
// {
78
// goToLoc(aMap, currTarget);
79
// currTarget = (currTarget+1)%Locs.size();
80
// if (moves.size() > 0)
81
// {
82
// dir = moves.back();
83
// moves.pop_back();
84
// return true;
85
// }
86
// }
87
// dir = kStay;
88
// return true;
89
//}
90
//
91
//double AbsMapPatrolUnit::goToLoc(MapAbstraction *aMap, int which)
92
//{
93
// std::cout<<"goToLoc\n";
94
// double pathCost=-1;
95
// path *p;
96
// node *from, *to;
97
// from = aMap->GetNodeFromMap(loc.x, loc.y); // gets my location
98
// int tox=Locs[which].x;
99
// int toy=Locs[which].y;
100
// //Locs[which].getLocation(tox, toy);
102
// to = aMap->GetNodeFromMap(tox, toy);
103
// p = algorithm->GetPath(aMap, from, to);
104
// nodesExpanded += algorithm->GetNodesExpanded();
105
// nodesTouched += algorithm->GetNodesTouched();
106
// if (p)
107
// {
108
// pathCost = aMap->distance(p);
109
// addPathToCache(p);
110
// }
111
// return pathCost;
112
//}
113
//
114
//void AbsMapPatrolUnit::OpenGLDraw(const AbsMapEnvironment *ame, const AbsMapSimulationInfo *) const
115
//
116
//{
117
// GLdouble xx, yy, zz, rad;
118
// Map *map = ame->GetMap();
119
// int posx = loc.x, posy = loc.y;
120
// map->GetOpenGLCoord(posx, posy, xx, yy, zz, rad);
121
// glColor3f(r, g, b);
122
// glBegin(GL_LINE_STRIP);
124
// glVertex3f(xx, yy, zz-rad/2);
125
// for (int t = moves.size()-1; t >= 0; t--)
126
// {
127
// posx += ((moves[t]&kE)?1:0) - ((moves[t]&kW)?1:0);
128
// posy += ((moves[t]&kS)?1:0) - ((moves[t]&kN)?1:0);
129
//
130
// map->GetOpenGLCoord(posx, posy, xx, yy, zz, rad);
131
//
133
// glVertex3f(xx, yy, zz-rad/2);
134
// }
135
// glEnd();
136
//
137
// map->GetOpenGLCoord(loc.x, loc.y, xx, yy, zz, rad);
138
// glColor3f(r, g, b);
139
// DrawSphere(xx, yy, zz, rad);
140
//}
141
//
142
//void AbsMapPatrolUnit::addPatrolLocation(xyLoc ru)
143
//{
144
//
145
// currTarget = 1;
146
// Locs.push_back(ru);
147
//}
148
//
149
//xyLoc AbsMapPatrolUnit::GetGoal()
150
//{
151
// if (currTarget == -1)
152
// {
153
// xyLoc l;
154
// l.x = -1;
155
// l.y = -1;
156
// return l;
157
// }
158
// return Locs[currTarget];
159
//}
160
//
161
//void AbsMapPatrolUnit::addPathToCache(path *p)
162
//{
163
// // we are at the last move; abort recursion
164
// if ((p == NULL) || (p->next == NULL))
165
// return;
166
// // there is another move; add it first to cache
167
// if (p->next->next)
168
// addPathToCache(p->next);
169
//
170
// // ----- Ok, we have a path starting at (x,y) [the current location] and
171
// // having at least one more state ----------------------------------------
172
//
173
// // Take the first move off the path and execute it
174
// int result = kStay;
175
//
176
// // Decide on the horizontal move
177
// switch ((p->n->GetLabelL(kFirstData)-p->next->n->GetLabelL(kFirstData)))
178
// {
179
// case -1: result = kE; break;
180
// case 0: break;
181
// case 1: result = kW; break;
182
// default :
183
// printf("SU: %s : The (x) nodes in the path are not next to each other!\n",
184
// this->GetName());
185
// printf("Distance is %ld\n",
186
// p->n->GetLabelL(kFirstData)-p->next->n->GetLabelL(kFirstData));
187
// std::cout << *p->n << "\n" << *p->next->n << "\n";
188
// exit(10); break;
189
// }
190
//
191
// // Tack the vertical move onto it
192
// // Notice the exploit of particular encoding of kStay, kE, etc. labels
193
// switch ((p->n->GetLabelL(kFirstData+1)-p->next->n->GetLabelL(kFirstData+1)))
194
// {
195
// case -1: result = result|kS; break;
196
// case 0: break;
197
// case 1: result = result|kN; break;
198
// default :
199
// printf("SU: %s : The (y) nodes in the path are not next to each other!\n",
200
// this->GetName());
201
// printf("Distance is %ld\n",
202
// p->n->GetLabelL(kFirstData+1)-p->next->n->GetLabelL(kFirstData+1));
203
// std::cout << *p->n << "\n" << *p->next->n << "\n";
204
// exit(10); break;
205
// }
206
// moves.push_back((tDirection)result);
207
//}
208
//
209
//void AbsMapPatrolUnit::logStats(StatCollection *stats)
210
//{
211
// if (((nodesExpanded == 0) && (nodesTouched != 0)) ||
212
// ((nodesExpanded != 0) && (nodesTouched == 0)))
213
// {
214
// printf("Error; somehow nodes touched/expanded are inconsistent. t:%d e:%d\n",
215
// nodesTouched, nodesExpanded);
216
// }
217
// // printf("SearchUnit::logStats(nodesExpanded=%d, nodesTouched=%d)\n",nodesExpanded,nodesTouched);
218
// if (nodesExpanded != 0)
219
// stats->AddStat("nodesExpanded", GetName(), (long)nodesExpanded);
220
// if (nodesTouched != 0)
221
// stats->AddStat("nodesTouched", GetName(), (long)nodesTouched);
222
// nodesExpanded = nodesTouched = 0;
223
//}
224
//
225
//void AbsMapPatrolUnit::LogFinalStats(StatCollection *stats)
226
//{
227
// algorithm->LogFinalStats(stats);
228
//}
Generated by
1.8.17