source: branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/StaticTriangleMatrix.java @ 1703

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

Adding static version of triangle matrix

File size: 1.4 KB
Line 
1package de.ugoe.cs.autoquest.tasktrees.alignment.matrix;
2
3public class StaticTriangleMatrix implements ITriangleMatrix {
4       
5        private float[] matrix;
6        protected int size;
7       
8       
9        public StaticTriangleMatrix(int size) {
10                this.size = size;
11                matrix = new float [size*(size+1)/2];
12        }
13       
14        public float get(int first, int second) {
15                int row = Math.min(first, second);
16                int col = Math.max(first, second);
17                return matrix[row*size-(row*(row+1)/2 - (size-col))];
18               
19        }
20       
21        public void set(int first, int second, float value) {
22                int row = Math.min(first, second);
23                int col = Math.max(first, second);
24                matrix[row*size-(row*(row+1)/2 - (size-col))] = value;
25        }
26
27        public void initialize(float value) {
28                for (int i=0; i < matrix.length; i++) {
29                        matrix[i] = value;
30                }
31        }
32       
33
34       
35        public String toString() {
36                String result = "";
37                for (int i = 0; i < size; i++) {
38                        for(int j = 0; j< size; j++) {
39                                if(i<j) {
40                                        if(Float.isInfinite(this.get(i,j))) {
41                                                result = result + " -------";
42                                        }
43                                        else {
44                                                result = result + String.format("%+8.2f",this.get(i,j));
45                                        }
46                                }
47                                else {
48                                        result = result + ("        ");
49                                }
50                        }
51                        result = result + "\n";
52                }
53                return result;
54        }
55
56        @Override
57        public void increaseSize(int count) throws Exception {
58                throw new Exception("Cannot call this function on this implementation of ITriangle Matrix");
59               
60        }
61
62        @Override
63        public int size() {
64                return size;
65        }
66}
Note: See TracBrowser for help on using the repository browser.