Revision 039ff951
Added by Leszek Koltunski 10 months ago
src/main/java/org/distorted/objectlib/algsolvers/MitmTable.java | ||
---|---|---|
13 | 13 |
|
14 | 14 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
15 | 15 |
|
16 |
public class MitmTable
|
|
16 |
class MitmTable |
|
17 | 17 |
{ |
18 | 18 |
private final int mBytesPerEntry; |
19 | 19 |
private final int mBitsPerQuat; |
... | ... | |
22 | 22 |
|
23 | 23 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
24 | 24 |
|
25 |
public MitmTable(int numCubits, int numQuats)
|
|
25 |
MitmTable(int numCubits, int numQuats) |
|
26 | 26 |
{ |
27 | 27 |
mNumQuats = numQuats; |
28 | 28 |
double tmp = Math.log(numQuats) / Math.log(2); |
src/main/java/org/distorted/objectlib/algsolvers/PhaseSolutionFinder.java | ||
---|---|---|
10 | 10 |
package org.distorted.objectlib.algsolvers; |
11 | 11 |
|
12 | 12 |
import org.distorted.library.type.Static4D; |
13 |
import org.distorted.objectlib.helpers.OperatingSystemInterface; |
|
14 | 13 |
|
15 | 14 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
16 | 15 |
|
17 |
public class PhaseSolutionFinder
|
|
16 |
class PhaseSolutionFinder |
|
18 | 17 |
{ |
19 | 18 |
private final static int MAX_MEMORY = 6*1024*1024; // 6MB max for the MitM table |
20 | 19 |
private final static double MAX_SEARCH = 3000000.0; // max 3mln positions back-searched |
... | ... | |
26 | 25 |
|
27 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
28 | 27 |
|
29 |
public PhaseSolutionFinder(SolvedObject object)
|
|
28 |
PhaseSolutionFinder(SolvedObject object) |
|
30 | 29 |
{ |
31 | 30 |
mObject = object; |
32 | 31 |
Static4D[] quats = object.getQuats(); |
... | ... | |
145 | 144 |
// Subphases can be solved in any order. |
146 | 145 |
// Calling function has already set up the endQuats of all cubits from future phases to null. |
147 | 146 |
|
148 |
int[] findSolutionSubphases(int[][] endQuats, Phase phase, int numSubphases, OperatingSystemInterface osi)
|
|
147 |
int[] findSolutionSubphases(int[][] endQuats, Phase phase, int numSubphases) |
|
149 | 148 |
{ |
150 | 149 |
int sub=0; |
151 | 150 |
int numQuats = endQuats.length; |
... | ... | |
163 | 162 |
|
164 | 163 |
if( !success ) |
165 | 164 |
{ |
166 |
osi.reportError("findSolutionSubphases: failed to solve subphase "+sub);
|
|
165 |
android.util.Log.e("D","findSolutionSubphases: failed to solve subphase "+sub);
|
|
167 | 166 |
break; |
168 | 167 |
} |
169 | 168 |
} |
src/main/java/org/distorted/objectlib/algsolvers/PhasedSolver.java | ||
---|---|---|
11 | 11 |
|
12 | 12 |
import org.distorted.library.helpers.QuatHelper; |
13 | 13 |
import org.distorted.library.type.Static4D; |
14 |
import org.distorted.objectlib.helpers.OperatingSystemInterface; |
|
15 | 14 |
|
16 | 15 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
17 | 16 |
|
18 |
public abstract class PhasedSolver
|
|
17 |
public class PhasedSolver |
|
19 | 18 |
{ |
20 | 19 |
public static final int MODE_ALL_AT_ONCE_OP = 0; // define a subset of cubits; solve their |
21 | 20 |
// orientation and permutation all in one go |
... | ... | |
175 | 174 |
// quats get overwritten at the end of the phase |
176 | 175 |
// return null on error |
177 | 176 |
|
178 |
private int[] solutionOfPhase(int phase, int[] quats, OperatingSystemInterface osi)
|
|
177 |
private int[] solutionOfPhase(int phase, int[] quats) |
|
179 | 178 |
{ |
180 | 179 |
Phase p = mPhases[phase]; |
181 | 180 |
int numSubphases = p.numSubphases(); |
182 | 181 |
int mode = p.getMode(); |
183 |
int numCubits = p.numCubitsInvolved();
|
|
182 |
int numCubits = mPositions.length;
|
|
184 | 183 |
int[][] endQuats = new int[numCubits][]; |
185 | 184 |
|
186 | 185 |
for(int c=0; c<numCubits; c++) |
... | ... | |
192 | 191 |
|
193 | 192 |
if( numSubphases>1 ) |
194 | 193 |
{ |
195 |
return mFinder.findSolutionSubphases(endQuats, p, numSubphases, osi);
|
|
194 |
return mFinder.findSolutionSubphases(endQuats,p,numSubphases);
|
|
196 | 195 |
} |
197 | 196 |
else |
198 | 197 |
{ |
... | ... | |
203 | 202 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
204 | 203 |
// return: [num of phase][num of move in phase] |
205 | 204 |
|
206 |
public int[][] solution(int[] quats, OperatingSystemInterface osi)
|
|
205 |
public int[][] solution(int[] quats) |
|
207 | 206 |
{ |
208 | 207 |
int[][] solution_moves = new int[mNumPhases][]; |
209 | 208 |
mFinder.prepareForSolution(quats); |
210 | 209 |
|
211 | 210 |
for(int i=0; i<mNumPhases; i++) |
212 | 211 |
{ |
213 |
solution_moves[i] = solutionOfPhase(i,quats,osi);
|
|
212 |
solution_moves[i] = solutionOfPhase(i,quats); |
|
214 | 213 |
|
215 | 214 |
if( solution_moves[i]==null ) |
216 | 215 |
{ |
217 |
osi.reportError("AlgSolver: error solving phase "+i);
|
|
216 |
android.util.Log.e("D","AlgSolver: error solving phase "+i);
|
|
218 | 217 |
break; |
219 | 218 |
} |
220 | 219 |
} |
src/main/java/org/distorted/objectlib/algsolvers/SolvedObjectCubit.java | ||
---|---|---|
17 | 17 |
|
18 | 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
19 | 19 |
|
20 |
public class SolvedObjectCubit
|
|
20 |
class SolvedObjectCubit |
|
21 | 21 |
{ |
22 | 22 |
private final int mNumCubits; |
23 | 23 |
private final int[][] mQuatMult; |
... | ... | |
167 | 167 |
{ |
168 | 168 |
int size = data.size(); |
169 | 169 |
int len = pos.length; |
170 |
float MAXERR = 0.001f; |
|
170 | 171 |
|
171 | 172 |
for(int i=0; i<size; i++) |
172 | 173 |
{ |
... | ... | |
174 | 175 |
float[] p = rd.position; |
175 | 176 |
int len1 = p.length; |
176 | 177 |
|
177 |
if( len==len1 )
|
|
178 |
if( 3*len==4*len1 ) // 'pos' is after rotating, contains the 4th component
|
|
178 | 179 |
{ |
179 | 180 |
boolean same = true; |
180 | 181 |
|
181 |
for(int l=0; l<len; l++) |
|
182 |
if( p[l] != pos[l] ) |
|
182 |
for(int l=0; l<len1; l++) |
|
183 |
{ |
|
184 |
float err = p[l]-pos[l]; |
|
185 |
|
|
186 |
if( err>MAXERR || err<-MAXERR ) |
|
183 | 187 |
{ |
184 | 188 |
same = false; |
185 | 189 |
break; |
186 | 190 |
} |
191 |
} |
|
187 | 192 |
|
188 | 193 |
if( same ) return i; |
189 | 194 |
} |
... | ... | |
216 | 221 |
} |
217 | 222 |
|
218 | 223 |
boolean added; |
219 |
float[] tmp = new float[maxsize];
|
|
224 |
float[] tmp = new float[4*maxsize/3];
|
|
220 | 225 |
int size = mNumCubits; |
221 | 226 |
|
222 | 227 |
do |
Also available in: Unified diff
various bugfixes for the PhasedSolver (doesn't work yet)