annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/InfoldingColumns.java @ 5334:b296d435fc69

Doc and whitespace fixes.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 19 Mar 2013 10:25:23 +0100
parents 243f1eb02b95
children
rev   line source
4800
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model;
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
2
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
3 /** A pretty naive pointwise algorithm to find out the columns
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
4 * of a WSTValueTable which imfold ("umhuellen") a set of WQKMs
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
5 * in terms of Q.
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
6 * A better implemention would exploit the fact that the
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
7 * Qs normally are constant for a while along km. This would
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
8 * reduce the runtime complexity to only a few Q spans instead
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
9 * of the pointwise evaluation.
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
10 */
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
11 public class InfoldingColumns
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
12 {
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
13 private QRangeTree.QuickQFinder [] qFinders;
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
14
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
15 private boolean [] infoldingColumns;
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
16
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
17 public InfoldingColumns() {
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
18 }
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
19
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
20 public InfoldingColumns(WstValueTable.Column [] columns) {
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
21
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
22 qFinders = new QRangeTree.QuickQFinder[columns.length];
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
23 for (int i = 0; i < qFinders.length; ++i) {
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
24 qFinders[i] = columns[i].getQRangeTree().new QuickQFinder();
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
25 }
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
26
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
27 infoldingColumns = new boolean[columns.length];
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
28 }
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
29
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
30 public boolean [] getInfoldingColumns() {
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
31 return infoldingColumns;
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
32 }
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
33
4819
243f1eb02b95 Use QKMs in calculation of the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4800
diff changeset
34 public void markInfoldingColumns(QKms [] qkms) {
243f1eb02b95 Use QKMs in calculation of the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4800
diff changeset
35 for (QKms qk: qkms) {
243f1eb02b95 Use QKMs in calculation of the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4800
diff changeset
36 markInfoldingColumns(qk);
4800
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
37 }
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
38 }
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
39
4819
243f1eb02b95 Use QKMs in calculation of the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4800
diff changeset
40 public void markInfoldingColumns(QKms qkms) {
243f1eb02b95 Use QKMs in calculation of the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4800
diff changeset
41 int N = qkms.size();
4800
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
42 int C = qFinders.length-1;
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
43 for (int i = 0; i < N; ++i) {
4819
243f1eb02b95 Use QKMs in calculation of the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4800
diff changeset
44 double km = qkms.getKm(i);
243f1eb02b95 Use QKMs in calculation of the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4800
diff changeset
45 double q = qkms.getQ(i);
4800
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
46 double above = Double.MAX_VALUE;
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
47 double below = -Double.MAX_VALUE;
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
48 int aboveIdx = -1;
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
49 int belowIdx = -1;
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
50
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
51 for (int j = C; j >= 0; --j) {
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
52 double qc = qFinders[j].findQ(km);
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
53 if (Double.isNaN(qc)) {
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
54 continue;
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
55 }
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
56 if (qc <= q) {
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
57 if (qc > below) {
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
58 below = qc;
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
59 belowIdx = j;
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
60 }
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
61 }
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
62 else if (qc < above) { // qc > q
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
63 above = qc;
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
64 aboveIdx = j;
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
65 }
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
66 }
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
67
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
68 if (aboveIdx != -1) {
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
69 infoldingColumns[aboveIdx] = true;
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
70 }
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
71
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
72 if (belowIdx != -1) {
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
73 infoldingColumns[belowIdx] = true;
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
74 }
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
75 }
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
76 }
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
77 }
c6814695c82c Added missing InfoldingColumns.java
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
78 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org