Project

General

Profile

« Previous | Next » 

Revision aa0757b6

Added by Leszek Koltunski about 1 year ago

Progress with TablebasesPruning

View differences:

src/main/java/org/distorted/objectlib/tablebases/TBCube2.java
265 265
    int twistNum = twist[0] + 3*(twist[2] + 3*(twist[3] + 3*(twist[4] + 3*(twist[5] + 3*twist[6]))));
266 266
    int permNum  = TablebaseHelpers.computePermutationNum(perm7);
267 267

  
268
if( permNum<0 )
269
  {
270
  android.util.Log.e("D", " permNum="+permNum );
271

  
272
  StringBuilder sb2 = new StringBuilder();
273
  for(int i=0; i<8; i++) { sb2.append(' '); sb2.append(perm8[i]); }
274
  android.util.Log.e("D", " perm8="+sb2 );
275

  
276
  StringBuilder sb3 = new StringBuilder();
277
  for(int i=0; i<8; i++) { sb3.append(' '); sb3.append(quats[i]); }
278
  android.util.Log.e("D", " quats="+sb3 );
279
  }
280

  
281 268
    return twistNum + 729*permNum;
282 269
    }
283 270
}  
src/main/java/org/distorted/objectlib/tablebases/TablebasesPruning.java
221 221
  private int traversePruningBlock(int[][] moves, PruningTable[] tables, int tableIndex, int index, int lastA, int lastR)
222 222
    {
223 223
    int movesIndex = 1;
224
    int[] move = moves[movesIndex];
225
    int[] tmpQuats = new int[4];
224
    int[] move, tmpQuats = new int[mNumCubits];
226 225

  
227 226
    do
228 227
      {
228
      move  = moves[movesIndex++];
229 229
      index = traverseDownTable(index,tables,tableIndex,lastA,lastR,move,tmpQuats);
230 230
      lastA = move[0];
231 231
      lastR = move[1];
232 232
      tableIndex--;
233
      movesIndex++;
234
      move = moves[movesIndex];
235 233
      }
236 234
    while( tableIndex>=0 );
237 235

  
......
253 251
        break;
254 252
        }
255 253

  
256
    if( tableIndex<0 ) return null;
254
    if( tableIndex<0 )
255
      {
256
      android.util.Log.e("D", "block doesn't contain index "+index);
257
      return null;
258
      }
257 259

  
258 260
    int[][] ret = new int[tableIndex+2][4];
259 261
    ret[0][1] = tables[0].getLevel()-1;
......
279 281

  
280 282
  private boolean jumpMidZeroRecursive(int index, int jump, int depth, int lastA, int lastR, int[][] solution)
