Go to the documentation of this file.
36 void SetGoal(
double x,
double y);
37 void GetGoal(
double &x,
double &y)
const;
44 if (
loc.IsGoalState())
48 out <<
"(" << x <<
", " << y <<
")" << std::endl;
52 for (
int x = 0; x <
loc.GetNumArms()-1; x++)
53 out <<
loc.GetAngle(x) <<
", ";
54 out <<
loc.GetAngle(
loc.GetNumArms()-1) <<
"]";
97 const double minX=-1,
const double minY=-1,
98 const double width=2 );
113 printf(
"Single State HCost Failure: method not implemented for RoboticArm\n");
114 exit(0);
return -1.0;}
141 printf(
"Single State Goal Test Failure: method not implemented for RoboticArm\n");
142 exit(0);
return false;}
152 double GetSin(
int angle)
const;
153 double GetCos(
int angle)
const;
178 const double minX = -1.0,
const double minY = -1.0,
179 const double width = 2.0);
202 uint64_t mask[6] = {0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F };
205 for (
int x =
reduction.size()-1; x >= 0 ; x--)
212 printf(
"Using mask 0x%llX\n",
theMask);
213 printf(
"Using result 0x%llX\n",
theResult);
214 printf(
"%" PRId64
" entries in table\n",
theSize);
224 uint64_t mask[5] = {0x3, 0x7, 0xF, 0x1F, 0x3F };
226 for (
int x = 0; x < numArms; x++)
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);
248 printf(
"Performing frontier BFS!\n");
250 std::cout <<
"Using " << config <<
" as basis for heuristic." << std::endl;
257 for (FrontierBFSClosedList::const_iterator it = closed.begin(); it != closed.end(); it++)
274 printf(
"Performing frontier BFS!\n");
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;
288 for (FrontierBFSClosedList::const_iterator it = closed.begin(); it != closed.end(); it++)
294 std::cout <<
"Using " << tmp <<
" as basis for heuristic." << std::endl;
301 for (FrontierBFSClosedList::const_iterator it = closed.begin(); it != closed.end(); it++)
341 double heuristic = 0;
344 for (
unsigned int x = 0; x <
values.size(); x++)
357 goal = referenceState;
363 for (FrontierBFSClosedList::const_iterator it = closed.begin(); it != closed.end(); it++)
368 std::cout <<
"Found state " << tmp <<
" distance " <<
distances[
GetIndex(tmp)] <<
" with error " << depth << std::endl;
381 FILE *f = fopen(file,
"w+");
382 if (f == 0) assert(!
"file could not be opened");
391 FILE *f = fopen(file,
"r");
392 if (f == 0) assert(!
"file could not be opened");
426 const int numHeuristics );
457 const double minX,
const double minY,
458 const double width )
const;
461 return count * count;
470 uint16_t *minTipDistances,
471 uint16_t *maxTipDistances );
478 uint16_t *minTipDistances,
479 uint16_t *maxTipDistances,
489 uint16_t curDistance, uint16_t *distances,
490 uint16_t *minTipDistances,
491 uint16_t *maxTipDistances,
496 uint16_t *distances )
const;
498 uint16_t *distances, uint16_t *minTipDistances,
499 uint16_t *maxTipDistances )
const;
std::vector< std::vector< bool > > legals
ArmToArmCompressedHeuristic(RoboticArm *ra, const char *file)
virtual ~RoboticArmHeuristic()
void SetAngle(int which, int value)
int NumTipPositionIndices() const
armRotations GetAction(const armAngles &s1, const armAngles &s2) const
double GetTolerance() const
void GetStateFromHash(uint64_t hash, armAngles &) const
ArmToArmCompressedHeuristic(RoboticArm *ra, std::vector< int > reductionPower, std::vector< int > offset)
virtual void OpenGLDraw() const
std::vector< double > sinTable
virtual void ApplyAction(armAngles &s, armRotations dir) const
std::vector< int > values
std::unordered_map< uint64_t, bool, Hash64 > FrontierBFSClosedList
const FrontierBFSClosedList & GetCurrentClosedList()
bool GoalTest(const armAngles &node, const armAngles &goal) const
virtual void OpenGLDraw(const armAngles &, const armAngles &, float) const
Draw the transition at some percentage 0...1 between two states.
std::vector< int > reduction
static std::ostream & operator<<(std::ostream &out, const armAngles &loc)
uint64_t GetIndex(const armAngles &a) const
double HCost(const armAngles &node1, const armAngles &node2) const
std::vector< uint16_t * > minTipDistancesTables
std::vector< uint16_t * > distancesTables
uint8_t * legalStateTable
void GetTipPosition(armAngles &s, double &x, double &y)
std::vector< std::vector< uint16_t > > distances
void AddHeuristic(RoboticArmHeuristic *h)
double GetSin(int angle) const
int GenerateMaxDistHeuristics(const armAngles &sampleArm, const int numHeuristics)
void GenerateRandomHeuristic(const armAngles &sampleArm)
uint64_t GenerateNextDepth(FILE *curFile, FILE *nextFile, uint16_t curDistance, uint16_t *distances, uint16_t *minTipDistances, uint16_t *maxTipDistances, armAngles &lastAdded)
uint64_t ArmAnglesIndex(const armAngles &arm) const
int GenerateHeuristicSub(const armAngles &sampleArm, const bool quiet, armAngles *goals, const int numGoals, uint16_t *distances, uint16_t *minTipDistances, uint16_t *maxTipDistances, armAngles &lastAdded)
int GenerateHeuristic(const armAngles &sampleArm, armAngles &goal)
void AddObstacle(line2d obs)
uint64_t GetStateHash(const armAngles &node) const
std::vector< uint16_t > tablesNumArms
virtual double HCost(const armAngles &node1, const armAngles &node2) const =0
void ClearGoal()
Clears the goal from memory.
virtual bool InvertAction(armRotations &a) const
int GetAngle(int which) const
int TipPositionIndex(const double x, const double y, const double minX=-1.0, const double minY=-1.0, const double width=2.0)
std::vector< std::vector< armAngles > > tipPositionTables
uint64_t GetActionHash(armRotations act) const
tRotation GetRotation(int which) const
int TipPositionIndex(const double x, const double y, const double minX, const double minY, const double width) const
virtual double HCost(const armAngles &) const
Heuristic value between node and the stored goal.
void Load(const char *file)
bool LegalArmConfig(armAngles &a) const
bool IsLegalState(armAngles &arm)
void GenerateLineSegments(const armAngles &a, std::vector< line2d > &armSegments) const
double HCost(const armAngles &node1, const armAngles &node2) const
void SetNumArms(int count)
void GetSuccessors(const armAngles &nodeID, std::vector< armAngles > &neighbors) const
std::vector< bool > legalStates
std::vector< line2d > armSegments
virtual double GCost(const armAngles &, const armRotations &) const
std::vector< uint16_t * > maxTipDistancesTables
uint64_t NumArmAnglesIndices(const armAngles &arm) const
void StoreGoal(armAngles &)
Stores the goal for use by single-state HCost.
std::vector< armAngles > canonicalStates
void SetRotation(int which, tRotation dir)
const std::vector< armAngles > & GetTipPositions(double x, double y)
uint16_t UseHeuristic(const armAngles &s, armAngles &g, uint16_t *distances) const
double GetCos(int angle) const
void SetupGoal(const armAngles &referenceState) const
std::vector< line2d > obstacles
void GetActions(const armAngles &nodeID, std::vector< armRotations > &actions) const
std::vector< int > errors
armAngles SelectStartNode()
armAngles BuildHeuristic(armAngles &config)
void InitializeSearch(SearchEnvironment< state, action > *env, state &from)
std::vector< RoboticArmHeuristic * > heuristics
void UpdateTipDistances(armAngles &arm, uint16_t distance, uint16_t *minTipDistances, uint16_t *maxTipDistances)
static bool operator==(const armAngles &l1, const armAngles &l2)
void Save(const char *file)
std::vector< armAngles > * tipPositionTables
double HCost(const armAngles &from, const armAngles &to) const
ArmToTipHeuristic(RoboticArm *r)
virtual void GetNextState(const armAngles ¤ts, armRotations dir, armAngles &news) const
bool ValidGoalPosition(double goalX, double goalY)
void AddState(armAngles &a, int dist)
virtual ~ArmToArmHeuristic()
std::vector< double > cosTable
void DrawLine(line2d l) const
void SetGoal(double x, double y)
ArmToArmCompressedHeuristic(RoboticArm *ra, int numArms, int reductionPower, int offset=0)
virtual ~ArmToTipHeuristic()
~ArmToArmCompressedHeuristic()
int ReadArmAngles(FILE *file, armAngles &a)
bool DoOneIteration(SearchEnvironment< state, action > *env)
bool IsGoalStored() const
void GenerateLegalStates(armAngles &init)
virtual double GCost(const armAngles &, const armAngles &) const
void GenerateTipPositionTables(armAngles &sampleArm)
bool LegalState(armAngles &a) const
armAngles GetRandomState()
RoboticArm(int DOF, double armLength, double tolerance=0.01)
armAngles BuildHeuristic(std::vector< armAngles > &config)
Nodes to be stored within a Graph.
int WriteArmAngles(FILE *file, armAngles &a)
void GenerateLegalStateTable(armAngles &legalArm)
virtual bool GoalTest(const armAngles &) const
Goal Test if the goal is stored.
ArmToArmHeuristic(RoboticArm *r, armAngles &initial, bool optimize=false)
int TipPositionIndex(armAngles &s, const double minX=-1, const double minY=-1, const double width=2)
std::vector< recVec > states
void GetGoal(double &x, double &y) const