Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java @ 5334:b296d435fc69
Doc and whitespace fixes.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 19 Mar 2013 10:25:23 +0100 |
parents | 14db045d6368 |
children | f4fd64a4d502 |
rev | line source |
---|---|
625
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.io.Serializable; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import java.util.List; |
2611
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
6 import java.util.ArrayList; |
625
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
8 import org.apache.log4j.Logger; |
625
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 public class QRangeTree |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 implements Serializable |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 { |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
13 private static Logger log = Logger.getLogger(QRangeTree.class); |
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
14 |
2611
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
15 public static final double EPSILON = 1e-4; |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
16 |
625
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 public static class Node |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 implements Serializable |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 Node left; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 Node right; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 Node prev; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 Node next; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 double a; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 double b; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 double q; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 public Node() { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 public Node(double a, double b, double q) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 this.a = a; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 this.b = b; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 this.q = q; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 protected final double interpolatePrev(double pos) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 /* |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 f(prev.b) = prev.q |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 f(a) = q |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 prev.q = m*prev.b + n |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 q = m*a + n <=> n = q - m*a |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 q - prev.q = m*(a - prev.b) |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 m = (q - prev.q)/(a - prev.b) # a != prev.b |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 */ |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 if (a == prev.b) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 return 0.5*(q + prev.q); |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 double m = (q - prev.q)/(a - prev.b); |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 double n = q - m*a; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 return m*pos + n; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 protected final double interpolateNext(double pos) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 /* |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 f(next.a) = next.q |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 f(b) = q |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 next.q = m*next.a + n |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 q = m*b + n <=> n = q - m*b |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 q - next.q = m*(b - next.a) |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 m = (q - next.q)/(b - next.a) # b != next.a |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 */ |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 if (b == next.a) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 return 0.5*(q + next.q); |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 double m = (q - next.q)/(b - next.a); |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 double n = q - m*b; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 return m*pos + n; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 public double findQ(double pos) { |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
80 |
625
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 Node current = this; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 for (;;) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 if (pos < current.a) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 if (current.left != null) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 current = current.left; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 continue; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 } |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
88 return current.prev != null |
625
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 ? current.interpolatePrev(pos) |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 : Double.NaN; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 if (pos > current.b) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 if (current.right != null) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 current = current.right; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 continue; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 } |
633
d08f77e7f7e8
WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
632
diff
changeset
|
97 return current.next != null |
625
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 ? current.interpolateNext(pos) |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 : Double.NaN; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 return current.q; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 } |
4797
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
104 |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
105 public Node findNode(double pos) { |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
106 Node current = this; |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
107 while (current != null) { |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
108 if (pos < current.a) { |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
109 current = current.left; |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
110 } |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
111 else if (pos > current.b) { |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
112 current = current.right; |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
113 } |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
114 return current; |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
115 } |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
116 return null; |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
117 } |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
118 |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
119 public boolean contains(double c) { |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
120 return c >= a && c <= b; |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
121 } |
625
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 } // class Node |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 |
4797
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
124 /** Class to cache the last found tree leaf in a search for Q. |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
125 * Its likely that a neighbored pos search |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
126 * results in using the same leaf node. So |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
127 * caching this leaf will minimize expensive |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
128 * tree traversals. |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
129 * Modeled as inner class because the QRangeTree |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
130 * itself is a shared data structure. |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
131 * Using this class omits interpolation between |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
132 * leaves. |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
133 */ |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
134 public final class QuickQFinder { |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
135 |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
136 private Node last; |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
137 |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
138 public QuickQFinder() { |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
139 } |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
140 |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
141 public double findQ(double pos) { |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
142 if (last != null && last.contains(pos)) { |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
143 return last.q; |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
144 } |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
145 last = QRangeTree.this.findNode(pos); |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
146 return last != null ? last.q : Double.NaN; |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
147 } |
4821
bcf25d8c183e
Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4797
diff
changeset
|
148 |
bcf25d8c183e
Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4797
diff
changeset
|
149 public double [] findQs(double [] kms, Calculation report) { |
bcf25d8c183e
Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4797
diff
changeset
|
150 return findQs(kms, new double[kms.length], report); |
bcf25d8c183e
Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4797
diff
changeset
|
151 } |
bcf25d8c183e
Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4797
diff
changeset
|
152 |
bcf25d8c183e
Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4797
diff
changeset
|
153 public double [] findQs( |
5282
14db045d6368
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4821
diff
changeset
|
154 double [] kms, |
14db045d6368
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4821
diff
changeset
|
155 double [] qs, |
4821
bcf25d8c183e
Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4797
diff
changeset
|
156 Calculation report |
bcf25d8c183e
Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4797
diff
changeset
|
157 ) { |
bcf25d8c183e
Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4797
diff
changeset
|
158 for (int i = 0; i < kms.length; ++i) { |
bcf25d8c183e
Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4797
diff
changeset
|
159 if (Double.isNaN(qs[i] = findQ(kms[i]))) { |
bcf25d8c183e
Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4797
diff
changeset
|
160 report.addProblem(kms[i], "cannot.find.q"); |
bcf25d8c183e
Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4797
diff
changeset
|
161 } |
bcf25d8c183e
Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4797
diff
changeset
|
162 } |
bcf25d8c183e
Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4797
diff
changeset
|
163 return qs; |
bcf25d8c183e
Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4797
diff
changeset
|
164 } |
4797
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
165 } // class QuickQFinder |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
166 |
625
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 protected Node root; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 public QRangeTree() { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 |
2609
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
172 public static final class AccessQAB { |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
173 private int startIndex; |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
174 |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
175 public AccessQAB(int startIndex) { |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
176 this.startIndex = startIndex; |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
177 } |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
178 |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
179 public Double getQ(Object [] row) { |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
180 return (Double)row[startIndex]; |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
181 } |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
182 |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
183 public Double getA(Object [] row) { |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
184 return (Double)row[startIndex+1]; |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
185 } |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
186 |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
187 public Double getB(Object [] row) { |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
188 return (Double)row[startIndex+2]; |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
189 } |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
190 } |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
191 |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
192 public static final AccessQAB WITH_COLUMN = new AccessQAB(1); |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
193 public static final AccessQAB WITHOUT_COLUMN = new AccessQAB(0); |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
194 |
632
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
195 /** wstQRanges need to be sorted by range.a */ |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
196 public QRangeTree(List<Object []> qRanges, int start, int stop) { |
2609
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
197 this(qRanges, WITH_COLUMN, start, stop); |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
198 } |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
199 |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
200 public QRangeTree( |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
201 List<Object []> qRanges, |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2792
diff
changeset
|
202 AccessQAB accessQAB, |
2609
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
203 int start, |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
204 int stop |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
205 ) { |
632
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
206 if (stop <= start) { |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
207 return; |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
208 } |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
209 |
2611
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
210 int N = stop-start; |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
211 |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
212 List<Node> nodes = new ArrayList<Node>(N); |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
213 |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
214 Node last = null; |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
215 |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
216 for (int i = 0; i < N; ++i) { |
1890
9144e5a5027b
(Picky) cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1020
diff
changeset
|
217 Object [] qRange = qRanges.get(start + i); |
2609
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
218 Double q = accessQAB.getQ(qRange); |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
219 Double a = accessQAB.getA(qRange); |
ed550e325248
Little optimization when fetching q ranges for single columns of wsts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1890
diff
changeset
|
220 Double b = accessQAB.getB(qRange); |
632
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
221 |
2611
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
222 double av = a != null ? a.doubleValue() : -Double.MAX_VALUE; |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
223 double bv = b != null ? b.doubleValue() : Double.MAX_VALUE; |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
224 double qv = q.doubleValue(); |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
225 |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
226 // If nodes are directly neighbored and Qs are the same |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
227 // join them. |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
228 if (last != null |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
229 && Math.abs(last.b - av) < EPSILON |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
230 && Math.abs(last.q - qv) < EPSILON) { |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
231 last.b = bv; |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
232 } |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
233 else { |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
234 nodes.add(last = new Node(av, bv, qv)); |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
235 } |
632
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
236 } |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
237 |
2612
49cfa5c66651
Squashed performance bug introduced in rev4070. Now CSV export is about 245 times faster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2611
diff
changeset
|
238 if (log.isDebugEnabled()) { |
49cfa5c66651
Squashed performance bug introduced in rev4070. Now CSV export is about 245 times faster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2611
diff
changeset
|
239 log.debug("Before/after nodes join: " + |
49cfa5c66651
Squashed performance bug introduced in rev4070. Now CSV export is about 245 times faster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2611
diff
changeset
|
240 N + "/" + nodes.size()); |
49cfa5c66651
Squashed performance bug introduced in rev4070. Now CSV export is about 245 times faster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2611
diff
changeset
|
241 } |
49cfa5c66651
Squashed performance bug introduced in rev4070. Now CSV export is about 245 times faster.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2611
diff
changeset
|
242 |
632
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
243 root = wireTree(nodes); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
244 } |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
245 |
2611
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
246 protected static Node wireTree(List<Node> nodes) { |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
247 int N = nodes.size(); |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
248 for (int i = 0; i < N; ++i) { |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
249 Node node = nodes.get(i); |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
250 if (i > 0 ) node.prev = nodes.get(i-1); |
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
251 if (i < N-1) node.next = nodes.get(i+1); |
625
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
252 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 |
2611
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
254 return buildTree(nodes, 0, N-1); |
625
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
255 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
256 |
2611
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
257 protected static Node buildTree(List<Node> nodes, int lo, int hi) { |
632
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
258 |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
259 if (lo > hi) { |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
260 return null; |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
261 } |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
262 |
625
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
263 int mid = (lo + hi) >> 1; |
2611
62e5c6fd2a0c
Join nodes in Q tree if they span a continuous interval and have same Qs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2609
diff
changeset
|
264 Node parent = nodes.get(mid); |
625
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
265 |
632
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
266 parent.left = buildTree(nodes, lo, mid-1); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
267 parent.right = buildTree(nodes, mid+1, hi); |
625
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
268 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
269 return parent; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
270 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
271 |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
272 public double findQ(double pos) { |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
273 return root != null ? root.findQ(pos) : Double.NaN; |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
274 } |
632
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
275 |
4797
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
276 public Node findNode(double pos) { |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
277 return root != null ? root.findNode(pos) : null; |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
278 } |
43e69af28b3c
A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4796
diff
changeset
|
279 |
3743
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
280 protected Node head() { |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
281 Node head = root; |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
282 while (head.left != null) { |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
283 head = head.left; |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
284 } |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
285 return head; |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
286 } |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
287 |
4796
729a5edb0313
Added intersectsQRange to QRangeTree to check if a given Q range intersects the Qs of the tree. Useful for 'Umhuellende'. TODO make check depend on km range.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3743
diff
changeset
|
288 public boolean intersectsQRange(double qMin, double qMax) { |
729a5edb0313
Added intersectsQRange to QRangeTree to check if a given Q range intersects the Qs of the tree. Useful for 'Umhuellende'. TODO make check depend on km range.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3743
diff
changeset
|
289 if (qMin > qMax) { |
729a5edb0313
Added intersectsQRange to QRangeTree to check if a given Q range intersects the Qs of the tree. Useful for 'Umhuellende'. TODO make check depend on km range.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3743
diff
changeset
|
290 double t = qMin; |
729a5edb0313
Added intersectsQRange to QRangeTree to check if a given Q range intersects the Qs of the tree. Useful for 'Umhuellende'. TODO make check depend on km range.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3743
diff
changeset
|
291 qMin = qMax; |
729a5edb0313
Added intersectsQRange to QRangeTree to check if a given Q range intersects the Qs of the tree. Useful for 'Umhuellende'. TODO make check depend on km range.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3743
diff
changeset
|
292 qMax = t; |
729a5edb0313
Added intersectsQRange to QRangeTree to check if a given Q range intersects the Qs of the tree. Useful for 'Umhuellende'. TODO make check depend on km range.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3743
diff
changeset
|
293 } |
729a5edb0313
Added intersectsQRange to QRangeTree to check if a given Q range intersects the Qs of the tree. Useful for 'Umhuellende'. TODO make check depend on km range.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3743
diff
changeset
|
294 for (Node curr = head(); curr != null; curr = curr.next) { |
729a5edb0313
Added intersectsQRange to QRangeTree to check if a given Q range intersects the Qs of the tree. Useful for 'Umhuellende'. TODO make check depend on km range.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3743
diff
changeset
|
295 if (curr.q >= qMin || curr.q <= qMax) { |
729a5edb0313
Added intersectsQRange to QRangeTree to check if a given Q range intersects the Qs of the tree. Useful for 'Umhuellende'. TODO make check depend on km range.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3743
diff
changeset
|
296 return true; |
729a5edb0313
Added intersectsQRange to QRangeTree to check if a given Q range intersects the Qs of the tree. Useful for 'Umhuellende'. TODO make check depend on km range.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3743
diff
changeset
|
297 } |
729a5edb0313
Added intersectsQRange to QRangeTree to check if a given Q range intersects the Qs of the tree. Useful for 'Umhuellende'. TODO make check depend on km range.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3743
diff
changeset
|
298 } |
729a5edb0313
Added intersectsQRange to QRangeTree to check if a given Q range intersects the Qs of the tree. Useful for 'Umhuellende'. TODO make check depend on km range.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3743
diff
changeset
|
299 return false; |
729a5edb0313
Added intersectsQRange to QRangeTree to check if a given Q range intersects the Qs of the tree. Useful for 'Umhuellende'. TODO make check depend on km range.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3743
diff
changeset
|
300 } |
729a5edb0313
Added intersectsQRange to QRangeTree to check if a given Q range intersects the Qs of the tree. Useful for 'Umhuellende'. TODO make check depend on km range.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3743
diff
changeset
|
301 |
3743
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
302 public List<Range> findSegments(double a, double b) { |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
303 if (a > b) { double t = a; a = b; b = t; } |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
304 return findSegments(new Range(a, b)); |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
305 } |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
306 |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
307 public List<Range> findSegments(Range range) { |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
308 List<Range> segments = new ArrayList<Range>(); |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
309 |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
310 // Linear scan should be good enough here. |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
311 for (Node curr = head(); curr != null; curr = curr.next) { |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
312 if (!range.disjoint(curr.a, curr.b)) { |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
313 Range r = new Range(curr.a, curr.b); |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
314 if (r.clip(range)) { |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
315 segments.add(r); |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
316 } |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
317 } |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
318 } |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
319 |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
320 return segments; |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
321 } |
51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3076
diff
changeset
|
322 |
2792
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
323 @Override |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
324 public String toString() { |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
325 StringBuilder sb = new StringBuilder(); |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
326 inorder(root, sb); |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
327 return sb.toString(); |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
328 } |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
329 |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
330 protected static void inorder(Node node, StringBuilder sb) { |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
331 if (node != null) { |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
332 inorder(node.left, sb); |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
333 sb.append('[') |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
334 .append(node.a) |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
335 .append(", ") |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
336 .append(node.b) |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
337 .append(": ") |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
338 .append(node.q) |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
339 .append(']'); |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
340 inorder(node.right, sb); |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
341 } |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
342 } |
fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2612
diff
changeset
|
343 |
632
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
344 private static final String name(Object o) { |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
345 return String.valueOf(System.identityHashCode(o) & 0xffffffffL); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
346 } |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
347 |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
348 public String toGraph() { |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
349 StringBuilder sb = new StringBuilder(); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
350 sb.append("subgraph c"); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
351 sb.append(name(this)); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
352 sb.append(" {\n"); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
353 if (root != null) { |
1020
a776afdf1ec5
Cosmetic: Replaced usage of legacy java.util.Stack with java.util.Deque.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
354 java.util.Deque<Node> stack = new java.util.ArrayDeque<Node>(); |
632
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
355 stack.push(root); |
1020
a776afdf1ec5
Cosmetic: Replaced usage of legacy java.util.Stack with java.util.Deque.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
633
diff
changeset
|
356 while (!stack.isEmpty()) { |
632
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
357 Node current = stack.pop(); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
358 String name = "n" + name(current); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
359 sb.append(name); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
360 sb.append(" [label=\""); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
361 sb.append(current.a).append(", ").append(current.b); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
362 sb.append(": ").append(current.q).append("\"]\n"); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
363 if (current.left != null) { |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
364 String leftName = name(current.left); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
365 sb.append(name).append(" -- n").append(leftName).append("\n"); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
366 stack.push(current.left); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
367 } |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
368 if (current.right != null) { |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
369 String rightName = name(current.right); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
370 sb.append(name).append(" -- n").append(rightName).append("\n"); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
371 stack.push(current.right); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
372 } |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
373 } |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
374 } |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
375 sb.append("}\n"); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
376 return sb.toString(); |
07640ab913fd
First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
625
diff
changeset
|
377 } |
625
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
378 } |
c0c60a611fca
Introduce model to store q values of WST columns efficiently.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
379 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |