1 | package de.ugoe.cs.autoquest.tasktrees.alignment.algorithms; |
---|
2 | |
---|
3 | import java.util.ArrayList; |
---|
4 | import java.util.Random; |
---|
5 | |
---|
6 | public class NumberSequence { |
---|
7 | private int[] sequence; |
---|
8 | private int signature; |
---|
9 | |
---|
10 | public NumberSequence(int size) { |
---|
11 | |
---|
12 | sequence = new int[size]; |
---|
13 | } |
---|
14 | |
---|
15 | public int[] getSequence() { |
---|
16 | return sequence; |
---|
17 | } |
---|
18 | |
---|
19 | public void setSequence(int[] sequence) { |
---|
20 | this.sequence = sequence; |
---|
21 | } |
---|
22 | |
---|
23 | public int getSignature() { |
---|
24 | return signature; |
---|
25 | } |
---|
26 | |
---|
27 | public void setSignature(int signature) { |
---|
28 | this.signature = signature; |
---|
29 | } |
---|
30 | |
---|
31 | public void printSequence() { |
---|
32 | for (int i = 0; i < sequence.length; i++) { |
---|
33 | System.out.format("%5d", sequence[i]); |
---|
34 | } |
---|
35 | System.out.println(); |
---|
36 | } |
---|
37 | |
---|
38 | public NumberSequence shuffle() { |
---|
39 | NumberSequence result = new NumberSequence(sequence.length); |
---|
40 | result.setSequence(this.sequence); |
---|
41 | Random rgen = new Random(); |
---|
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; |
---|
48 | } |
---|
49 | return result; |
---|
50 | |
---|
51 | } |
---|
52 | |
---|
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 | i++; |
---|
65 | continue notmatched; |
---|
66 | } |
---|
67 | } |
---|
68 | count++; |
---|
69 | } |
---|
70 | i++; |
---|
71 | } |
---|
72 | return count; |
---|
73 | } |
---|
74 | |
---|
75 | public int size() { |
---|
76 | return sequence.length; |
---|
77 | } |
---|
78 | } |
---|