source: branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/algorithms/NumberSequence.java @ 1618

Last change on this file since 1618 was 1618, checked in by rkrimmel, 10 years ago

Startet implementing signigicant match detection

File size: 1.7 KB
Line 
1package de.ugoe.cs.autoquest.tasktrees.alignment.algorithms;
2
3import java.util.ArrayList;
4import java.util.Random;
5
6public class NumberSequence {
7        private int[] sequence;
8        private int signature;
9
10        public NumberSequence(int size) {
11
12                sequence = new int[size];
13        }
14
15        public int[] getSequence() {
16                return sequence;
17        }
18
19        public void setSequence(int[] sequence) {
20                this.sequence = sequence;
21        }
22
23        public int getSignature() {
24                return signature;
25        }
26
27        public void setSignature(int signature) {
28                this.signature = signature;
29        }
30
31        public void printSequence() {
32                for (int i = 0; i < sequence.length; i++) {
33                        System.out.format("%5d", sequence[i]);
34                }
35                System.out.println();
36        }
37
38        public NumberSequence shuffle() {
39                NumberSequence result = new NumberSequence(sequence.length);
40                result.setSequence(this.sequence);
41                Random rgen = new Random();
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;
48                }
49                return result;
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;
72        }
73
74        public int size() {
75                return sequence.length;
76        }
77}
Note: See TracBrowser for help on using the repository browser.