[1553] | 1 | package de.ugoe.cs.autoquest.tasktrees.alignment.algorithms; |
---|
[1450] | 2 | |
---|
[1618] | 3 | import java.util.ArrayList; |
---|
[1568] | 4 | import java.util.Random; |
---|
[1450] | 5 | |
---|
[1618] | 6 | public class NumberSequence { |
---|
[1450] | 7 | private int[] sequence; |
---|
| 8 | private int signature; |
---|
[1618] | 9 | |
---|
[1450] | 10 | public NumberSequence(int size) { |
---|
[1618] | 11 | |
---|
[1450] | 12 | sequence = new int[size]; |
---|
| 13 | } |
---|
[1618] | 14 | |
---|
[1450] | 15 | public int[] getSequence() { |
---|
| 16 | return sequence; |
---|
| 17 | } |
---|
[1618] | 18 | |
---|
[1450] | 19 | public void setSequence(int[] sequence) { |
---|
| 20 | this.sequence = sequence; |
---|
| 21 | } |
---|
[1618] | 22 | |
---|
[1450] | 23 | public int getSignature() { |
---|
| 24 | return signature; |
---|
| 25 | } |
---|
[1618] | 26 | |
---|
[1450] | 27 | public void setSignature(int signature) { |
---|
| 28 | this.signature = signature; |
---|
| 29 | } |
---|
[1618] | 30 | |
---|
| 31 | public void printSequence() { |
---|
[1558] | 32 | for (int i = 0; i < sequence.length; i++) { |
---|
[1559] | 33 | System.out.format("%5d", sequence[i]); |
---|
[1558] | 34 | } |
---|
| 35 | System.out.println(); |
---|
| 36 | } |
---|
[1618] | 37 | |
---|
| 38 | public NumberSequence shuffle() { |
---|
[1568] | 39 | NumberSequence result = new NumberSequence(sequence.length); |
---|
| 40 | result.setSequence(this.sequence); |
---|
| 41 | Random rgen = new Random(); |
---|
[1618] | 42 | |
---|
| 43 | for (int i = 0; i < result.sequence.length; i++) { |
---|
| 44 | int randomPosition = rgen.nextInt(result.sequence.length); |
---|
| 45 | int temp = result.sequence[i]; |
---|
| 46 | result.sequence[i] = result.sequence[randomPosition]; |
---|
| 47 | result.sequence[randomPosition] = temp; |
---|
[1568] | 48 | } |
---|
| 49 | return result; |
---|
[1618] | 50 | |
---|
[1568] | 51 | } |
---|
[1450] | 52 | |
---|
[1618] | 53 | // TODO: This can be done faster |
---|
| 54 | public int containsPattern(ArrayList<NumberSequence> pattern) { |
---|
| 55 | int i = 0; |
---|
| 56 | int count = 0; |
---|
| 57 | int[] pat1 = pattern.get(0).getSequence(); |
---|
| 58 | int[] pat2 = pattern.get(1).getSequence(); |
---|
| 59 | notmatched: while (i < sequence.length - pat1.length) { |
---|
| 60 | if (sequence[i] == pat1[0] || sequence[i] == pat2[0]) { |
---|
| 61 | for (int j = 0; j < pat1.length; j++) { |
---|
| 62 | if (sequence[i + j] != pat1[j] |
---|
| 63 | && sequence[i + j] != pat2[j]) { |
---|
| 64 | continue notmatched; |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | count++; |
---|
| 68 | } |
---|
| 69 | i++; |
---|
| 70 | } |
---|
| 71 | return count; |
---|
| 72 | } |
---|
| 73 | |
---|
[1592] | 74 | public int size() { |
---|
| 75 | return sequence.length; |
---|
| 76 | } |
---|
[1450] | 77 | } |
---|