Changeset 1660 for branches/autoquest-core-tasktrees-alignment/src
- Timestamp:
- 08/11/14 22:39:00 (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
r1657 r1660 44 44 } 45 45 46 // Searching occurrences of 46 //Recursive check if sequence contains pattern at position i 47 public boolean matches(int i, int[] p1, int[] p2 ,int ip1,int ip2) { 48 49 if(p1.length==ip1) { 50 return true; 51 } 52 if(p2.length==ip2) { 53 return true; 54 } 55 if(i==sequence.length) { 56 return false; 57 } 58 if(p1[ip1]==sequence[i]||p2[ip2]==sequence[i]) { 59 return matches(i+1,p1,p2,ip1+1,ip2+1); 60 } 61 if(p1[ip1]==-1) { 62 return matches(i,p1,p2,ip1+1,ip2); 63 } 64 if(p2[ip2]==-1) { 65 return matches(i,p1,p2,ip1,ip2+1); 66 } 67 return false; 68 } 69 70 //Searching occurrences of pattern 71 47 72 public LinkedList<Integer> containsPattern(Match pattern) { 48 73 LinkedList<Integer> result = new LinkedList<Integer>(); … … 50 75 int[] pat1 = pattern.getFirstSequence().getSequence(); 51 76 int[] pat2 = pattern.getSecondSequence().getSequence(); 52 notmatched: while (i <= sequence.length - pat1.length) {53 if (sequence[i] == pat1[0] || sequence[i] == pat2[0]) {54 int ipat1 = 0;55 int ipat2 = 0;56 int optcount1 = 0;57 int optcount2 = 0;58 while (ipat1 < pat1.length59 && 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 77 74 if (sequence[i + ipat1 - optcount1] != pat1[ipat1] 75 && sequence[i + ipat2 - optcount2] != pat2[ipat2]) { 76 i++; 77 // System.out.println(sequence[i+ipat1-optcount1] + 78 // " != " + pat1[ipat1] + " || " + 79 // sequence[i+ipat2-optcount2] + " != " + pat2[ipat2]); 80 continue notmatched; 81 } 82 ipat1++; 83 ipat2++; 84 } 85 78 while (i < sequence.length ) { 79 if(matches(i,pat1,pat2,0,0)) { 80 System.out.println(i); 86 81 result.add(i); 87 82 System.out.println("FOUND MATCH AT: " + i);
Note: See TracChangeset
for help on using the changeset viewer.