40 return (
angles>>(10*which))&0x3FF;
45 value %= 1024;
if ( value < 0 ) { value += 1024; }
47 uint64_t mask = 1023ll<<(10*which);
48 uint64_t val = ((uint64_t)value)<<(10*which);
59 uint64_t mask = 0xFFFFFFFFFFFFFFFull;
60 uint64_t newCnt = count;
61 newCnt = newCnt << 60;
68 uint64_t fixedDecx, fixedFracx;
69 uint64_t fixedDecy, fixedFracy;
72 fixedDecx = ((uint32_t)x)&0x3FF;
73 fixedFracx = (int)((x-(
double)fixedDecx)*1024.0*1024.0);
74 fixedDecy = ((uint32_t)y)&0x3FF;
75 fixedFracy = (int)((y-(
double)fixedDecy)*1024.0*1024.0);
76 angles = (0xFll<<60)|(fixedDecx<<50)|(fixedFracx<<30)|(fixedDecy<<20)|fixedFracy;
83 x = ((
angles>>50)&0x3FF) + (double)((
angles>>30)&0xFFFFF)/(1024.0*1024.0);
84 y = ((
angles>>20)&0x3FF) + (double)((
angles)&0xFFFFF)/(1024.0*1024.0);
92 return ((
angles>>60) == 0xF);
97 :DOF(dof), armLength(armlength), tolerance(fTolerance)
110 std::vector<line2d> armSegs;
112 recVec a = armSegs.back().end;
118 const double minX,
const double minY,
154 for (
int x = 1; x < maxVal; x++)
173 neighbors.push_back(s);
188 actions.push_back(a);
195 actions.push_back(a);
232 for (
int x = 0; x < newState.
GetNumArms(); x++) {
241 for (
int x = 0; x < 6; x++)
268 for (
int x = 0; x <
DOF; x++)
285 for (
unsigned int x = 0; x <
heuristics.size(); x++)
293 std::vector<line2d> armSegments1;
295 recVec a = armSegments1.back().end;
298 double actDistance = sqrt((x-a.
x)*(x-a.
x)+(y-a.
y)*(y-a.
y));
309 h = actDistance / movementAmount;
328 return sqrt((a.
x-b.
x)*(a.
x-b.
x) + (a.
y-b.
y)*(a.
y-b.
y));
349 return sqrt((a.
x-b.
x)*(a.
x-b.
x) + (a.
y-b.
y)*(a.
y-b.
y));
358 return GCost(node1, node2);
366 return (
node == goal);
384 for (
int x = 0; x <
node.GetNumArms(); x++)
385 res = (uint64_t)(res<<9)|((uint64_t)
node.GetAngle(x)/2);
412 glColor3f(0, 0, 0.1);
413 glVertex3f(-1, -1, 0.1);
414 glVertex3f(1, -1, 0.1);
415 glVertex3f(1, 1, 0.1);
416 glVertex3f(-1, 1, 0.1);
420 for (
unsigned int x = 0; x <
obstacles.size(); x++)
448 for (
unsigned int x = 0; x <
armSegments.size(); x++)
457 glBegin(GL_LINE_LOOP);
458 glColor3f(0, 1.0, 0);
508 for (
unsigned int x = 0; x <
armSegments.size(); x++)
510 for (
unsigned int y = 0; y <
obstacles.size(); y++)
515 for (
unsigned int y = x+2; y <
armSegments.size(); y++)
519 if ((x > 0) && (a.
GetAngle(x) == 0))
530 for (
unsigned int x = 0; x <
armSegments.size(); x++)
532 for (
unsigned int y = x+2; y <
armSegments.size(); y++)
536 if ((x > 0) && (a.
GetAngle(x) == 0))
544 armSegments1.resize(0);
562 start = armSegments1.back().end;
563 prev = armSegments1.back().start;
574 armSegments1.push_back(
line2d(start, end));
576 assert(armSegments1.size() > 0);
593 for (
int x = 0; x < 1024; x++)
625 if ((
double)tableH > h )
643 std::vector<std::vector<bool> > legals;
645 for (
unsigned int x = 0; x < legals.size(); x++)
647 legals[x].resize(512);
648 printf(
"Building table for %d\n", x);
649 for (
unsigned int y = 0; y < legals[x].size(); y++)
675 const double minX,
const double minY,
676 const double width )
const
696 if ( fwrite( &v,
sizeof( v ), 1, file ) < 1 ) {
701 if ( fwrite( &v,
sizeof( v ), 1, file ) < 1 ) {
714 if ( fread( &v,
sizeof( v ), 1, file ) < 1 ) {
719 if ( fread( &v,
sizeof( v ), 1, file ) < 1 ) {
730 uint16_t *minTipDistances,
731 uint16_t *maxTipDistances )
738 if ( distance < minTipDistances[ idx ] ) {
739 minTipDistances[ idx ] = distance;
741 if ( distance > maxTipDistances[ idx ] ) {
742 maxTipDistances[ idx ] = distance;
753 uint16_t curDistance,
755 uint16_t *minTipDistances,
756 uint16_t *maxTipDistances,
759 uint64_t count = 0, idx;
762 std::vector<armRotations> actions;
766 for ( i = 0; i < actions.size(); ++i ) {
771 if ( distances[ idx ]
772 > curDistance + 1 ) {
775 distances[ idx ] = curDistance + 1;
777 if ( minTipDistances ) {
798 uint16_t *minTipDistances,
799 uint16_t *maxTipDistances,
802 uint64_t count, i, total;
803 int numArms = sampleArm.
GetNumArms(), segment, g;
806 FILE *curFile, *nextFile;
811 for ( i = 0; i < count; ++i ) {
812 distances[ i ] = 65535;
815 if ( minTipDistances ) {
817 for ( i = 0; i < count; ++i ) {
818 minTipDistances[ i ] = 65535;
819 maxTipDistances[ i ] = 0;
823 nextFile = tmpfile();
824 assert( nextFile != NULL );
830 printf(
"populating depth 0\n" );
832 for ( segment = 0; segment < numArms; ++segment ) {
839 for ( g = 0; g < numGoals; ++g ) {
859 if ( arm.
GetAngle( segment ) != 0 ) {
862 }
while( ++segment < numArms );
863 if ( segment == numArms ) {
869 printf(
"%" PRId64
" legal states\n", total );
881 printf(
"%" PRId64
" states at distance %u\n",
886 nextFile = tmpfile();
889 distances, minTipDistances,
890 maxTipDistances, lastAdded );
898 printf(
"%" PRId64
" total states\n", total );
915 uint16_t *distances, *minTipDistances, *maxTipDistances;
923 goal.
SetGoal( (
double)random()/(
double)RAND_MAX * 2.0 - 1.0,
924 (
double)random()/(
double)RAND_MAX * 2.0 - 1.0 );
926 minTipDistances, maxTipDistances,
940 uint16_t *distances, *minTipDistances, *maxTipDistances;
948 minTipDistances, maxTipDistances, last ) ) {
949 delete[] maxTipDistances;
950 delete[] minTipDistances;
966 const int numHeuristics )
969 uint16_t *distances, *minTipDistances, *maxTipDistances;
978 for ( i = 0; i < numHeuristics; ++i ) {
983 printf(
"generating next goal position\n" );
986 distances, minTipDistances,
987 maxTipDistances, goals[ i ] );
990 distances, minTipDistances,
991 maxTipDistances, goals[ i ] );
994 delete[] maxTipDistances;
995 delete[] minTipDistances;
1000 printf(
"new goal position: (%lf,%lf)\n", x, y );
1005 distances, minTipDistances,
1006 maxTipDistances, last ) ) {
1007 delete[] maxTipDistances;
1008 delete[] minTipDistances;
1023 uint16_t *distances )
const
1036 double goalX,
double goalY,
1037 uint16_t *distances,
1038 uint16_t *minTipDistances,
1039 uint16_t *maxTipDistances )
const
1041 int32_t mind, maxd, t;
1047 for ( y = goalY -
ra->
GetTolerance(), i = 0; i < 3; y += ra->GetTolerance(), ++i ) {
1048 for ( x = goalX -
ra->
GetTolerance(), j = 0; j < 3; x += ra->GetTolerance(), ++j ) {
1050 if ( minTipDistances[ index ] < mind ) {
1051 mind = minTipDistances[ index ];
1053 if ( maxTipDistances[ index ] > maxd ) {
1054 maxd = maxTipDistances[ index ];
1064 if ( mind > maxd ) {
1079 double x, y, tx, ty;
1086 for ( y = goalY -
ra->
GetTolerance(), i = 0; i < 3; y += ra->GetTolerance(), ++i ) {
1087 for ( x = goalX -
ra->
GetTolerance(), j = 0; j < 3; x += ra->GetTolerance(), ++j ) {
1091 }
else if ( tx >= 1.0 ) {
1097 }
else if ( ty >= 1.0 ) {
1102 if ( !(
legalGoalTable[ index >> 3 ] & ( 1 << ( index & 7 ) ) ) ) {
1117 uint64_t numStates, numTip, i;
1118 uint16_t *distances, *minTipDistances, *maxTipDistances, distance;
1121 FILE *curFile, *nextFile;
1123 printf(
"generating legal state table\n" );
1128 lst =
new uint8_t[ ( numStates + 7 ) >> 3 ];
1129 memset( lst, 0, ( numStates + 7 ) >> 3 );
1130 lgt =
new uint8_t[ ( numTip + 7 ) >> 3 ];
1131 memset( lgt, 0, ( numTip + 7 ) >> 3 );
1132 distances =
new uint16_t[ numStates ];
1133 for ( i = 0; i < numStates; ++i ) {
1134 distances[ i ] = 65535;
1136 minTipDistances =
new uint16_t[ numTip ];
1137 maxTipDistances =
new uint16_t[ numTip ];
1138 for ( i = 0; i < numTip; ++i ) {
1139 minTipDistances[ i ] = 65535;
1140 maxTipDistances[ i ] = 0;
1143 nextFile = tmpfile();
1144 assert( nextFile != NULL );
1154 nextFile = tmpfile();
1157 distances, minTipDistances,
1158 maxTipDistances, lastAdded );
1164 printf(
"done: maximum distance of %d from chosen state\n",
1167 for ( i = 0; i < numStates; ++i ) {
1168 if ( distances[ i ] < 65535 ) {
1169 lst[ i >> 3 ] |= 1 << ( i & 7 );
1173 for ( i = 0; i < numTip; ++i ) {
1174 if ( minTipDistances[ i ]
1175 <= maxTipDistances[ i ] ) {
1176 lgt[ i >> 3 ] |= 1 << ( i & 7 );
1182 delete[] maxTipDistances;
1183 delete[] minTipDistances;
1189 int numArms = sampleArm.
GetNumArms(), segment;
1193 printf(
"generating tip position table\n" );
1203 for (segment = 0; segment < numArms; ++segment)
1222 if ( arm.
GetAngle( segment ) != 0 ) {
1225 }
while( ++segment < numArms );
1226 if (segment == numArms )
1250 for (
unsigned int x = 0; x <
distances.size(); x++)
1257 hval =
max(nextval, hval);
1263 const double minX,
const double minY,
1264 const double width )
1282 printf(
"Building new heuristic table [%d]\n", which);
1286 std::deque<armAngles> q;
1289 while (q.size() > 0)
1298 std::vector<armAngles> moves;
1301 for (
unsigned int x = 0; x < moves.size(); x++)
1312 q.push_back(moves[x]);
1321 std::deque<armAngles> q;
1322 std::vector<bool> used;
1323 used.resize(512*512*512);
1343 while (q.size() > 0)
1348 std::vector<armAngles> moves;
1350 for (
unsigned int x = 0; x < moves.size(); x++)
1355 q.push_back(moves[x]);
1370 printf(
"Getting legal states and tip positions\n");
1372 std::deque<armAngles> q;
1375 while (q.size() > 0)
1377 if ((cnt++%10000) == 0)
1378 printf(
"(%d) Q size: %d\n", cnt, (
int)q.size());
1381 std::vector<armAngles> moves;
1383 for (
unsigned int x = 0; x < moves.size(); x++)
1388 q.push_back(moves[x]);