Better error logs
This commit is contained in:
parent
19083a380a
commit
345b53eeff
@ -126,7 +126,7 @@ public class Utils {
|
|||||||
if (StaticVars.outputLevel == 0) {
|
if (StaticVars.outputLevel == 0) {
|
||||||
println(System.out);
|
println(System.out);
|
||||||
} else {
|
} else {
|
||||||
println(System.err);
|
println(System.out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ public class Utils {
|
|||||||
if (StaticVars.outputLevel == 0) {
|
if (StaticVars.outputLevel == 0) {
|
||||||
println(System.out, "[" + time + "]"+str);
|
println(System.out, "[" + time + "]"+str);
|
||||||
} else {
|
} else {
|
||||||
println(System.err, "[" + time + "]"+str);
|
println(System.out, "[" + time + "]"+str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ public class Utils {
|
|||||||
if (StaticVars.outputLevel == 0) {
|
if (StaticVars.outputLevel == 0) {
|
||||||
print(System.out, str);
|
print(System.out, str);
|
||||||
} else {
|
} else {
|
||||||
print(System.err, str);
|
print(System.out, str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -158,7 +158,7 @@ public class Utils {
|
|||||||
if (StaticVars.outputLevel == 0) {
|
if (StaticVars.outputLevel == 0) {
|
||||||
println(System.out, "[" + time + "][" + prefix + "]" + str);
|
println(System.out, "[" + time + "][" + prefix + "]" + str);
|
||||||
} else {
|
} else {
|
||||||
println(System.err, "[" + time + "][" + prefix + "]" + str);
|
println(System.out, "[" + time + "][" + prefix + "]" + str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,7 +177,7 @@ public class Utils {
|
|||||||
if (StaticVars.outputLevel == 0) {
|
if (StaticVars.outputLevel == 0) {
|
||||||
println(System.out, "[" + time + "]" + output);
|
println(System.out, "[" + time + "]" + output);
|
||||||
} else {
|
} else {
|
||||||
println(System.err, "[" + time + "]" + output);
|
println(System.out, "[" + time + "]" + output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.warp.picalculator.math.solver;
|
package org.warp.picalculator.math.solver;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.StaticVars;
|
import org.warp.picalculator.StaticVars;
|
||||||
@ -15,7 +16,7 @@ import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
|||||||
public class MathSolver {
|
public class MathSolver {
|
||||||
|
|
||||||
private final Function initialFunction;
|
private final Function initialFunction;
|
||||||
private int stepState = 0;
|
private AtomicInteger stepState = new AtomicInteger(0);
|
||||||
private int currentStepStateN = 0;
|
private int currentStepStateN = 0;
|
||||||
private int consecutiveNullSteps = 0;
|
private int consecutiveNullSteps = 0;
|
||||||
private enum StepState {
|
private enum StepState {
|
||||||
@ -37,19 +38,17 @@ public class MathSolver {
|
|||||||
ObjectArrayList<Function> lastFnc = null, currFnc = new ObjectArrayList<>();
|
ObjectArrayList<Function> lastFnc = null, currFnc = new ObjectArrayList<>();
|
||||||
Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_VERBOSE, "Math Solver", "Solving all steps. Input: " + initialFunction.toString());
|
Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_VERBOSE, "Math Solver", "Solving all steps. Input: " + initialFunction.toString());
|
||||||
currFnc.add(initialFunction);
|
currFnc.add(initialFunction);
|
||||||
long debugStepNumber = 0;
|
long stepNumber = 0;
|
||||||
int stepBefore = 0, stepAfter = 0;
|
int stepBefore = 0, stepAfter = 0;
|
||||||
|
AtomicInteger stepState = new AtomicInteger(0);
|
||||||
do {
|
do {
|
||||||
final String stepName = "Step " + debugStepNumber;
|
final String stepName = "Step " + stepNumber;
|
||||||
for (int i = stepBefore; i <= stepAfter; i++) {
|
for (int i = stepBefore; i <= stepAfter; i++) {
|
||||||
lastFnc = lastFunctions[i] = currFnc;
|
lastFnc = lastFunctions[i] = currFnc;
|
||||||
}
|
}
|
||||||
Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_VERBOSE, "Math Solver", stepName, "Starting step. Input: " + currFnc);
|
stepBefore = stepState.get();
|
||||||
stepBefore = stepState;
|
Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_VERBOSE, "Math Solver", stepName, "Starting step " + stepStates[stepBefore] + ". Input: " + currFnc);
|
||||||
ObjectArrayList<Function> stepResult = solveStep(lastFnc);
|
ObjectArrayList<Function> stepResult = solveStep(lastFnc, stepState);
|
||||||
Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_VERBOSE, "Math Solver", stepName, "Step state: " + stepStates[stepState]);
|
|
||||||
Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_VERBOSE, "Math Solver", stepName, "Step result: " + stepResult);
|
|
||||||
Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_VERBOSE, "Math Solver", stepName, "Step result details: Consecutive steps that did nothing: " + consecutiveNullSteps + ", this step did " + currentStepStateN + " simplifications.");
|
|
||||||
if (stepResult == null) {
|
if (stepResult == null) {
|
||||||
currFnc = lastFnc;
|
currFnc = lastFnc;
|
||||||
} else {
|
} else {
|
||||||
@ -59,9 +58,13 @@ public class MathSolver {
|
|||||||
currFnc = stepResult;
|
currFnc = stepResult;
|
||||||
steps.add(currFnc);
|
steps.add(currFnc);
|
||||||
}
|
}
|
||||||
stepAfter = stepState;
|
stepAfter = stepState.get();
|
||||||
debugStepNumber++;
|
stepNumber++;
|
||||||
} while(consecutiveNullSteps < stepStates.length && !checkEquals(currFnc, lastFunctions[stepState]));
|
|
||||||
|
Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_VERBOSE, "Math Solver", stepName, "Step result: " + stepResult);
|
||||||
|
Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_VERBOSE, "Math Solver", stepName, "Step result details: Consecutive steps that did nothing: " + consecutiveNullSteps + ", this step did " + currentStepStateN + " simplifications.");
|
||||||
|
Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_VERBOSE, "Math Solver", stepName, "Next step state: " + stepStates[stepAfter]);
|
||||||
|
} while(consecutiveNullSteps < stepStates.length &&!checkEquals(currFnc, lastFunctions[stepAfter]));
|
||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,12 +88,16 @@ public class MathSolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ObjectArrayList<Function> solveStep(ObjectArrayList<Function> fncs) throws InterruptedException, Error {
|
private ObjectArrayList<Function> solveStep(ObjectArrayList<Function> fncs) throws InterruptedException, Error {
|
||||||
|
return solveStep(fncs, stepState);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ObjectArrayList<Function> solveStep(ObjectArrayList<Function> fncs, AtomicInteger stepState) throws InterruptedException, Error {
|
||||||
ObjectArrayList<Function> processedFncs = applyRules(fncs, RuleType.EXISTENCE); // Apply existence rules before everything
|
ObjectArrayList<Function> processedFncs = applyRules(fncs, RuleType.EXISTENCE); // Apply existence rules before everything
|
||||||
if (processedFncs != null) {
|
if (processedFncs != null) {
|
||||||
fncs = processedFncs;
|
fncs = processedFncs;
|
||||||
}
|
}
|
||||||
RuleType currentAcceptedRules;
|
RuleType currentAcceptedRules;
|
||||||
switch(stepStates[stepState]) {
|
switch(stepStates[stepState.get()]) {
|
||||||
case _1_CALCULATION: {
|
case _1_CALCULATION: {
|
||||||
currentAcceptedRules = RuleType.CALCULATION;
|
currentAcceptedRules = RuleType.CALCULATION;
|
||||||
break;
|
break;
|
||||||
@ -112,10 +119,10 @@ public class MathSolver {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
ObjectArrayList<Function> results = applyRules(fncs, currentAcceptedRules);
|
ObjectArrayList<Function> results = applyRules(fncs, currentAcceptedRules);
|
||||||
switch(stepStates[stepState]) {
|
switch(stepStates[stepState.get()]) {
|
||||||
case _1_CALCULATION: {
|
case _1_CALCULATION: {
|
||||||
if (results == null) {
|
if (results == null) {
|
||||||
stepState++;
|
stepState.incrementAndGet();
|
||||||
consecutiveNullSteps++;
|
consecutiveNullSteps++;
|
||||||
currentStepStateN = 0;
|
currentStepStateN = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -128,10 +135,10 @@ public class MathSolver {
|
|||||||
case _2_EXPANSION: {
|
case _2_EXPANSION: {
|
||||||
if (results == null) {
|
if (results == null) {
|
||||||
if (currentStepStateN == 0) {
|
if (currentStepStateN == 0) {
|
||||||
stepState += 2;
|
stepState.addAndGet(2);
|
||||||
consecutiveNullSteps += 2;
|
consecutiveNullSteps += 2;
|
||||||
} else {
|
} else {
|
||||||
stepState++;
|
stepState.incrementAndGet();
|
||||||
consecutiveNullSteps++;
|
consecutiveNullSteps++;
|
||||||
}
|
}
|
||||||
currentStepStateN = 0;
|
currentStepStateN = 0;
|
||||||
@ -144,7 +151,7 @@ public class MathSolver {
|
|||||||
}
|
}
|
||||||
case _3_CALCULATION: {
|
case _3_CALCULATION: {
|
||||||
if (results == null) {
|
if (results == null) {
|
||||||
stepState++;
|
stepState.incrementAndGet();
|
||||||
consecutiveNullSteps++;
|
consecutiveNullSteps++;
|
||||||
currentStepStateN = 0;
|
currentStepStateN = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -156,11 +163,11 @@ public class MathSolver {
|
|||||||
}
|
}
|
||||||
case _4_REDUCTION: {
|
case _4_REDUCTION: {
|
||||||
if (results == null) {
|
if (results == null) {
|
||||||
stepState = 1;
|
stepState.set(1);
|
||||||
consecutiveNullSteps++;
|
consecutiveNullSteps++;
|
||||||
currentStepStateN = 0;
|
currentStepStateN = 0;
|
||||||
} else {
|
} else {
|
||||||
stepState = 0;
|
stepState.set(0);
|
||||||
consecutiveNullSteps = 0;
|
consecutiveNullSteps = 0;
|
||||||
currentStepStateN++;
|
currentStepStateN++;
|
||||||
return results;
|
return results;
|
||||||
@ -190,7 +197,7 @@ public class MathSolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (StaticVars.debugOn & results != null & appliedRule != null) {
|
if (StaticVars.debugOn & results != null & appliedRule != null) {
|
||||||
Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_VERBOSE, "Math Solver", stepStates[stepState].toString(), "Applied rule " + appliedRule.getRuleName());
|
Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_VERBOSE, "Math Solver", currentAcceptedRules.toString(), "Applied rule " + appliedRule.getRuleName());
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user