Revision 884b702b
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/objectlib/tablebases/ImplementedTablebasesList.java | ||
---|---|---|
73 | 73 |
|
74 | 74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
75 | 75 |
|
76 |
public static TablebasesAbstract createPacked(Resources res, int signature)
|
|
76 |
private static TablebasesAbstract create(Resources res, int signature, boolean packed)
|
|
77 | 77 |
{ |
78 | 78 |
Class<? extends TablebasesAbstract> clazz=null; |
79 | 79 |
|
... | ... | |
92 | 92 |
|
93 | 93 |
if( cons.length==2 ) |
94 | 94 |
{ |
95 |
Object[] parameters = new Object[] { res }; |
|
96 |
return (TablebasesAbstract)cons[1].newInstance(parameters); |
|
95 |
if( packed ) |
|
96 |
{ |
|
97 |
Object[] parameters = new Object[] { res }; |
|
98 |
return (TablebasesAbstract)cons[1].newInstance(parameters); |
|
99 |
} |
|
100 |
else |
|
101 |
{ |
|
102 |
return (TablebasesAbstract)cons[0].newInstance(); |
|
103 |
} |
|
97 | 104 |
} |
98 | 105 |
else |
99 | 106 |
{ |
... | ... | |
118 | 125 |
|
119 | 126 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
120 | 127 |
|
121 |
public static TablebasesAbstract createUnpacked(int signatures)
|
|
128 |
public static TablebasesAbstract createPacked(Resources res, int signature)
|
|
122 | 129 |
{ |
123 |
Class<? extends TablebasesAbstract> clazz=null; |
|
124 |
|
|
125 |
for(int i=0; i<NUM_OBJECTS; i++) |
|
126 |
if( objects[i].mSignature == signatures ) |
|
127 |
{ |
|
128 |
clazz = objects[i].mClass; |
|
129 |
break; |
|
130 |
} |
|
131 |
|
|
132 |
if( clazz==null ) return null; |
|
133 |
|
|
134 |
try |
|
135 |
{ |
|
136 |
Constructor<?>[] cons = clazz.getConstructors(); |
|
130 |
return create(res,signature,true); |
|
131 |
} |
|
137 | 132 |
|
138 |
if( cons.length==2 ) |
|
139 |
{ |
|
140 |
return (TablebasesAbstract)cons[0].newInstance(); |
|
141 |
} |
|
142 |
else |
|
143 |
{ |
|
144 |
android.util.Log.e("TablebasesList", "ERROR! number of TablebasesAbstract constructors="+cons.length); |
|
145 |
} |
|
146 |
} |
|
147 |
catch(IllegalAccessException iae) |
|
148 |
{ |
|
149 |
android.util.Log.e("TablebasesList", "Illegal Access Exception: "+iae.getMessage()); |
|
150 |
} |
|
151 |
catch(InstantiationException ie) |
|
152 |
{ |
|
153 |
android.util.Log.e("TablebasesList", "Instantiation Exception: "+ie.getMessage()); |
|
154 |
} |
|
155 |
catch(InvocationTargetException ite) |
|
156 |
{ |
|
157 |
android.util.Log.e("TablebasesList", "Invocation Target Exception: "+ite.getMessage()); |
|
158 |
} |
|
133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
159 | 134 |
|
160 |
return null; |
|
135 |
public static TablebasesAbstract createUnpacked(int signature) |
|
136 |
{ |
|
137 |
return create(null,signature,false); |
|
161 | 138 |
} |
162 | 139 |
} |
src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java | ||
---|---|---|
60 | 60 |
abstract int getSize(); |
61 | 61 |
abstract int[] getQuats(int index); |
62 | 62 |
abstract int getIndex(int[] quats); |
63 |
abstract int[] getPruningLevels(); |
|
63 | 64 |
|
64 | 65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
65 | 66 |
|
src/main/java/org/distorted/objectlib/tablebases/TablebasesCube2.java | ||
---|---|---|
18 | 18 |
|
19 | 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
20 | 20 |
|
21 |
public class TablebasesCube2 extends TablebasesAbstract
|
|
21 |
public class TablebasesCube2 extends TablebasesMITM
|
|
22 | 22 |
{ |
23 | 23 |
private static final int[][] P = |
24 | 24 |
{ |
... | ... | |
73 | 73 |
|
74 | 74 |
public TablebasesCube2(Resources res) |
75 | 75 |
{ |
76 |
super(res, R.raw.cube_2_tablebase);
|
|
76 |
super(res, new int[] {} ); // TODO
|
|
77 | 77 |
} |
78 | 78 |
|
79 | 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
144 | 144 |
return 9; |
145 | 145 |
} |
146 | 146 |
|
147 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
148 |
|
|
149 |
int[] getPruningLevels() |
|
150 |
{ |
|
151 |
return new int[] {5,11}; |
|
152 |
} |
|
153 |
|
|
147 | 154 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
148 | 155 |
|
149 | 156 |
private int[] getPermTwist(float[] point) |
src/main/java/org/distorted/objectlib/tablebases/TablebasesCuboid232.java | ||
---|---|---|
112 | 112 |
|
113 | 113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
114 | 114 |
|
115 |
int getMinScramble() |
|
115 |
int getMinScramble()
|
|
116 | 116 |
{ |
117 | 117 |
return 12; |
118 | 118 |
} |
119 | 119 |
|
120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
121 |
|
|
122 |
int[] getPruningLevels() |
|
123 |
{ |
|
124 |
return null; |
|
125 |
} |
|
126 |
|
|
120 | 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
121 | 128 |
|
122 | 129 |
private void getCornerQuats(int[] output, int[] perm) |
src/main/java/org/distorted/objectlib/tablebases/TablebasesIvyCube.java | ||
---|---|---|
114 | 114 |
|
115 | 115 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
116 | 116 |
|
117 |
int getMinScramble() |
|
117 |
int getMinScramble()
|
|
118 | 118 |
{ |
119 | 119 |
return 7; |
120 | 120 |
} |
121 | 121 |
|
122 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
123 |
|
|
124 |
int[] getPruningLevels() |
|
125 |
{ |
|
126 |
return null; |
|
127 |
} |
|
128 |
|
|
122 | 129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
123 | 130 |
|
124 | 131 |
private int findFirst(int[] table, int value) |
src/main/java/org/distorted/objectlib/tablebases/TablebasesMITM.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package org.distorted.objectlib.tablebases; |
11 | 11 |
|
12 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
12 |
import android.content.res.Resources;
|
|
13 | 13 |
|
14 |
public abstract class TablebasesMITM extends TablebasesAbstract
|
|
15 |
{
|
|
16 |
private PruningTable mTable;
|
|
14 |
import java.io.ByteArrayOutputStream;
|
|
15 |
import java.io.IOException;
|
|
16 |
import java.io.InputStream;
|
|
17 | 17 |
|
18 | 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
19 | 19 |
|
20 |
public TablebasesMITM() |
|
21 |
{ |
|
22 |
super(); |
|
23 |
} |
|
20 |
public abstract class TablebasesMITM extends TablebasesAbstract |
|
21 |
{ |
|
22 |
private PruningTable[] mTables; |
|
23 |
private boolean mInitialized; |
|
24 |
private int[] mLevels; |
|
24 | 25 |
|
25 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
26 | 27 |
|
27 |
private String createAdjusted(int num)
|
|
28 |
private void createPruningTable(Resources res, int id, int index)
|
|
28 | 29 |
{ |
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 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
30 |
InputStream stream = res.openRawResource(id); |
|
31 |
ByteArrayOutputStream buffer = new ByteArrayOutputStream(); |
|
37 | 32 |
|
38 |
private int numBytesForIndices(int total) |
|
39 |
{ |
|
40 |
int bytes = 0; |
|
33 |
int nRead; |
|
34 |
byte[] tmp = new byte[16384]; |
|
41 | 35 |
|
42 |
while(total!=0)
|
|
36 |
try
|
|
43 | 37 |
{ |
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 ) |
|
38 |
while ((nRead = stream.read(tmp, 0, tmp.length)) != -1) |
|
63 | 39 |
{ |
64 |
numPos++; |
|
65 |
int currBucket = i/numsInBucket; |
|
66 |
bucket[currBucket]++; |
|
40 |
buffer.write(tmp, 0, nRead); |
|
67 | 41 |
} |
68 |
|
|
69 |
int totalBytesForTable = 0; |
|
70 |
int maxObjectsInBucket = 0; |
|
71 |
|
|
72 |
for(int i=0; i<numBuckets; i++) |
|
42 |
stream.close(); |
|
43 |
byte[] data = buffer.toByteArray(); |
|
44 |
buffer.close(); |
|
45 |
mTables[index] = new PruningTable(data); |
|
46 |
mLevels[index] = mTables[index].getLevel(); |
|
47 |
} |
|
48 |
catch(IOException ex) |
|
73 | 49 |
{ |
74 |
int numBytes = (bucket[i]*numBits+7)/8; |
|
75 |
totalBytesForTable+=numBytes; |
|
76 |
if( bucket[i]>maxObjectsInBucket ) maxObjectsInBucket = bucket[i]; |
|
50 |
mInitialized = false; |
|
77 | 51 |
} |
52 |
} |
|
78 | 53 |
|
79 |
int totalBytesForBuckets = numBuckets*numBytesForIndices(totalBytesForTable); |
|
80 |
int constantModeBytes = (maxObjectsInBucket*numBits+7)/8; |
|
54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
81 | 55 |
|
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 |
*/ |
|
56 |
public TablebasesMITM() |
|
57 |
{ |
|
58 |
super(); |
|
86 | 59 |
} |
87 | 60 |
|
88 | 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
89 | 62 |
|
90 |
public void pack(int level, int numBits)
|
|
63 |
public TablebasesMITM(Resources res, int[] resourceIDs)
|
|
91 | 64 |
{ |
92 |
//mTable = new PruningTable(mTablebase,level,numBits); |
|
65 |
super(); |
|
66 |
|
|
67 |
int numOfIDs = resourceIDs.length; |
|
68 |
mTables = new PruningTable[numOfIDs]; |
|
69 |
mLevels = new int[numOfIDs]; |
|
70 |
mInitialized = true; |
|
71 |
|
|
72 |
for(int i=0; i<numOfIDs; i++) createPruningTable(res,resourceIDs[i],i); |
|
93 | 73 |
} |
94 | 74 |
|
95 | 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objectlib/tablebases/TablebasesPyraminx.java | ||
---|---|---|
246 | 246 |
return 9; |
247 | 247 |
} |
248 | 248 |
|
249 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
250 |
|
|
251 |
int[] getPruningLevels() |
|
252 |
{ |
|
253 |
return null; |
|
254 |
} |
|
255 |
|
|
249 | 256 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
250 | 257 |
|
251 | 258 |
public static void getEdgePermutation(int[] output, int[] quats, int index) |
src/main/java/org/distorted/objectlib/tablebases/TablebasesPyraminxDuo.java | ||
---|---|---|
101 | 101 |
|
102 | 102 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
103 | 103 |
|
104 |
int getMinScramble() |
|
104 |
int getMinScramble()
|
|
105 | 105 |
{ |
106 | 106 |
return 4; |
107 | 107 |
} |
108 | 108 |
|
109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
110 |
|
|
111 |
int[] getPruningLevels() |
|
112 |
{ |
|
113 |
return null; |
|
114 |
} |
|
115 |
|
|
109 | 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
110 | 117 |
|
111 | 118 |
int[] getQuats(int index) |
src/main/java/org/distorted/objectlib/tablebases/TablebasesSkewbDiamond.java | ||
---|---|---|
126 | 126 |
|
127 | 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
128 | 128 |
|
129 |
int getMinScramble() |
|
129 |
int getMinScramble()
|
|
130 | 130 |
{ |
131 | 131 |
return 8; |
132 | 132 |
} |
133 | 133 |
|
134 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
135 |
|
|
136 |
int[] getPruningLevels() |
|
137 |
{ |
|
138 |
return null; |
|
139 |
} |
|
140 |
|
|
134 | 141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
135 | 142 |
|
136 | 143 |
private int computeCenterQuat(int originalLocation, int newLocation) |
Also available in: Unified diff
progress with PruningTable.