281 283
    {
282
    int[] quats  = getQuats(index);
283
    int numQuats = quats.length;
284
    int[] move   = solution[depth];
285
    int[] tmp    = new int[mNumCubits];
284
    int[] quats   = getQuats(index);
285
    int numQuats  = quats.length;
286
    int[] move    = solution[depth];
287
    int[] tmp     = new int[mNumCubits];
288
    int[][] rotRow= new int[mNumCubits][mNumAxis];
286 289

  
287 290
    move[0]=0;
288 291
    move[1]=0;
......
291 294

  
292 295
    for(int ax=0; ax<mNumAxis; ax++)
293 296
      for(int cubit=0; cubit<mNumCubits; cubit++)
294
        mRotRow[cubit][ax] = computeRow(mPosition[cubit],quats[cubit],ax);
297
        rotRow[cubit][ax] = computeRow(mPosition[cubit],quats[cubit],ax);
295 298

  
296 299
    for(int s=0; s<mScalingFactor; s++)
297 300
      {
......
305 308
        System.arraycopy(quats, 0, tmp, 0, numQuats);
306 309

  
307 310
        for(int cubit=0; cubit<mNumCubits; cubit++)
308
          if( mRotRow[cubit][ax]==bitLayer )
311
          if( rotRow[cubit][ax]==bitLayer )
309 312
            {
310 313
            int currQuat = tmp[cubit];
311 314
            int newQuat = getMultQuat(quat,currQuat);
......
316 319

  
317 320
        if( childIndex==0 )
318 321
          {
322
          android.util.Log.e("D", "1 jumped to mid: index="+childIndex);
323

  
319 324
          solution[0][0] = childIndex;
320 325
          solution[0][1] = 0;
321 326
          return true;
......
325 330

  
326 331
        if( containingTable>=0 )
327 332
          {
333
          android.util.Log.e("D", "2 jumped to mid: index="+childIndex);
334

  
328 335
          solution[0][0] = childIndex;
329 336
          solution[0][1] = mMidTables[containingTable].getLevel();
330 337
          return true;
......
343 350
    }
344 351

  
345 352
///////////////////////////////////////////////////////////////////////////////////////////////////
346
// ret: [0][] --> (?,old depth,?,?) ; [1...N-1][] --> moves.
353
// ret: [0][] --> (num moves,old depth,?,?) ; [1...N-1][] --> moves.
347 354

  
348 355
  private int[][] jumpToMidOrZero(int index, int maxJump, int lastA, int lastR)
349 356
    {
357
    if( midTablesContain(index)>=0 ) return null;
358

  
350 359
    int[][] solution = new int[maxJump+1][4];
351 360

  
352 361
    for(int i=1; i<maxJump; i++)
353 362
      if( jumpMidZeroRecursive(index,i,1,lastA,lastR,solution) )
363
        {
364
        solution[0][0] = i;
354 365
        return solution;
366
        }
355 367

  
356 368
    return null;
357 369
    }
......
364 376
    int numQuats = quats.length;
365 377
    int[] move   = solution[depth];
366 378
    int[] tmp    = new int[mNumCubits];
367

  
368
    android.util.Log.e("D", "trying 0rec: index="+index);
379
    int[][]rotRow= new int[mNumCubits][mNumAxis];
369 380

  
370 381
    move[0]=0;
371 382
    move[1]=0;
......
374 385

  
375 386
    for(int ax=0; ax<mNumAxis; ax++)
376 387
      for(int cubit=0; cubit<mNumCubits; cubit++)
377
        mRotRow[cubit][ax] = computeRow(mPosition[cubit],quats[cubit],ax);
388
        rotRow[cubit][ax] = computeRow(mPosition[cubit],quats[cubit],ax);
389
/*
390
if( index==1719861 )
391
  {
392
StringBuilder sb4 = new StringBuilder();
393
  for(int a=0; a<mNumAxis; a++)
394
    {
395
      for(int c=0; c<mNumCubits; c++)
396
        {
397
        sb4.append(mRotRow[c][a]);
398
        sb4.append(' ');
399
        }
400
    sb4.append("\n");
378 401

  
402
    }
403
  android.util.Log.e("D", "1 rotRows= \n"+sb4 );
404
  }
405
*/
379 406
    for(int s=0; s<mScalingFactor; s++)
380 407
      {
381 408
      int ax    = move[0];
......
388 415
        System.arraycopy(quats, 0, tmp, 0, numQuats);
389 416

  
390 417
        for(int cubit=0; cubit<mNumCubits; cubit++)
391
          if( mRotRow[cubit][ax]==bitLayer )
418
          if( rotRow[cubit][ax]==bitLayer )
392 419
            {
393 420
            int currQuat = tmp[cubit];
394 421
            int newQuat = getMultQuat(quat,currQuat);
395 422
            tmp[cubit] = newQuat;
396 423
            }
424
/*
425
if( depth==1 && ax==1 && layer==1 && move[2]==3 )
426
  {
427
  StringBuilder sb2 = new StringBuilder();
428
  for(int i=0; i<8; i++) { sb2.append(' '); sb2.append(quats[i]); }
429
  android.util.Log.e("D", " quats= "+sb2 );
430

  
431
  StringBuilder sb3 = new StringBuilder();
432
  for(int i=0; i<8; i++) { sb3.append(' '); sb3.append(tmp[i]); }
433
  android.util.Log.e("D", " tmpQuats= "+sb3 );
434

  
435

  
436

  
437
  android.util.Log.e("D", " index= "+index );
438
  }
439

  
440

  
441
if( index==1719861 )
442
  {
443
StringBuilder sb4 = new StringBuilder();
444
  for(int a=0; a<mNumAxis; a++)
445
    {
446
      for(int c=0; c<mNumCubits; c++)
447
        {
448
        sb4.append(mRotRow[c][a]);
449
        sb4.append(' ');
450
        }
451
    sb4.append("\n");
452

  
453
    }
454
  android.util.Log.e("D", "2 rotRows= \n"+sb4 );
455
  }
456
*/
397 457

  
398 458
        int childIndex = getIndex(tmp);
399
        if( childIndex==0 )
400
          {
401
          android.util.Log.e("D", "END: ax="+ax+" layer="+layer+" angle: "+move[2]);
402
          return true;
403
          }
404
        if( jump>1 && jumpZeroRecursive(childIndex, jump-1, depth+1, ax, layer, solution) )
405
          {
406
          android.util.Log.e("D", "REC: ax="+ax+" layer="+layer+" angle: "+move[2]);
407
          return true;
408
          }
459
        if( childIndex==0 ) return true;
460
        if( jump>1 && jumpZeroRecursive(childIndex, jump-1, depth+1, ax, layer, solution) ) return true;
409 461
        }
410 462

  
411 463
      getNextAxisLayerAngleQuat(move);
......
415 467
    }
416 468

  
417 469
///////////////////////////////////////////////////////////////////////////////////////////////////
418
// ret: [0][] --> (?,old depth,?,?) ; [1...N-1][] --> moves.
470
// ret: [0][] --> (numMoves,old depth,?,?) ; [1...N-1][] --> moves.
419 471

  
420 472
  private int[][] jumpToZero(int index, int maxJump, int lastA, int lastR)
421 473
    {
......
423 475

  
424 476
    for(int i=1; i<maxJump; i++)
425 477
      if( jumpZeroRecursive(index,i,1,lastA,lastR,solution) )
478
        {
479
        solution[0][0] = i;
426 480
        return solution;
481
        }
427 482

  
428 483
    return null;
429 484
    }
......
433 488
  private int[][] concatenateMoves(int[][] high, int[][] jump1, int[][] mid, int[][] jump2)
434 489
    {
435 490
    int len1 = high ==null ? 0 : high.length-1;
436
    int len2 = jump1==null ? 0 : jump1[0][1];
491
    int len2 = jump1==null ? 0 : jump1[0][0];
437 492
    int len3 = mid  ==null ? 0 : mid.length-1;
438
    int len4 = jump2==null ? 0 : jump2[0][1];
493
    int len4 = jump2==null ? 0 : jump2[0][0];
439 494

  
440 495
    int[][] moves = new int[len1+len2+len3+len4][];
441 496
    int index = 0;
......
498 553
      }
499 554
    else throw new RuntimeException("error traversing mid Tables");
500 555

  
556
android.util.Log.e("D", "");
557

  
501 558
    int[][] jump2Moves = jumpToZero(index,mLowestMid-1,lastA,lastR);
502 559
    if( jump2Moves==null ) throw new RuntimeException("2 error jumping to 0");
503 560
    return concatenateMoves(highMoves,jump1Moves,midMoves,jump2Moves);

Also available in: Unified diff