source: branches/ralph/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/substitution/TriangleMatrix.java @ 1569

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

Enhanced output of the matrix

File size: 1.1 KB
Line 
1package de.ugoe.cs.autoquest.tasktrees.alignment.substitution;
2
3public class TriangleMatrix {
4       
5        private double[] matrix;
6        private int size;
7       
8        public TriangleMatrix(int size) {
9                this.size = size;
10                matrix = new double [size*(size+1)/2];
11        }
12       
13        public double get(int first, int second) {
14                int row = Math.min(first, second);
15                int col = Math.max(first, second);
16                return matrix[row*size-(row*(row+1)/2 - (size-col))];
17               
18        }
19       
20        public void set(int first, int second, double value) {
21                int row = Math.min(first, second);
22                int col = Math.max(first, second);
23                matrix[row*size-(row*(row+1)/2 - (size-col))] = value;
24        }
25
26        public void initialize(double value) {
27                for (int i=0; i < matrix.length; i++) {
28                        matrix[i] = value;
29                }
30        }
31       
32       
33        public String toString() {
34                String result = "";
35                for (int i = 0; i < size; i++) {
36                        for(int j = 0; j< size; j++) {
37                                if(i<j) {
38                                        if(Double.isInfinite(this.get(i,j))) {
39                                                result = result + " -------";
40                                        }
41                                        else {
42                                                result = result + String.format("%+8.2f",this.get(i,j));
43                                        }
44                                }
45                                else {
46                                        result = result + ("        ");
47                                }
48                        }
49                        result = result + "\n";
50                }
51                return result;
52        }
53}
Note: See TracBrowser for help on using the repository browser.