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

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

Building distance matrix between sequences

File size: 995 bytes
RevLine 
[1554]1package de.ugoe.cs.autoquest.tasktrees.alignment.substitution;
2
3public class TriangleMatrix {
4       
[1568]5        private double[] matrix;
[1554]6        private int size;
7       
8        public TriangleMatrix(int size) {
9                this.size = size;
[1568]10                matrix = new double [size*(size+1)/2];
[1554]11        }
12       
[1568]13        public double get(int first, int second) {
[1554]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       
[1568]20        public void set(int first, int second, double value) {
[1554]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       
[1555]27       
28       
[1554]29        //Note: String just looks good for small. testing matrices
30        public String toString() {
31                String result = "";
32                for (int i = 0; i < size; i++) {
33                        for(int j = 0; j< size; j++) {
34                                if(i<j) {
[1558]35                                        result = result + String.format("%+4.1f",this.get(i,j));
[1554]36                                }
37                                else {
[1558]38                                        result = result + ("      ");
[1554]39                                }
40                        }
41                        result = result + "\n";
42                }
43                return result;
44        }
45}
Note: See TracBrowser for help on using the repository browser.