Ignore:
Timestamp:
07/16/14 18:07:05 (10 years ago)
Author:
rkrimmel
Message:

Startet implementing signigicant match detection

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/NumberSequence.java

    r1592 r1618  
    11package de.ugoe.cs.autoquest.tasktrees.alignment.algorithms; 
    22 
    3  
     3import java.util.ArrayList; 
    44import java.util.Random; 
    55 
    6 public class NumberSequence  { 
     6public class NumberSequence { 
    77        private int[] sequence; 
    88        private int signature; 
    9          
     9 
    1010        public NumberSequence(int size) { 
    11                  
     11 
    1212                sequence = new int[size]; 
    1313        } 
    14          
     14 
    1515        public int[] getSequence() { 
    1616                return sequence; 
    1717        } 
     18 
    1819        public void setSequence(int[] sequence) { 
    1920                this.sequence = sequence; 
    2021        } 
     22 
    2123        public int getSignature() { 
    2224                return signature; 
    2325        } 
     26 
    2427        public void setSignature(int signature) { 
    2528                this.signature = signature; 
    2629        } 
    27          
    28         public void printSequence() 
    29         {        
     30 
     31        public void printSequence() { 
    3032                for (int i = 0; i < sequence.length; i++) { 
    3133                        System.out.format("%5d", sequence[i]); 
     
    3335                System.out.println(); 
    3436        } 
    35          
    36         public NumberSequence shuffle(){ 
     37 
     38        public NumberSequence shuffle() { 
    3739                NumberSequence result = new NumberSequence(sequence.length); 
    3840                result.setSequence(this.sequence); 
    3941                Random rgen = new Random(); 
    40                  
    41                 for (int i=0; i<result.sequence.length; i++) { 
    42                     int randomPosition = rgen.nextInt(result.sequence.length); 
    43                     int temp = result.sequence[i]; 
    44                     result.sequence[i] = result.sequence[randomPosition]; 
    45                     result.sequence[randomPosition] = temp; 
     42 
     43                for (int i = 0; i < result.sequence.length; i++) { 
     44                        int randomPosition = rgen.nextInt(result.sequence.length); 
     45                        int temp = result.sequence[i]; 
     46                        result.sequence[i] = result.sequence[randomPosition]; 
     47                        result.sequence[randomPosition] = temp; 
    4648                } 
    4749                return result; 
    48                  
     50 
     51        } 
     52 
     53        // TODO: This can be done faster 
     54        public int containsPattern(ArrayList<NumberSequence> pattern) { 
     55                int i = 0; 
     56                int count = 0; 
     57                int[] pat1 = pattern.get(0).getSequence(); 
     58                int[] pat2 = pattern.get(1).getSequence(); 
     59                notmatched: while (i < sequence.length - pat1.length) { 
     60                        if (sequence[i] == pat1[0] || sequence[i] == pat2[0]) { 
     61                                for (int j = 0; j < pat1.length; j++) { 
     62                                        if (sequence[i + j] != pat1[j] 
     63                                                        && sequence[i + j] != pat2[j]) { 
     64                                                continue notmatched; 
     65                                        } 
     66                                } 
     67                                count++; 
     68                        } 
     69                        i++; 
     70                } 
     71                return count; 
    4972        } 
    5073 
Note: See TracChangeset for help on using the changeset viewer.