[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; |
---|
[1620] | 8 | private int id; |
---|
[1618] | 9 | |
---|
[1620] | 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 | |
---|
[1450] | 25 | public NumberSequence(int size) { |
---|
[1618] | 26 | |
---|
[1450] | 27 | sequence = new int[size]; |
---|
| 28 | } |
---|
[1620] | 29 | |
---|
[1450] | 30 | public int[] getSequence() { |
---|
| 31 | return sequence; |
---|
| 32 | } |
---|
[1618] | 33 | |
---|
[1450] | 34 | public void setSequence(int[] sequence) { |
---|
| 35 | this.sequence = sequence; |
---|
| 36 | } |
---|
[1618] | 37 | |
---|
[1620] | 38 | |
---|
[1618] | 39 | |
---|
| 40 | public void printSequence() { |
---|
[1558] | 41 | for (int i = 0; i < sequence.length; i++) { |
---|
[1559] | 42 | System.out.format("%5d", sequence[i]); |
---|
[1558] | 43 | } |
---|
| 44 | System.out.println(); |
---|
| 45 | } |
---|
[1618] | 46 | |
---|
| 47 | public NumberSequence shuffle() { |
---|
[1568] | 48 | NumberSequence result = new NumberSequence(sequence.length); |
---|
[1620] | 49 | result.setId(getId()); |
---|
[1568] | 50 | result.setSequence(this.sequence); |
---|
| 51 | Random rgen = new Random(); |
---|
[1618] | 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; |
---|
[1568] | 58 | } |
---|
| 59 | return result; |
---|
[1618] | 60 | |
---|
[1568] | 61 | } |
---|
[1450] | 62 | |
---|
[1620] | 63 | |
---|
| 64 | public int containsPattern(Match pattern) { |
---|
[1618] | 65 | int i = 0; |
---|
| 66 | int count = 0; |
---|
[1620] | 67 | int[] pat1 = pattern.getFirstSequence().getSequence(); |
---|
| 68 | int[] pat2 = pattern.getSecondSequence().getSequence(); |
---|
[1618] | 69 | notmatched: while (i < sequence.length - pat1.length) { |
---|
| 70 | if (sequence[i] == pat1[0] || sequence[i] == pat2[0]) { |
---|
[1620] | 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]) { |
---|
[1619] | 84 | i++; |
---|
[1618] | 85 | continue notmatched; |
---|
| 86 | } |
---|
[1620] | 87 | ipat1++; |
---|
| 88 | ipat2++; |
---|
[1618] | 89 | } |
---|
| 90 | count++; |
---|
| 91 | } |
---|
| 92 | i++; |
---|
| 93 | } |
---|
| 94 | return count; |
---|
| 95 | } |
---|
[1620] | 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 | } |
---|
[1618] | 107 | |
---|
[1592] | 108 | public int size() { |
---|
| 109 | return sequence.length; |
---|
| 110 | } |
---|
[1620] | 111 | |
---|
| 112 | |
---|
| 113 | public int getId() { |
---|
| 114 | return id; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | public void setId(int id) { |
---|
| 119 | this.id = id; |
---|
| 120 | } |
---|
[1450] | 121 | } |
---|