Last change
on this file since 1583 was
1572,
checked in by rkrimmel, 10 years ago
|
Added parts of the PAL library, implemented UPGMA Algoritm for Feng Doolittle guide tree
|
File size:
1.1 KB
|
Rev | Line | |
---|
[1572] | 1 | package de.ugoe.cs.autoquest.tasktrees.alignment.matrix; |
---|
[1554] | 2 | |
---|
| 3 | public class TriangleMatrix { |
---|
| 4 | |
---|
[1568] | 5 | private double[] matrix; |
---|
[1572] | 6 | protected int size; |
---|
[1554] | 7 | |
---|
[1570] | 8 | |
---|
| 9 | |
---|
[1554] | 10 | public TriangleMatrix(int size) { |
---|
| 11 | this.size = size; |
---|
[1568] | 12 | matrix = new double [size*(size+1)/2]; |
---|
[1554] | 13 | } |
---|
| 14 | |
---|
[1568] | 15 | public double get(int first, int second) { |
---|
[1554] | 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 | |
---|
[1568] | 22 | public void set(int first, int second, double value) { |
---|
[1554] | 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 | |
---|
[1569] | 28 | public void initialize(double value) { |
---|
| 29 | for (int i=0; i < matrix.length; i++) { |
---|
| 30 | matrix[i] = value; |
---|
| 31 | } |
---|
| 32 | } |
---|
[1554] | 33 | |
---|
[1555] | 34 | |
---|
[1554] | 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) { |
---|
[1569] | 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 | } |
---|
[1554] | 46 | } |
---|
| 47 | else { |
---|
[1569] | 48 | result = result + (" "); |
---|
[1554] | 49 | } |
---|
| 50 | } |
---|
| 51 | result = result + "\n"; |
---|
| 52 | } |
---|
| 53 | return result; |
---|
| 54 | } |
---|
| 55 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.