Revisions: comments, hashcode, efficiency
Benjamin Bardin
9 years ago
1 | 1 | |
2 | 2 | import java.util.ArrayList; |
3 | 3 | |
4 | /** | |
5 | * Note: this class has a natural ordering that is inconsistent with equals. | |
6 | */ | |
4 | 7 | public class PidExperiment implements Comparable<PidExperiment> { |
5 | 8 | public static final long MAX_TIME_MILLIS = 10000; |
6 | 9 | public static final double THRESHOLD_ANGLE = 20.0; |
61 | 64 | // mScore saved once processed (lazy evaluation) |
62 | 65 | if (mScore != -1) return mScore; |
63 | 66 | |
67 | // If we don't get to the start of a third cycle, this experiment | |
68 | // was really bad. Return MAX_VALUE. | |
64 | 69 | if (isTimeUp()) { |
65 | 70 | mScore = Integer.MAX_VALUE; |
66 | 71 | return mScore; |
123 | 128 | return (getP() == other.getP()) && (getI() == other.getI()) && (getD() == other.getD()); |
124 | 129 | } |
125 | 130 | |
131 | public int hashCode() { | |
132 | return new Double(getP()).hashCode() ^ | |
133 | new Double(getI()).hashCode() ^ | |
134 | new Double(getD()).hashCode(); | |
135 | } | |
136 | ||
126 | 137 | public int compareTo(PidExperiment other) { |
127 | 138 | if (getScore() == other.getScore()) return 0; |
128 | 139 | if (getScore() < other.getScore()) return -1; |