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 id; |
---|
9 | |
---|
10 | public ArrayList<Match> getMatches() { |
---|
11 | return matches; |
---|
12 | } |
---|
13 | |
---|
14 | |
---|
15 | public void setMatches(ArrayList<Match> matches) { |
---|
16 | this.matches = matches; |
---|
17 | } |
---|
18 | |
---|
19 | public void addMatches(ArrayList<Match> matches) { |
---|
20 | this.matches.addAll(matches); |
---|
21 | } |
---|
22 | |
---|
23 | private ArrayList<Match> matches; |
---|
24 | |
---|
25 | public NumberSequence(int size) { |
---|
26 | |
---|
27 | sequence = new int[size]; |
---|
28 | } |
---|
29 | |
---|
30 | public int[] getSequence() { |
---|
31 | return sequence; |
---|
32 | } |
---|
33 | |
---|
34 | public void setSequence(int[] sequence) { |
---|
35 | this.sequence = sequence; |
---|
36 | } |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | public void printSequence() { |
---|
41 | for (int i = 0; i < sequence.length; i++) { |
---|
42 | System.out.format("%5d", sequence[i]); |
---|
43 | } |
---|
44 | System.out.println(); |
---|
45 | } |
---|
46 | |
---|
47 | public NumberSequence shuffle() { |
---|
48 | NumberSequence result = new NumberSequence(sequence.length); |
---|
49 | result.setId(getId()); |
---|
50 | result.setSequence(this.sequence); |
---|
51 | Random rgen = new Random(); |
---|
52 | |
---|
53 | for (int i = 0; i < result.sequence.length; i++) { |
---|
54 | int randomPosition = rgen.nextInt(result.sequence.length); |
---|
55 | int temp = result.sequence[i]; |
---|
56 | result.sequence[i] = result.sequence[randomPosition]; |
---|
57 | result.sequence[randomPosition] = temp; |
---|
58 | } |
---|
59 | return result; |
---|
60 | |
---|
61 | } |
---|
62 | |
---|
63 | |
---|
64 | public int containsPattern(Match pattern) { |
---|
65 | int i = 0; |
---|
66 | int count = 0; |
---|
67 | int[] pat1 = pattern.getFirstSequence().getSequence(); |
---|
68 | int[] pat2 = pattern.getSecondSequence().getSequence(); |
---|
69 | notmatched: while (i < sequence.length - pat1.length) { |
---|
70 | if (sequence[i] == pat1[0] || sequence[i] == pat2[0]) { |
---|
71 | int ipat1 =0; |
---|
72 | int ipat2 =0; |
---|
73 | while(ipat1 < pat1.length && ipat2<pat2.length) { |
---|
74 | if(pat1[ipat1]==-1) { |
---|
75 | ipat1++; |
---|
76 | continue; |
---|
77 | } |
---|
78 | if(pat2[ipat2]==-1) { |
---|
79 | ipat2++; |
---|
80 | continue; |
---|
81 | } |
---|
82 | if (sequence[i + ipat1] != pat1[ipat1] |
---|
83 | && sequence[i + ipat2] != pat2[ipat2]) { |
---|
84 | i++; |
---|
85 | continue notmatched; |
---|
86 | } |
---|
87 | ipat1++; |
---|
88 | ipat2++; |
---|
89 | } |
---|
90 | count++; |
---|
91 | } |
---|
92 | i++; |
---|
93 | } |
---|
94 | return count; |
---|
95 | } |
---|
96 | |
---|
97 | //Returns the number of times event occurs in this sequence |
---|
98 | public int eventCount(int event) { |
---|
99 | int count = 0; |
---|
100 | for(int i=0;i<sequence.length;i++) { |
---|
101 | if(sequence[i] == event) { |
---|
102 | count++; |
---|
103 | } |
---|
104 | } |
---|
105 | return count; |
---|
106 | } |
---|
107 | |
---|
108 | public int size() { |
---|
109 | return sequence.length; |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | public int getId() { |
---|
114 | return id; |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | public void setId(int id) { |
---|
119 | this.id = id; |
---|
120 | } |
---|
121 | } |
---|