Ignore:
Timestamp:
08/11/14 08:22:13 (10 years ago)
Author:
rkrimmel
Message:

About to fix bug in containsPattern

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  
    88        private int id; 
    99 
    10  
    1110        public NumberSequence(int size) { 
    1211 
    1312                sequence = new int[size]; 
    1413        } 
    15          
     14 
    1615        public int[] getSequence() { 
    1716                return sequence; 
     
    4544        } 
    4645 
    47         //Searching occurrences of  
     46        // Searching occurrences of 
    4847        public LinkedList<Integer> containsPattern(Match pattern) { 
    4948                LinkedList<Integer> result = new LinkedList<Integer>(); 
     
    5150                int[] pat1 = pattern.getFirstSequence().getSequence(); 
    5251                int[] pat2 = pattern.getSecondSequence().getSequence(); 
    53                 notmatched: while (i < sequence.length - pat1.length) { 
     52                notmatched: while (i <= sequence.length - pat1.length) { 
    5453                        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; 
    5756                                int optcount1 = 0; 
    5857                                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]) { 
    7276                                                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]); 
    7480                                                continue notmatched; 
    7581                                        } 
    76                                         ipat1++; 
    77                                         ipat2++; 
     82                                                ipat1++; 
     83                                                ipat2++; 
    7884                                } 
     85                                 
    7986                                result.add(i); 
     87                                System.out.println("FOUND MATCH AT: " + i); 
     88                                this.printSequence(); 
     89                                pattern.getFirstSequence().printSequence(); 
     90                                pattern.getSecondSequence().printSequence(); 
    8091                        } 
    8192                        i++; 
     
    8394                return result; 
    8495        } 
    85          
    86         //Returns the number of times event occurs in this sequence 
     96 
     97        // Returns the number of times event occurs in this sequence 
    8798        public int eventCount(int event) { 
    8899                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) { 
    91102                                count++; 
    92103                        } 
     
    99110        } 
    100111 
    101  
    102112        public int getId() { 
    103113                return id; 
    104114        } 
    105115 
    106  
    107116        public void setId(int id) { 
    108117                this.id = id; 
    109118        } 
    110          
     119 
    111120        public boolean equals(NumberSequence n) { 
    112121                int[] seq = n.getSequence(); 
    113                 if(n.size() !=this.size()) { 
    114                         return false;  
     122                if (n.size() != this.size()) { 
     123                        return false; 
    115124                } 
    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]) { 
    118127                                return false; 
    119128                        } 
     
    121130                return true; 
    122131        } 
    123          
    124          
     132 
    125133} 
Note: See TracChangeset for help on using the changeset viewer.