Last change
on this file since 1554 was
1554,
checked in by rkrimmel, 10 years ago
|
Moved alignment plugin into core-tasktrees
|
File size:
968 bytes
|
Rev | Line | |
---|
[1554] | 1 | package de.ugoe.cs.autoquest.tasktrees.alignment.substitution; |
---|
| 2 | |
---|
| 3 | public class TriangleMatrix { |
---|
| 4 | |
---|
| 5 | private float[] matrix; |
---|
| 6 | private int size; |
---|
| 7 | |
---|
| 8 | public TriangleMatrix(int size) { |
---|
| 9 | this.size = size; |
---|
| 10 | matrix = new float[size*(size+1)/2]; |
---|
| 11 | } |
---|
| 12 | |
---|
| 13 | public float 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, float 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 | |
---|
| 27 | //Note: String just looks good for small. testing matrices |
---|
| 28 | public String toString() { |
---|
| 29 | String result = ""; |
---|
| 30 | for (int i = 0; i < size; i++) { |
---|
| 31 | for(int j = 0; j< size; j++) { |
---|
| 32 | if(i<j) { |
---|
| 33 | result = result + (this.get(i,j) + " "); |
---|
| 34 | } |
---|
| 35 | else { |
---|
| 36 | result = result + (" "); |
---|
| 37 | } |
---|
| 38 | } |
---|
| 39 | result = result + "\n"; |
---|
| 40 | } |
---|
| 41 | return result; |
---|
| 42 | } |
---|
| 43 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.