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

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

Adding FitchMargaliash? Class

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       
9       
10        public TriangleMatrix(int size) {
11                this.size = size;
12                matrix = new double [size*(size+1)/2];
13        }
14       
15        public double get(int first, int second) {
16                int row = Math.min(first, second);
17                int col = Math.max(first, second);
18                return matrix[row*size-(row*(row+1)/2 - (size-col))];
19               
20        }
21       
22        public void set(int first, int second, double value) {
23                int row = Math.min(first, second);
24                int col = Math.max(first, second);
25                matrix[row*size-(row*(row+1)/2 - (size-col))] = value;
26        }
27
28        public void initialize(double value) {
29                for (int i=0; i < matrix.length; i++) {
30                        matrix[i] = value;
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(Double.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}
Note: See TracBrowser for help on using the repository browser.