Changeset 1657 for branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/NumberSequence.java
- Timestamp:
- 08/11/14 08:22:13 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/NumberSequence.java
r1653 r1657 8 8 private int id; 9 9 10 11 10 public NumberSequence(int size) { 12 11 13 12 sequence = new int[size]; 14 13 } 15 14 16 15 public int[] getSequence() { 17 16 return sequence; … … 45 44 } 46 45 47 // Searching occurrences of46 // Searching occurrences of 48 47 public LinkedList<Integer> containsPattern(Match pattern) { 49 48 LinkedList<Integer> result = new LinkedList<Integer>(); … … 51 50 int[] pat1 = pattern.getFirstSequence().getSequence(); 52 51 int[] pat2 = pattern.getSecondSequence().getSequence(); 53 notmatched: while (i < sequence.length - pat1.length) {52 notmatched: while (i <= sequence.length - pat1.length) { 54 53 if (sequence[i] == pat1[0] || sequence[i] == pat2[0]) { 55 int ipat1 = 0;56 int ipat2 = 0;54 int ipat1 = 0; 55 int ipat2 = 0; 57 56 int optcount1 = 0; 58 57 int optcount2 = 0; 59 while(ipat1 < pat1.length && ipat2<pat2.length) { 60 if(pat1[ipat1]==-1) { 61 ipat1++; 62 optcount1++; 63 continue; 64 } 65 if(pat2[ipat2]==-1) { 66 ipat2++; 67 optcount2++; 68 continue; 69 } 70 if (sequence[i + ipat1-optcount1] != pat1[ipat1] 71 && sequence[i + ipat2-optcount2] != pat2[ipat2]) { 58 while (ipat1 < pat1.length 59 && ipat2 < pat2.length) { 60 61 if (pat1[ipat1] == -1) { 62 ipat1++; 63 optcount1++; 64 continue; 65 } 66 67 if (pat2[ipat2] == -1) { 68 ipat2++; 69 optcount2++; 70 continue; 71 } 72 73 74 if (sequence[i + ipat1 - optcount1] != pat1[ipat1] 75 && sequence[i + ipat2 - optcount2] != pat2[ipat2]) { 72 76 i++; 73 //System.out.println(sequence[i+ipat1] + " != " + pat1[ipat1] + " || " + sequence[i+ipat2] + " != " + pat2[ipat2]); 77 // System.out.println(sequence[i+ipat1-optcount1] + 78 // " != " + pat1[ipat1] + " || " + 79 // sequence[i+ipat2-optcount2] + " != " + pat2[ipat2]); 74 80 continue notmatched; 75 81 } 76 ipat1++;77 ipat2++;82 ipat1++; 83 ipat2++; 78 84 } 85 79 86 result.add(i); 87 System.out.println("FOUND MATCH AT: " + i); 88 this.printSequence(); 89 pattern.getFirstSequence().printSequence(); 90 pattern.getSecondSequence().printSequence(); 80 91 } 81 92 i++; … … 83 94 return result; 84 95 } 85 86 // Returns the number of times event occurs in this sequence96 97 // Returns the number of times event occurs in this sequence 87 98 public int eventCount(int event) { 88 99 int count = 0; 89 for (int i=0;i<sequence.length;i++) {90 if (sequence[i] == event) {100 for (int i = 0; i < sequence.length; i++) { 101 if (sequence[i] == event) { 91 102 count++; 92 103 } … … 99 110 } 100 111 101 102 112 public int getId() { 103 113 return id; 104 114 } 105 115 106 107 116 public void setId(int id) { 108 117 this.id = id; 109 118 } 110 119 111 120 public boolean equals(NumberSequence n) { 112 121 int[] seq = n.getSequence(); 113 if (n.size() !=this.size()) {114 return false; 122 if (n.size() != this.size()) { 123 return false; 115 124 } 116 for (int i =0; i<n.size();i++) {117 if (seq[i] != this.sequence[i]) {125 for (int i = 0; i < n.size(); i++) { 126 if (seq[i] != this.sequence[i]) { 118 127 return false; 119 128 } … … 121 130 return true; 122 131 } 123 124 132 125 133 }
Note: See TracChangeset
for help on using the changeset viewer.