HOG2
RoboticArm.h
Go to the documentation of this file.
1 /*
2  * RoboticArm.h
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 11/15/08.
6  * Copyright 2008 __MyCompanyName__. All rights reserved.
7  *
8  */
9 
10 #ifndef ROBOTICARM_H
11 #define ROBOTICARM_H
12 
13 #include <stdint.h>
14 #include <iostream>
15 #include <string.h>
16 #include <cinttypes>
17 #include "Map.h"
18 #include "SearchEnvironment.h"
19 #include "UnitSimulation.h"
20 #include "ReservationProvider.h"
21 #include "ConfigEnvironment.h"
22 #include "FrontierBFS.h"
23 #include <cassert>
24 
25 //#include "BaseMapOccupancyInterface.h"
26 
27 
28 
29 class armAngles {
30 public:
31  armAngles() { angles = 0; }
32  int GetAngle(int which) const;
33  void SetAngle(int which, int value);
34  int GetNumArms() const;
35  void SetNumArms(int count);
36  void SetGoal(double x, double y);
37  void GetGoal(double &x, double &y) const;
38  bool IsGoalState() const;
39  uint64_t angles;
40 };
41 
42 static std::ostream& operator <<(std::ostream & out, const armAngles &loc)
43 {
44  if (loc.IsGoalState())
45  {
46  double x, y;
47  loc.GetGoal(x, y);
48  out << "(" << x << ", " << y << ")" << std::endl;
49  }
50  else {
51  out << "[";
52  for (int x = 0; x < loc.GetNumArms()-1; x++)
53  out << loc.GetAngle(x) << ", ";
54  out << loc.GetAngle(loc.GetNumArms()-1) << "]";
55  }
56  return out;
57 }
58 
59 static bool operator==(const armAngles &l1, const armAngles &l2) {
60  return (l1.angles == l2.angles);
61 }
62 
63 enum tRotation {
64  kRotateCCW = -1,
67 };
68 
69 class armRotations {
70 public:
72  :rotations() {}
73  uint16_t rotations;
74  tRotation GetRotation(int which) const;
75  void SetRotation(int which, tRotation dir);
76 };
77 
78 static bool operator==(const armRotations &l1, const armRotations &l2) {
79  return (l1.rotations == l2.rotations);
80 }
81 
83 public:
84  virtual ~RoboticArmHeuristic() {}
85  virtual double HCost(const armAngles &node1, const armAngles &node2) const = 0;
86 };
87 
88 class RoboticArm : public SearchEnvironment<armAngles, armRotations>
89 {
90 public:
91  RoboticArm(int DOF, double armLength, double tolerance = 0.01);
92  virtual ~RoboticArm();
93 
94  double GetTolerance() const { return tolerance; }
95  void GetTipPosition( armAngles &s, double &x, double &y );
97  const double minX=-1, const double minY=-1,
98  const double width=2 );
99 
100  void AddObstacle(line2d obs);
101  void PopObstacle();
102  void GetSuccessors(const armAngles &nodeID, std::vector<armAngles> &neighbors) const;
103  void GetActions(const armAngles &nodeID, std::vector<armRotations> &actions) const;
104  armRotations GetAction(const armAngles &s1, const armAngles &s2) const;
105  virtual void ApplyAction(armAngles &s, armRotations dir) const;
107 
108  virtual bool InvertAction(armRotations &a) const;
109 
110  void AddHeuristic(RoboticArmHeuristic *h) { heuristics.push_back(h); }
111 
112  virtual double HCost(const armAngles &) const {
113  printf("Single State HCost Failure: method not implemented for RoboticArm\n");
114  exit(0); return -1.0;}
115 
116  virtual double HCost(const armAngles &node1, const armAngles &node2) const;
117 
118  virtual double GCost(const armAngles &, const armAngles &) const { return 1; }
119  virtual double GCost(const armAngles &, const armRotations &) const { return 1; }
120  bool GoalTest(const armAngles &node, const armAngles &goal) const;
121  void GetStateFromHash(uint64_t hash, armAngles &) const;
122  uint64_t GetStateHash(const armAngles &node) const;
123  uint64_t GetActionHash(armRotations act) const;
124 
125  virtual void OpenGLDraw() const;
126  virtual void OpenGLDraw(const armAngles &l) const;
127  virtual void OpenGLDraw(const armAngles &, const armRotations &) const;
128  virtual void OpenGLDraw(const armAngles&, const armAngles&, float) const {}
129 // virtual void OpenGLDraw(const armAngles &, const armRotations &, GLfloat r, GLfloat g, GLfloat b) const;
130 // virtual void OpenGLDraw(const armAngles &l, GLfloat r, GLfloat g, GLfloat b) const;
131 
132  virtual void GetNextState(const armAngles &currents, armRotations dir, armAngles &news) const;
133 
134  bool LegalState(armAngles &a) const;
135  bool LegalArmConfig(armAngles &a) const;
136 
137  void StoreGoal(armAngles &) {}
138  void ClearGoal(){}
139  bool IsGoalStored()const {return false;}
140  virtual bool GoalTest(const armAngles &) const {
141  printf("Single State Goal Test Failure: method not implemented for RoboticArm\n");
142  exit(0); return false;}
143 
144 private:
145  void DrawLine(line2d l) const;
146  void GenerateLineSegments(const armAngles &a, std::vector<line2d> &armSegments) const;
147 
148  int DOF;
150  std::vector<std::vector<bool> > legals;
151 
152  double GetSin(int angle) const;
153  double GetCos(int angle) const;
154  void BuildSinCosTables();
155  std::vector<double> sinTable;
156  std::vector<double> cosTable;
157  std::vector<line2d> obstacles;
158  mutable std::vector<line2d> armSegments;
159 
160  mutable std::vector<recVec> states;
161 
162  std::vector<RoboticArmHeuristic *> heuristics;
164 };
165 
167 public:
168  ArmToArmHeuristic(RoboticArm *r, armAngles &initial, bool optimize = false);
169  virtual ~ArmToArmHeuristic() {}
170  double HCost(const armAngles &node1, const armAngles &node2) const;
171  void AddDiffTable();
172  bool IsLegalState(armAngles &arm);
173  const std::vector<armAngles> &GetTipPositions(double x, double y)
174  { return tipPositionTables[TipPositionIndex(x, y)]; }
175 private:
177  int TipPositionIndex(const double x, const double y,
178  const double minX = -1.0, const double minY = -1.0,
179  const double width = 2.0);
180  void GenerateLegalStates(armAngles &init);
183  std::vector<std::vector<uint16_t> > distances;
184  std::vector<armAngles> canonicalStates;
185  std::vector<std::vector<armAngles> > tipPositionTables;
186  std::vector<bool> legalStates;
187 };
188 
190 public:
192  {
193  r = ra;
194  Load(file);
195  }
196  ArmToArmCompressedHeuristic(RoboticArm *ra, std::vector<int> reductionPower, std::vector<int> offset)
197  {
198  r = ra;
199  reduction = reductionPower;
200  // we are actually only using 9 of the bits anyway
201  // strip 1, 2, 3, 4 or 5 additional bits
202  uint64_t mask[6] = {0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F }; //{ 0x3FC, 0x3F8, 0x3F0, 0x3E0, 0x3C0 };
203  theMask = theResult = 0;
204  theSize = 1;
205  for (int x = reduction.size()-1; x >= 0 ; x--)
206  {
207  theMask = (theMask<<(10))|(mask[reduction[x]-1]);
208  theResult = (theResult<<(10))|(offset[x]<<1);
209  theSize *= 512/pow(2,reduction[x]-1);
210  }
211  //theSize = (uint32_t)pow(512/reductionPower, numArms);
212  printf("Using mask 0x%llX\n", theMask);
213  printf("Using result 0x%llX\n", theResult);
214  printf("%" PRId64 " entries in table\n", theSize);
215  distances = new uint16_t[theSize];
216  memset ( distances, 0xFFFF, theSize*sizeof(uint16_t) );
217  }
218  ArmToArmCompressedHeuristic(RoboticArm *ra, int numArms, int reductionPower, int offset = 0)
219  {
220  r = ra;
221 // reduction = reductionPower;
222  // we are actually only using 9 of the bits anyway
223  // strip 1, 2, 3, 4 or 5 additional bits
224  uint64_t mask[5] = {0x3, 0x7, 0xF, 0x1F, 0x3F }; //{ 0x3FC, 0x3F8, 0x3F0, 0x3E0, 0x3C0 };
225  theMask = theResult = 0;
226  for (int x = 0; x < numArms; x++)
227  {
228  reduction.push_back(reductionPower);
229  theMask = (theMask<<(10))|(mask[reductionPower-2]);
230  theResult = (theResult<<(10))|(offset<<1);
231  }
232  theSize = (uint32_t)pow(512/reductionPower, numArms);
233  printf("Using mask 0x%llX\n", theMask);
234  printf("Using result 0x%llX\n", theResult);
235  printf("%" PRId64 " entries in table\n", theSize);
236  distances = new uint16_t[theSize];
237  }
239  {
240  delete [] distances;
241  }
242  // takes start state and returns farthest state from it
244  {
245  memset ( distances, 0xFFFF, theSize*sizeof(uint16_t) );
246 
248  printf("Performing frontier BFS!\n");
249 
250  std::cout << "Using " << config << " as basis for heuristic." << std::endl;
251  int depth = 0;
252  armAngles tmp = config;
253  fbfs.InitializeSearch(r, tmp);
254  while (!fbfs.DoOneIteration(r))
255  {
256  const FrontierBFSClosedList closed = fbfs.GetCurrentClosedList();
257  for (FrontierBFSClosedList::const_iterator it = closed.begin(); it != closed.end(); it++)
258  {
259  r->GetStateFromHash((*it).first, tmp);
260  AddState(tmp, depth);
261  //assert(r->HCost(tmp, config) <= depth);
262  }
263  depth++;
264  }
265  return tmp;
266  }
267 
268  // takes set of start states, finds farthest to build heuristic from, and returns source of heuristic
269  armAngles BuildHeuristic(std::vector<armAngles> &config)
270  {
271  memset ( distances, 0xFFFF, theSize*sizeof(uint16_t) );
272 
274  printf("Performing frontier BFS!\n");
275  //std::cout << "Starting from " << config[0] << std::endl;
276 
277  armAngles tmp = config[0];
278  armAngles source = tmp;
279 
280  std::cout << "Finding farthest states from: ";
281  for (unsigned int x = 0; x < config.size(); x++)
282  std::cout << config[x] << " ";
283  std::cout << std::endl;
284  fbfs.InitializeSearch(r, config);
285  while (!fbfs.DoOneIteration(r))
286  {
287  const FrontierBFSClosedList closed = fbfs.GetCurrentClosedList();
288  for (FrontierBFSClosedList::const_iterator it = closed.begin(); it != closed.end(); it++)
289  {
290  r->GetStateFromHash((*it).first, tmp);
291  }
292  }
293 
294  std::cout << "Using " << tmp << " as basis for heuristic." << std::endl;
295  int depth = 0;
296  source = tmp;
297  fbfs.InitializeSearch(r, tmp);
298  while (!fbfs.DoOneIteration(r))
299  {
300  const FrontierBFSClosedList closed = fbfs.GetCurrentClosedList();
301  for (FrontierBFSClosedList::const_iterator it = closed.begin(); it != closed.end(); it++)
302  {
303  r->GetStateFromHash((*it).first, tmp);
304  AddState(tmp, depth);
305  //assert(r->HCost(tmp, config) <= depth);
306  }
307  depth++;
308  }
309  return source;
310  }
311  void AddState(armAngles &a, int dist)
312  {
313  //printf("Using mask 0x%llX on 0x%llX (0x%llX) (0x%llX)?\n", theMask, a.angles, a.angles&theMask, theResult);
314  if ((a.angles&theMask) != theResult)
315  return;
316  uint64_t index = GetIndex(a);
317  assert(distances[index] == 0xFFFF);
318  //std::cout << a << " goes in the table with index " << index << " : " << (a.angles&0xFFFFFFFF) << std::endl;
319  distances[index] = dist;
320  }
321  uint64_t GetIndex(const armAngles &a) const
322  {
323  //std::cout << "Index of " << a << " : " << (a.angles&0xFFFFFFFF) << " is ";
324  uint64_t index = 0;
325  for (int x = 0; x < a.GetNumArms(); x++)
326  {
327  index = (index<<(10-reduction[x]))|(a.GetAngle(x)>>reduction[x]);
328  //std::cout << index << ", ";
329  }
330  //std::cout << std::endl;
331  assert(index < theSize);
332  return index;
333  }
334 
335  double HCost(const armAngles &from, const armAngles &to) const
336  {
337  if ((from.angles&theMask) != theResult)
338  return 0;
339  if (!(to == goal))
340  SetupGoal(to);
341  double heuristic = 0;
342  assert(distances[GetIndex(from)]<10000);
343  double baseDist = distances[GetIndex(from)];
344  for (unsigned int x = 0; x < values.size(); x++)
345  {
346  heuristic = max(heuristic, std::abs(baseDist-values[x])-errors[x]);
347  }
348  return heuristic;
349  }
350 
351  void SetupGoal(const armAngles &referenceState) const
352  {
353  values.resize(0);
354  errors.resize(0);
356  armAngles tmp = referenceState;
357  goal = referenceState;
358  int depth = 0;
359  fbfs.InitializeSearch(r, tmp);
360  while (!fbfs.DoOneIteration(r))
361  {
362  const FrontierBFSClosedList closed = fbfs.GetCurrentClosedList();
363  for (FrontierBFSClosedList::const_iterator it = closed.begin(); it != closed.end(); it++)
364  {
365  r->GetStateFromHash((*it).first, tmp);
366  if ((tmp.angles&theMask) == theResult)
367  {
368  std::cout << "Found state " << tmp << " distance " << distances[GetIndex(tmp)] << " with error " << depth << std::endl;
369  values.push_back(distances[GetIndex(tmp)]);
370  errors.push_back(depth);
371  }
372  }
373  if (values.size() > 0)
374  return;
375  depth++;
376  }
377  }
378 
379  void Save(const char *file)
380  {
381  FILE *f = fopen(file, "w+");
382  if (f == 0) assert(!"file could not be opened");
383  fprintf(f, "%" PRId64 " %" PRId64 " %" PRId64 " %d\n", theSize, theMask, theResult, (int)reduction.size());
384  fwrite(&reduction[0], sizeof(int), reduction.size(), f);
385  fwrite(distances, sizeof(uint16_t), theSize, f);
386  fclose(f);
387  }
388  void Load(const char *file)
389  {
390  int numArms;
391  FILE *f = fopen(file, "r");
392  if (f == 0) assert(!"file could not be opened");
393  fscanf(f, "%" PRId64 " %" PRId64 " %" PRId64 " %d\n", &theSize, &theMask, &theResult, &numArms);
394  reduction.resize(numArms);
395  fread(&reduction[0], sizeof(int), reduction.size(), f);
396  distances = new uint16_t[theSize];
397  fread(distances, sizeof(uint16_t), theSize, f);
398  fclose(f);
399  }
400 private:
401  uint64_t theSize;
402  std::vector<int> reduction;
403 
404  // caching for each goal state
405  mutable std::vector<int> values;
406  mutable std::vector<int> errors;
407  mutable armAngles goal;
409  uint16_t *distances;
410  uint64_t theMask;
411  uint64_t theResult;
412 };
413 
415 public:
417  virtual ~ArmToTipHeuristic() {}
418  double HCost(const armAngles &node1, const armAngles &node2) const;
419 
420  void GenerateLegalStateTable( armAngles &legalArm );
421  void GenerateTipPositionTables( armAngles &sampleArm );
422 
423  void GenerateRandomHeuristic( const armAngles &sampleArm );
424  int GenerateHeuristic( const armAngles &sampleArm, armAngles &goal );
425  int GenerateMaxDistHeuristics( const armAngles &sampleArm,
426  const int numHeuristics );
427  // Returns true if the position is guaranteed to be valid.
428  // Returns false if the position is either unvalid,
429  // or possibly unvalid
430  bool ValidGoalPosition( double goalX, double goalY );
431 private:
432  void GenerateCPDB();
433 
434 
437 
438  uint8_t *legalStateTable;
439  uint8_t *legalGoalTable;
440 
441  std::vector<uint16_t *> distancesTables;
442  std::vector<uint16_t *> minTipDistancesTables;
443  std::vector<uint16_t *> maxTipDistancesTables;
444  std::vector<uint16_t> tablesNumArms;
445 
446  std::vector<armAngles> *tipPositionTables;
447 
448 
449  // convert an arm configuration into an index
450  uint64_t ArmAnglesIndex( const armAngles &arm ) const;
451  uint64_t NumArmAnglesIndices( const armAngles &arm ) const {
452  return 1 << ( 9 * arm.GetNumArms() );
453  }
454 
455  // convert a tip position into an index
456  int TipPositionIndex( const double x, const double y,
457  const double minX, const double minY,
458  const double width ) const;
459  int NumTipPositionIndices() const {
460  int count = (int)ceil( 2.0 / ra->GetTolerance() );
461  return count * count;
462  }
463 
464  // write/read a binary representation of a configuration
465  // DOES NOT WRITE/READ THE ARM LENGTHS!
466  int WriteArmAngles(FILE *file, armAngles &a);
467  int ReadArmAngles(FILE *file, armAngles &a);
468 
469  void UpdateTipDistances( armAngles &arm, uint16_t distance,
470  uint16_t *minTipDistances,
471  uint16_t *maxTipDistances );
472 
473  // common subroutine for all the different heuristic
474  // generation functions
475  int GenerateHeuristicSub( const armAngles &sampleArm, const bool quiet,
476  armAngles *goals, const int numGoals,
477  uint16_t *distances,
478  uint16_t *minTipDistances,
479  uint16_t *maxTipDistances,
480  armAngles &lastAdded );
481  // function needed for GenerateHeuristic
482  // given a file curFile of the frontier of positions at depth
483  // curDistance, generates a file of the positions at curDistance+1
484  // uses and updates distances[] to avoid re-visiting positions
485  // if XXXTipDistances are not NULL, it will update XXXTipDistances
486  // to be the min/maximum distance for all positions with that
487  // tip position
488  uint64_t GenerateNextDepth( FILE *curFile, FILE *nextFile,
489  uint16_t curDistance, uint16_t *distances,
490  uint16_t *minTipDistances,
491  uint16_t *maxTipDistances,
492  armAngles &lastAdded );
493 
494  // use a heuristic table
495  uint16_t UseHeuristic(const armAngles &s, armAngles &g,
496  uint16_t *distances ) const;
497  uint16_t UseHeuristic(const armAngles &arm, double goalX, double goalY,
498  uint16_t *distances, uint16_t *minTipDistances,
499  uint16_t *maxTipDistances ) const;
500 };
501 
502 //typedef UnitSimulation<armAngles, armRotations, MapEnvironment> UnitMapSimulation;
503 
504 #endif
RoboticArm::legals
std::vector< std::vector< bool > > legals
Definition: RoboticArm.h:150
ArmToTipHeuristic
Definition: RoboticArm.h:414
ArmToArmCompressedHeuristic::ArmToArmCompressedHeuristic
ArmToArmCompressedHeuristic(RoboticArm *ra, const char *file)
Definition: RoboticArm.h:191
RoboticArmHeuristic::~RoboticArmHeuristic
virtual ~RoboticArmHeuristic()
Definition: RoboticArm.h:84
UnitSimulation.h
ArmToArmCompressedHeuristic::theSize
uint64_t theSize
Definition: RoboticArm.h:401
armAngles::SetAngle
void SetAngle(int which, int value)
Definition: RoboticArm.cpp:43
ArmToTipHeuristic::NumTipPositionIndices
int NumTipPositionIndices() const
Definition: RoboticArm.h:459
RoboticArm::GetAction
armRotations GetAction(const armAngles &s1, const armAngles &s2) const
Definition: RoboticArm.cpp:219
RoboticArm::GetTolerance
double GetTolerance() const
Definition: RoboticArm.h:94
RoboticArm::GetStateFromHash
void GetStateFromHash(uint64_t hash, armAngles &) const
Definition: RoboticArm.cpp:390
ArmToArmCompressedHeuristic::ArmToArmCompressedHeuristic
ArmToArmCompressedHeuristic(RoboticArm *ra, std::vector< int > reductionPower, std::vector< int > offset)
Definition: RoboticArm.h:196
ConfigEnvironment
Definition: ConfigEnvironment.h:15
armAngles::angles
uint64_t angles
Definition: RoboticArm.h:39
RoboticArm::OpenGLDraw
virtual void OpenGLDraw() const
Definition: RoboticArm.cpp:404
RoboticArm::sinTable
std::vector< double > sinTable
Definition: RoboticArm.h:155
RoboticArm::ApplyAction
virtual void ApplyAction(armAngles &s, armRotations dir) const
Definition: RoboticArm.cpp:229
ArmToArmCompressedHeuristic::values
std::vector< int > values
Definition: RoboticArm.h:405
FrontierBFSClosedList
std::unordered_map< uint64_t, bool, Hash64 > FrontierBFSClosedList
Definition: FrontierBFS.h:18
ArmToArmCompressedHeuristic::distances
uint16_t * distances
Definition: RoboticArm.h:409
FrontierBFS::GetCurrentClosedList
const FrontierBFSClosedList & GetCurrentClosedList()
Definition: FrontierBFS.h:34
armRotations
Definition: RoboticArm.h:69
RoboticArm::GoalTest
bool GoalTest(const armAngles &node, const armAngles &goal) const
Definition: RoboticArm.cpp:362
RoboticArm::OpenGLDraw
virtual void OpenGLDraw(const armAngles &, const armAngles &, float) const
Draw the transition at some percentage 0...1 between two states.
Definition: RoboticArm.h:128
ArmToArmCompressedHeuristic::reduction
std::vector< int > reduction
Definition: RoboticArm.h:402
operator<<
static std::ostream & operator<<(std::ostream &out, const armAngles &loc)
Definition: RoboticArm.h:42
ArmToArmCompressedHeuristic::GetIndex
uint64_t GetIndex(const armAngles &a) const
Definition: RoboticArm.h:321
ArmToTipHeuristic::HCost
double HCost(const armAngles &node1, const armAngles &node2) const
Definition: RoboticArm.cpp:610
tRotation
tRotation
Definition: RoboticArm.h:63
ArmToTipHeuristic::minTipDistancesTables
std::vector< uint16_t * > minTipDistancesTables
Definition: RoboticArm.h:442
ArmToTipHeuristic::distancesTables
std::vector< uint16_t * > distancesTables
Definition: RoboticArm.h:441
ArmToTipHeuristic::legalStateTable
uint8_t * legalStateTable
Definition: RoboticArm.h:438
RoboticArm::BuildSinCosTables
void BuildSinCosTables()
Definition: RoboticArm.cpp:589
RoboticArm::GetTipPosition
void GetTipPosition(armAngles &s, double &x, double &y)
Definition: RoboticArm.cpp:108
ArmToArmHeuristic::distances
std::vector< std::vector< uint16_t > > distances
Definition: RoboticArm.h:183
RoboticArm::AddHeuristic
void AddHeuristic(RoboticArmHeuristic *h)
Definition: RoboticArm.h:110
RoboticArm::GetSin
double GetSin(int angle) const
Definition: RoboticArm.cpp:579
ArmToTipHeuristic::GenerateMaxDistHeuristics
int GenerateMaxDistHeuristics(const armAngles &sampleArm, const int numHeuristics)
Definition: RoboticArm.cpp:965
ArmToTipHeuristic::GenerateRandomHeuristic
void GenerateRandomHeuristic(const armAngles &sampleArm)
Definition: RoboticArm.cpp:913
ArmToTipHeuristic::GenerateCPDB
void GenerateCPDB()
Definition: RoboticArm.cpp:635
ArmToTipHeuristic::GenerateNextDepth
uint64_t GenerateNextDepth(FILE *curFile, FILE *nextFile, uint16_t curDistance, uint16_t *distances, uint16_t *minTipDistances, uint16_t *maxTipDistances, armAngles &lastAdded)
Definition: RoboticArm.cpp:752
ArmToTipHeuristic::ArmAnglesIndex
uint64_t ArmAnglesIndex(const armAngles &arm) const
Definition: RoboticArm.cpp:660
ArmToTipHeuristic::GenerateHeuristicSub
int GenerateHeuristicSub(const armAngles &sampleArm, const bool quiet, armAngles *goals, const int numGoals, uint16_t *distances, uint16_t *minTipDistances, uint16_t *maxTipDistances, armAngles &lastAdded)
Definition: RoboticArm.cpp:794
ArmToTipHeuristic::GenerateHeuristic
int GenerateHeuristic(const armAngles &sampleArm, armAngles &goal)
Definition: RoboticArm.cpp:937
width
int width
Definition: SFML_HOG.cpp:54
RoboticArm::AddObstacle
void AddObstacle(line2d obs)
Definition: RoboticArm.cpp:247
FrontierBFS
Definition: FrontierBFS.h:21
RoboticArm::GetStateHash
uint64_t GetStateHash(const armAngles &node) const
Definition: RoboticArm.cpp:379
ArmToTipHeuristic::tablesNumArms
std::vector< uint16_t > tablesNumArms
Definition: RoboticArm.h:444
RoboticArmHeuristic::HCost
virtual double HCost(const armAngles &node1, const armAngles &node2) const =0
RoboticArm::ClearGoal
void ClearGoal()
Clears the goal from memory.
Definition: RoboticArm.h:138
ArmToArmHeuristic::optimizeLocations
bool optimizeLocations
Definition: RoboticArm.h:181
RoboticArm::InvertAction
virtual bool InvertAction(armRotations &a) const
Definition: RoboticArm.cpp:239
ArmToTipHeuristic::ra
RoboticArm * ra
Definition: RoboticArm.h:435
armAngles::GetAngle
int GetAngle(int which) const
Definition: RoboticArm.cpp:38
ArmToArmHeuristic::TipPositionIndex
int TipPositionIndex(const double x, const double y, const double minX=-1.0, const double minY=-1.0, const double width=2.0)
Definition: RoboticArm.cpp:1262
ArmToArmHeuristic::tipPositionTables
std::vector< std::vector< armAngles > > tipPositionTables
Definition: RoboticArm.h:185
RoboticArm::GetActionHash
uint64_t GetActionHash(armRotations act) const
Definition: RoboticArm.cpp:399
RoboticArm::DOF
int DOF
Definition: RoboticArm.h:148
armRotations::rotations
uint16_t rotations
Definition: RoboticArm.h:73
armRotations::GetRotation
tRotation GetRotation(int which) const
Definition: RoboticArm.cpp:15
ArmToTipHeuristic::TipPositionIndex
int TipPositionIndex(const double x, const double y, const double minX, const double minY, const double width) const
Definition: RoboticArm.cpp:674
RoboticArm::HCost
virtual double HCost(const armAngles &) const
Heuristic value between node and the stored goal.
Definition: RoboticArm.h:112
armAngles::IsGoalState
bool IsGoalState() const
Definition: RoboticArm.cpp:90
armAngles::GetNumArms
int GetNumArms() const
Definition: RoboticArm.cpp:52
ArmToArmCompressedHeuristic::Load
void Load(const char *file)
Definition: RoboticArm.h:388
loc
Definition: MapGenerators.cpp:296
armAngles::armAngles
armAngles()
Definition: RoboticArm.h:31
RoboticArm::LegalArmConfig
bool LegalArmConfig(armAngles &a) const
Definition: RoboticArm.cpp:525
ArmToArmHeuristic::IsLegalState
bool IsLegalState(armAngles &arm)
Definition: RoboticArm.cpp:1361
RoboticArm::GenerateLineSegments
void GenerateLineSegments(const armAngles &a, std::vector< line2d > &armSegments) const
Definition: RoboticArm.cpp:542
ArmToTipHeuristic::m_TableComplete
bool m_TableComplete
Definition: RoboticArm.h:436
ArmToTipHeuristic::legalGoalTable
uint8_t * legalGoalTable
Definition: RoboticArm.h:439
ArmToArmHeuristic::HCost
double HCost(const armAngles &node1, const armAngles &node2) const
Definition: RoboticArm.cpp:1242
armAngles::SetNumArms
void SetNumArms(int count)
Definition: RoboticArm.cpp:57
RoboticArm::GetSuccessors
void GetSuccessors(const armAngles &nodeID, std::vector< armAngles > &neighbors) const
Definition: RoboticArm.cpp:133
line2d
‍**
Definition: GLUtil.h:155
ArmToArmHeuristic::legalStates
std::vector< bool > legalStates
Definition: RoboticArm.h:186
RoboticArm::armSegments
std::vector< line2d > armSegments
Definition: RoboticArm.h:158
ArmToArmCompressedHeuristic::theMask
uint64_t theMask
Definition: RoboticArm.h:410
RoboticArm
Definition: RoboticArm.h:88
RoboticArm::GCost
virtual double GCost(const armAngles &, const armRotations &) const
Definition: RoboticArm.h:119
ArmToTipHeuristic::maxTipDistancesTables
std::vector< uint16_t * > maxTipDistancesTables
Definition: RoboticArm.h:443
ArmToTipHeuristic::NumArmAnglesIndices
uint64_t NumArmAnglesIndices(const armAngles &arm) const
Definition: RoboticArm.h:451
ConfigEnvironment.h
kRotateCW
@ kRotateCW
Definition: RoboticArm.h:66
RoboticArm::StoreGoal
void StoreGoal(armAngles &)
Stores the goal for use by single-state HCost.
Definition: RoboticArm.h:137
ArmToArmHeuristic::canonicalStates
std::vector< armAngles > canonicalStates
Definition: RoboticArm.h:184
armRotations::SetRotation
void SetRotation(int which, tRotation dir)
Definition: RoboticArm.cpp:26
ArmToArmHeuristic::GetTipPositions
const std::vector< armAngles > & GetTipPositions(double x, double y)
Definition: RoboticArm.h:173
armRotations::armRotations
armRotations()
Definition: RoboticArm.h:71
ArmToTipHeuristic::UseHeuristic
uint16_t UseHeuristic(const armAngles &s, armAngles &g, uint16_t *distances) const
Definition: RoboticArm.cpp:1022
RoboticArm::GetCos
double GetCos(int angle) const
Definition: RoboticArm.cpp:584
max
#define max(a, b)
Definition: MinimalSectorAbstraction.cpp:40
ArmToArmCompressedHeuristic::SetupGoal
void SetupGoal(const armAngles &referenceState) const
Definition: RoboticArm.h:351
RoboticArm::obstacles
std::vector< line2d > obstacles
Definition: RoboticArm.h:157
RoboticArm::GetActions
void GetActions(const armAngles &nodeID, std::vector< armRotations > &actions) const
Definition: RoboticArm.cpp:177
RoboticArm::ce
ConfigEnvironment * ce
Definition: RoboticArm.h:163
ArmToArmHeuristic::AddDiffTable
void AddDiffTable()
Definition: RoboticArm.cpp:1277
RoboticArm::PopObstacle
void PopObstacle()
Definition: RoboticArm.cpp:255
ArmToArmCompressedHeuristic::theResult
uint64_t theResult
Definition: RoboticArm.h:411
ArmToArmCompressedHeuristic::errors
std::vector< int > errors
Definition: RoboticArm.h:406
ArmToArmHeuristic::SelectStartNode
armAngles SelectStartNode()
Definition: RoboticArm.cpp:1318
ArmToArmCompressedHeuristic::BuildHeuristic
armAngles BuildHeuristic(armAngles &config)
Definition: RoboticArm.h:243
FrontierBFS::InitializeSearch
void InitializeSearch(SearchEnvironment< state, action > *env, state &from)
Definition: FrontierBFS.h:63
RoboticArm::heuristics
std::vector< RoboticArmHeuristic * > heuristics
Definition: RoboticArm.h:162
RoboticArm::~RoboticArm
virtual ~RoboticArm()
Definition: RoboticArm.cpp:103
ReservationProvider.h
ArmToTipHeuristic::UpdateTipDistances
void UpdateTipDistances(armAngles &arm, uint16_t distance, uint16_t *minTipDistances, uint16_t *maxTipDistances)
Definition: RoboticArm.cpp:729
operator==
static bool operator==(const armAngles &l1, const armAngles &l2)
Definition: RoboticArm.h:59
ArmToArmCompressedHeuristic::Save
void Save(const char *file)
Definition: RoboticArm.h:379
ArmToTipHeuristic::tipPositionTables
std::vector< armAngles > * tipPositionTables
Definition: RoboticArm.h:446
ArmToArmCompressedHeuristic::HCost
double HCost(const armAngles &from, const armAngles &to) const
Definition: RoboticArm.h:335
ArmToTipHeuristic::ArmToTipHeuristic
ArmToTipHeuristic(RoboticArm *r)
Definition: RoboticArm.cpp:600
RoboticArm::GetNextState
virtual void GetNextState(const armAngles &currents, armRotations dir, armAngles &news) const
Definition: RoboticArm.cpp:489
ArmToTipHeuristic::ValidGoalPosition
bool ValidGoalPosition(double goalX, double goalY)
Definition: RoboticArm.cpp:1076
RoboticArmHeuristic
Definition: RoboticArm.h:82
armAngles
Definition: RoboticArm.h:29
ArmToArmCompressedHeuristic::r
RoboticArm * r
Definition: RoboticArm.h:408
ArmToArmCompressedHeuristic::AddState
void AddState(armAngles &a, int dist)
Definition: RoboticArm.h:311
ArmToArmHeuristic::~ArmToArmHeuristic
virtual ~ArmToArmHeuristic()
Definition: RoboticArm.h:169
ArmToArmCompressedHeuristic
Definition: RoboticArm.h:189
RoboticArm::cosTable
std::vector< double > cosTable
Definition: RoboticArm.h:156
RoboticArm::DrawLine
void DrawLine(line2d l) const
Definition: RoboticArm.cpp:479
RoboticArm::tolerance
double tolerance
Definition: RoboticArm.h:149
armAngles::SetGoal
void SetGoal(double x, double y)
Definition: RoboticArm.cpp:66
ArmToArmCompressedHeuristic::ArmToArmCompressedHeuristic
ArmToArmCompressedHeuristic(RoboticArm *ra, int numArms, int reductionPower, int offset=0)
Definition: RoboticArm.h:218
ArmToTipHeuristic::~ArmToTipHeuristic
virtual ~ArmToTipHeuristic()
Definition: RoboticArm.h:417
Map.h
ArmToArmCompressedHeuristic::~ArmToArmCompressedHeuristic
~ArmToArmCompressedHeuristic()
Definition: RoboticArm.h:238
ArmToTipHeuristic::ReadArmAngles
int ReadArmAngles(FILE *file, armAngles &a)
Definition: RoboticArm.cpp:708
FrontierBFS::DoOneIteration
bool DoOneIteration(SearchEnvironment< state, action > *env)
Definition: FrontierBFS.h:94
RoboticArm::IsGoalStored
bool IsGoalStored() const
Definition: RoboticArm.h:139
RoboticArm::armLength
double armLength
Definition: RoboticArm.h:149
ArmToArmHeuristic::GenerateLegalStates
void GenerateLegalStates(armAngles &init)
Definition: RoboticArm.cpp:1366
ArmToArmHeuristic::ra
RoboticArm * ra
Definition: RoboticArm.h:182
RoboticArm::GCost
virtual double GCost(const armAngles &, const armAngles &) const
Definition: RoboticArm.h:118
ArmToTipHeuristic::GenerateTipPositionTables
void GenerateTipPositionTables(armAngles &sampleArm)
Definition: RoboticArm.cpp:1187
RoboticArm::LegalState
bool LegalState(armAngles &a) const
Definition: RoboticArm.cpp:495
FrontierBFS.h
ArmToArmCompressedHeuristic::goal
armAngles goal
Definition: RoboticArm.h:407
SearchEnvironment
Definition: SearchEnvironment.h:30
RoboticArm::GetRandomState
armAngles GetRandomState()
Definition: RoboticArm.cpp:264
RoboticArm::RoboticArm
RoboticArm(int DOF, double armLength, double tolerance=0.01)
Definition: RoboticArm.cpp:96
ArmToArmHeuristic
Definition: RoboticArm.h:166
ArmToArmCompressedHeuristic::BuildHeuristic
armAngles BuildHeuristic(std::vector< armAngles > &config)
Definition: RoboticArm.h:269
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
ArmToTipHeuristic::WriteArmAngles
int WriteArmAngles(FILE *file, armAngles &a)
Definition: RoboticArm.cpp:690
kNoRotation
@ kNoRotation
Definition: RoboticArm.h:65
SearchEnvironment.h
kRotateCCW
@ kRotateCCW
Definition: RoboticArm.h:64
ArmToTipHeuristic::GenerateLegalStateTable
void GenerateLegalStateTable(armAngles &legalArm)
Definition: RoboticArm.cpp:1115
RoboticArm::GoalTest
virtual bool GoalTest(const armAngles &) const
Goal Test if the goal is stored.
Definition: RoboticArm.h:140
ArmToArmHeuristic::ArmToArmHeuristic
ArmToArmHeuristic(RoboticArm *r, armAngles &initial, bool optimize=false)
Definition: RoboticArm.cpp:1235
RoboticArm::TipPositionIndex
int TipPositionIndex(armAngles &s, const double minX=-1, const double minY=-1, const double width=2)
Definition: RoboticArm.cpp:117
RoboticArm::states
std::vector< recVec > states
Definition: RoboticArm.h:160
armAngles::GetGoal
void GetGoal(double &x, double &y) const
Definition: RoboticArm.cpp:79