annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java @ 1078:048517d67215

Changed state spawning mechanism of MainValuesArtifact. flys-artifacts/trunk@2575 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 25 Aug 2011 10:38:45 +0000
parents 821aaceb2776
children 03fbf1b30e72
rev   line source
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model;
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import gnu.trove.TDoubleArrayList;
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4
744
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
5 import java.util.Random;
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
6
1033
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
7 import org.apache.log4j.Logger;
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
8
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 public class WQ
925
0cb1a70b8b92 Added the math needed to calculate "W-Differenzen" in "Laengsschnitten"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 748
diff changeset
10 extends NamedObjectImpl
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 {
1033
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
12 private static Logger logger = Logger.getLogger(WQ.class);
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
13
925
0cb1a70b8b92 Added the math needed to calculate "W-Differenzen" in "Laengsschnitten"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 748
diff changeset
14 // TODO: s/w/ws/g
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 protected TDoubleArrayList w;
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
925
0cb1a70b8b92 Added the math needed to calculate "W-Differenzen" in "Laengsschnitten"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 748
diff changeset
17 // TODO: s/q/qs/g
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 protected TDoubleArrayList q;
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 public WQ() {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 this("");
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 public WQ(String name) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 w = new TDoubleArrayList();
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 q = new TDoubleArrayList();
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 public WQ(int capacity) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 this(capacity, "");
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 public WQ(int capacity, String name) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 super(name);
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 w = new TDoubleArrayList(capacity);
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 q = new TDoubleArrayList(capacity);
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 public WQ(double [] qs, double [] ws) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 this(qs, ws, "");
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 public WQ(double [] qs, double [] ws, String name) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 super(name);
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 w = new TDoubleArrayList(ws);
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 q = new TDoubleArrayList(qs);
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 public void add(double w, double q) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 this.w.add(w);
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 this.q.add(q);
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 public int size() {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 return w.size();
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 public double getW(int idx) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 return w.getQuick(idx);
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 public double getQ(int idx) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 return q.getQuick(idx);
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 public double [] get(int idx) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 return get(idx, new double [2]);
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 public double [] get(int idx, double [] dst) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 dst[0] = w.getQuick(idx);
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 dst[1] = q.getQuick(idx);
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 return dst;
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 public double [] getWs() {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78 return w.toNativeArray();
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 public double [] getQs() {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 return q.toNativeArray();
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 public static void removeNaNs(TDoubleArrayList [] arrays) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 int dest = 0;
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 int A = arrays.length;
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 int N = arrays[0].size();
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 OUTER: for (int i = 0; i < N; ++i) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 for (int j = 0; j < A; ++j) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 TDoubleArrayList a = arrays[j];
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 double v = a.getQuick(i);
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 if (Double.isNaN(v)) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 continue OUTER;
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 a.setQuick(dest, v);
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 ++dest;
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 if (dest < N) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 for (int i = 0; i < A; ++i) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 arrays[i].remove(dest, N-dest);
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 public void removeNaNs() {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112 removeNaNs(new TDoubleArrayList [] { w, q });
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113 }
744
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
114
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
115 public boolean guessWaterIncreasing() {
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
116 return guessWaterIncreasing(0.05f);
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
117 }
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
118
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
119 public boolean guessWaterIncreasing(float factor) {
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
120
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
121 int N = w.size();
926
659608128823 Fix(?) for flys/issue114
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 925
diff changeset
122 if (N < 2) return false;
659608128823 Fix(?) for flys/issue114
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 925
diff changeset
123
744
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
124 int samples = (int)(factor*N) + 1;
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
125
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
126 int up = 0;
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
127
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
128 Random rand = new Random();
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
129
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
130 for (int i = 0; i < samples; ++i) {
748
30be4b71c36c WQ: Guessing increaing w is not based on direct neighbors any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 744
diff changeset
131 int pos2 = rand.nextInt(N-1) + 1;
926
659608128823 Fix(?) for flys/issue114
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 925
diff changeset
132 if (pos2 == 0) continue;
748
30be4b71c36c WQ: Guessing increaing w is not based on direct neighbors any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 744
diff changeset
133 int pos1 = rand.nextInt(pos2);
30be4b71c36c WQ: Guessing increaing w is not based on direct neighbors any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 744
diff changeset
134 double w1 = w.getQuick(pos1);
30be4b71c36c WQ: Guessing increaing w is not based on direct neighbors any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 744
diff changeset
135 double w2 = w.getQuick(pos2);
744
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
136 if (w2 > w1) ++up;
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
137 }
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
138
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
139 return up > samples/2;
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
140 }
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
141
1033
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
142 public int [] longestIncreasingWRangeIndices() {
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
143 return longestIncreasingWRangeIndices(new int[2]);
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
144 }
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
145
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
146 public int [] longestIncreasingWRangeIndices(int [] bounds) {
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
147
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
148 int N = size();
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
149 int start = 0;
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
150 int stop = 0;
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
151
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
152 double lastW = Double.MAX_VALUE;
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
153
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
154 for (int i = 0; i < N; ++i) {
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
155 double v = w.getQuick(i);
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
156 if (v <= lastW) {
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
157 if (stop-start > bounds[1]-bounds[0]) {
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
158 bounds[0] = start;
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
159 bounds[1] = stop;
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
160 if (logger.isDebugEnabled()) {
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
161 logger.debug("new range: " +
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
162 bounds[0] + " - " + bounds[1] + " (" +
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
163 w.getQuick(bounds[0]) + ", " +
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
164 w.getQuick(bounds[1]) + ")");
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
165
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
166 }
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
167 }
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
168 start = stop = i;
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
169 }
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
170 else {
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
171 stop = i;
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
172 }
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
173 lastW = v;
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
174 }
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
175
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
176 if (stop-start > bounds[1]-bounds[0]) {
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
177 bounds[0] = start;
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
178 bounds[1] = stop;
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
179 if (logger.isDebugEnabled()) {
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
180 logger.debug("new range @end: " +
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
181 bounds[0] + " - " + bounds[1] + " (" +
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
182 w.getQuick(bounds[0]) + ", " +
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
183 w.getQuick(bounds[1]) + ")");
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
184
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
185 }
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
186 }
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
187
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
188 return bounds;
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
189 }
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
190 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
191 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org