Revision 00947987
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/objectlib/tablebases/PruningTable.java | ||
---|---|---|
17 | 17 |
private final byte[] mData; |
18 | 18 |
private final int mNumBits; |
19 | 19 |
private final int mBucketBytes; |
20 |
private final int mTotalSize; |
|
21 | 20 |
private final int mNumBuckets; |
22 | 21 |
private final int mLevel; |
23 | 22 |
|
... | ... | |
58 | 57 |
|
59 | 58 |
private int getBucketOffset(int bucket) |
60 | 59 |
{ |
61 |
if( bucket>=mNumBuckets ) return mTotalSize;
|
|
60 |
if( bucket>=mNumBuckets ) return mData.length;
|
|
62 | 61 |
|
63 | 62 |
int ret = 0; |
64 | 63 |
int start = HEADER_SIZE + bucket*mBucketBytes; |
... | ... | |
178 | 177 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
179 | 178 |
// only numBits = 4,8,12,16 actually supported |
180 | 179 |
|
181 |
public PruningTable(Tablebase table, int level, int numBits)
|
|
180 |
PruningTable(Tablebase table, int level, int numBits) |
|
182 | 181 |
{ |
183 | 182 |
mNumBits = numBits; |
184 | 183 |
mLevel = level; |
... | ... | |
205 | 204 |
|
206 | 205 |
mBucketBytes = numBytesForIndices(totalBytesForTable); |
207 | 206 |
int totalBytesForBuckets = mNumBuckets*mBucketBytes; |
208 |
mTotalSize = HEADER_SIZE + totalBytesForBuckets + totalBytesForTable;
|
|
209 |
mData = new byte[mTotalSize];
|
|
207 |
int totalSize = HEADER_SIZE + totalBytesForBuckets + totalBytesForTable;
|
|
208 |
mData = new byte[totalSize];
|
|
210 | 209 |
|
211 | 210 |
writeHeader(); |
212 | 211 |
writeBucketPointers(bucket); |
... | ... | |
215 | 214 |
|
216 | 215 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
217 | 216 |
|
218 |
public boolean belongs(int number) |
|
217 |
PruningTable(byte[] data) |
|
218 |
{ |
|
219 |
mData = data; |
|
220 |
|
|
221 |
mLevel = ((int)mData[0])&0xff; |
|
222 |
mBucketBytes = ((int)mData[1])&0xff; |
|
223 |
mNumBits = ((int)mData[2])&0xff; |
|
224 |
mNumBuckets =(((int)mData[3])&0xff)*256 + ((int)mData[4])&0xff; |
|
225 |
} |
|
226 |
|
|
227 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
228 |
|
|
229 |
byte[] getPacked() |
|
230 |
{ |
|
231 |
return mData; |
|
232 |
} |
|
233 |
|
|
234 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
235 |
|
|
236 |
int getLevel() |
|
237 |
{ |
|
238 |
return mLevel; |
|
239 |
} |
|
240 |
|
|
241 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
242 |
|
|
243 |
boolean belongs(int number) |
|
219 | 244 |
{ |
220 | 245 |
int bucket = (number>>mNumBits); |
221 | 246 |
int offset1 = getBucketOffset(bucket); |
src/main/java/org/distorted/objectlib/tablebases/TablebasesCube2.java | ||
---|---|---|
14 | 14 |
import org.distorted.library.main.QuatHelper; |
15 | 15 |
import org.distorted.library.type.Static3D; |
16 | 16 |
import org.distorted.library.type.Static4D; |
17 |
import org.distorted.objectlib.R; |
|
17 | 18 |
|
18 | 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
19 | 20 |
|
... | ... | |
72 | 73 |
|
73 | 74 |
public TablebasesCube2(Resources res) |
74 | 75 |
{ |
75 |
super(res,org.distorted.objectlib.R.raw.cube_2_tablebase);
|
|
76 |
super(res, R.raw.cube_2_tablebase);
|
|
76 | 77 |
} |
77 | 78 |
|
78 | 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objectlib/tablebases/TablebasesMITM.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2023 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
9 |
|
|
10 |
package org.distorted.objectlib.tablebases; |
|
11 |
|
|
12 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
13 |
|
|
14 |
public abstract class TablebasesMITM extends TablebasesAbstract |
|
15 |
{ |
|
16 |
private PruningTable mTable; |
|
17 |
|
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
public TablebasesMITM() |
|
21 |
{ |
|
22 |
super(); |
|
23 |
} |
|
24 |
|
|
25 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
26 |
|
|
27 |
private String createAdjusted(int num) |
|
28 |
{ |
|
29 |
if( num<10 ) return " "+num; |
|
30 |
if( num<100 ) return " "+num; |
|
31 |
if( num<1000) return " "+num; |
|
32 |
|
|
33 |
return Integer.toString(num); |
|
34 |
} |
|
35 |
|
|
36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
37 |
|
|
38 |
private int numBytesForIndices(int total) |
|
39 |
{ |
|
40 |
int bytes = 0; |
|
41 |
|
|
42 |
while(total!=0) |
|
43 |
{ |
|
44 |
total>>=8; |
|
45 |
bytes++; |
|
46 |
} |
|
47 |
|
|
48 |
return bytes; |
|
49 |
} |
|
50 |
|
|
51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
52 |
|
|
53 |
public void probe(int level, int numBits) |
|
54 |
{ |
|
55 |
/* |
|
56 |
int numPos = 0; |
|
57 |
int numsInBucket = (1<<numBits); |
|
58 |
int numBuckets = (mSize+numsInBucket-1)/numsInBucket; |
|
59 |
int[] bucket = new int[numBuckets]; |
|
60 |
|
|
61 |
for(int i=0; i<mSize; i++) |
|
62 |
if( mTablebase.retrieveUnpacked(i)==level ) |
|
63 |
{ |
|
64 |
numPos++; |
|
65 |
int currBucket = i/numsInBucket; |
|
66 |
bucket[currBucket]++; |
|
67 |
} |
|
68 |
|
|
69 |
int totalBytesForTable = 0; |
|
70 |
int maxObjectsInBucket = 0; |
|
71 |
|
|
72 |
for(int i=0; i<numBuckets; i++) |
|
73 |
{ |
|
74 |
int numBytes = (bucket[i]*numBits+7)/8; |
|
75 |
totalBytesForTable+=numBytes; |
|
76 |
if( bucket[i]>maxObjectsInBucket ) maxObjectsInBucket = bucket[i]; |
|
77 |
} |
|
78 |
|
|
79 |
int totalBytesForBuckets = numBuckets*numBytesForIndices(totalBytesForTable); |
|
80 |
int constantModeBytes = (maxObjectsInBucket*numBits+7)/8; |
|
81 |
|
|
82 |
android.util.Log.e("D","bits: "+numBits+" header: 4 buckets: "+totalBytesForBuckets+" table: "+totalBytesForTable+ |
|
83 |
" total: "+(4+totalBytesForBuckets+totalBytesForTable)+ |
|
84 |
" max : "+maxObjectsInBucket+" total constant: "+(numBuckets*constantModeBytes+4)); |
|
85 |
*/ |
|
86 |
} |
|
87 |
|
|
88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
89 |
|
|
90 |
public void pack(int level, int numBits) |
|
91 |
{ |
|
92 |
//mTable = new PruningTable(mTablebase,level,numBits); |
|
93 |
} |
|
94 |
|
|
95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
96 |
|
|
97 |
public int[][] solution(int index, int[] extra) |
|
98 |
{ |
|
99 |
return null; |
|
100 |
} |
|
101 |
} |
Also available in: Unified diff
New PruningTable data structure for solvers.