Project

General

Profile

« Previous | Next » 

Revision 9abfdef3

Added by Leszek Koltunski about 2 years ago

Bandaged 3x3: more speedups with creating the ScrambleState graph. '4 pillars' now takes 10 seconds (before all speedups it used to take 50 minutes)

View differences:

src/main/java/org/distorted/objectlib/scrambling/ScrambleStateBandaged3x3.java
109 109
    String y = getTable( 9);
110 110
    String z = getTable(18);
111 111

  
112
    return "    new ScrambleState( new int[][] { "+x+", "+y+", "+z+" } ),";
112
    return x+"  "+y+"  "+z;
113 113
    }
114 114

  
115 115
///////////////////////////////////////////////////////////////////////////////////////////////////
......
206 206
android.util.Log.e("D", "inserting children: "+(t2-t1));
207 207

  
208 208
    // if there's only one single state, do not prune moves which point to itself
209
    boolean pruneMoves = (graph.size()>1);
210
    pruneGraph(graph,id,pruneMoves);
209
    if(graph.size()>1)
210
      {
211
      pruneGraph(graph,id);
212
      }
211 213

  
212 214
long t3 = System.currentTimeMillis();
213 215
android.util.Log.e("D", "pruning graph: "+(t3-t2));
......
282 284

  
283 285
///////////////////////////////////////////////////////////////////////////////////////////////////
284 286

  
285
  private static void pruneGraph(Map<Long,ScrambleStateBandaged3x3> map, long startingID, boolean pruneMoves)
287
  private static void pruneGraph(Map<Long,ScrambleStateBandaged3x3> map, long startingID)
286 288
    {
287 289
    boolean pruned = false;
290
    boolean startingIsSingle = false;
288 291

  
289 292
    Iterator<Map.Entry<Long,ScrambleStateBandaged3x3>> it = map.entrySet().iterator();
290 293

  
......
296 299
      if( value.numAxis()<2 )
297 300
        {
298 301
        long prunedID = value.getID();
299
        if( pruneMoves ) markInvalid(map,prunedID);
300 302

  
301 303
        if( prunedID!=startingID ) // do not remove the starting point, even if it does have only 1 axis
302 304
          {
303 305
          it.remove();
304 306
          pruned = true;
305 307
          }
308
        else
309
          {
310
          startingIsSingle = true;
311
          }
306 312
        }
307 313
      }
308 314

  
309
    if( pruned ) pruneGraph(map,startingID,true);
310
    }
311

  
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313

  
314
  private static void markInvalid(Map<Long,ScrambleStateBandaged3x3> map, long id)
315
    {
316 315
    for (Map.Entry<Long,ScrambleStateBandaged3x3> entry : map.entrySet() )
317 316
      {
318 317
      ScrambleStateBandaged3x3 value = entry.getValue();
319 318

  
320
      for(int j=0; j<NUM_MOVES; j++)
319
      for(int m=0; m<NUM_MOVES; m++)
321 320
        {
322
        if( value.mMoves[j]==id ) value.mMoves[j]=INVALID_MOVE;
321
        long move = value.mMoves[m];
322
        ScrambleStateBandaged3x3 tmp = findState(map,move);
323

  
324
        if( tmp==null || (startingIsSingle && move==startingID) )
325
          {
326
          value.mMoves[m]=INVALID_MOVE;
327
          }
323 328
        }
324 329
      }
330

  
331
    if( pruned ) pruneGraph(map,startingID);
325 332
    }
326 333

  
327 334
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff