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