1
2
3
4 package org.opentrafficsim.water.demand;
5
6 import java.io.Serializable;
7 import java.util.HashMap;
8 import java.util.HashSet;
9 import java.util.Map;
10 import java.util.Set;
11
12 import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
13 import org.opentrafficsim.water.role.Company;
14 import org.opentrafficsim.water.transfer.Terminal;
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 public class TransportDemand implements Serializable
32 {
33
34 private static final long serialVersionUID = 1L;
35
36
37 private OTSDEVSSimulatorInterface simulator;
38
39
40 private Region operatingArea;
41
42
43 private Map<Terminal, Map<Terminal, DemandCell>> demandMap = new HashMap<Terminal, Map<Terminal, DemandCell>>();
44
45
46
47
48
49 public TransportDemand(final OTSDEVSSimulatorInterface simulator, final Region operatingArea)
50 {
51 this.simulator = simulator;
52 this.operatingArea = operatingArea;
53 }
54
55
56
57
58 public final Region getOperatingArea()
59 {
60 return this.operatingArea;
61 }
62
63
64
65
66 public final Map<Terminal, Map<Terminal, DemandCell>> getDemandMap()
67 {
68 return this.demandMap;
69 }
70
71
72
73
74
75 public final void addDemand(final DemandCell demandCell)
76 {
77 Map<Terminal, DemandCell> partMap = this.demandMap.get(demandCell.getTerminalFrom());
78 if (partMap == null)
79 {
80 partMap = new HashMap<Terminal, DemandCell>();
81 this.demandMap.put(demandCell.getTerminalFrom(), partMap);
82 }
83 partMap.put(demandCell.getTerminalTo(), demandCell);
84 }
85
86
87
88
89
90
91
92
93
94
95 public final void addDemand(final Terminal terminalFrom, final Terminal terminalTo, final int numberAnnual,
96 final double fraction20ft, final double fractionEmpty, final Map<Company, Double> fractionOwners)
97 {
98 DemandCell demandCell =
99 new DemandCell(terminalFrom, terminalTo, numberAnnual, fraction20ft, fractionEmpty, fractionOwners);
100 addDemand(demandCell);
101 }
102
103
104
105
106
107
108 public final DemandCell getDemand(final Terminal terminalFrom, final Terminal terminalTo)
109 {
110 if (this.demandMap.containsKey(terminalFrom))
111 {
112 return this.demandMap.get(terminalFrom).get(terminalTo);
113 }
114 return null;
115 }
116
117
118
119
120
121 public final Map<Terminal, DemandCell> getDemandMapFrom(final Terminal terminalFrom)
122 {
123 return this.demandMap.get(terminalFrom);
124 }
125
126
127
128
129
130 public final Map<Terminal, DemandCell> getDemandMapTo(final Terminal terminalTo)
131 {
132 Map<Terminal, DemandCell> toMap = new HashMap<Terminal, DemandCell>();
133 for (Terminal from : this.demandMap.keySet())
134 {
135 for (Terminal to : this.demandMap.get(from).keySet())
136 {
137 if (terminalTo.equals(to))
138 {
139 toMap.put(from, this.demandMap.get(from).get(to));
140 }
141 }
142 }
143 return toMap;
144 }
145
146
147
148
149
150 public final Set<DemandCell> getDemandSetFrom(final Terminal terminalFrom)
151 {
152 return new HashSet<DemandCell>(this.demandMap.get(terminalFrom).values());
153 }
154
155
156
157
158
159 public final Set<DemandCell> getDemandSetTo(final Terminal terminalTo)
160 {
161 Set<DemandCell> toSet = new HashSet<DemandCell>();
162 for (Terminal from : this.demandMap.keySet())
163 {
164 for (Terminal to : this.demandMap.get(from).keySet())
165 {
166 if (terminalTo.equals(to))
167 {
168 toSet.add(this.demandMap.get(from).get(to));
169 }
170 }
171 }
172 return toSet;
173 }
174
175
176
177
178 public final OTSDEVSSimulatorInterface getSimulator()
179 {
180 return this.simulator;
181 }
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199 public class DemandCell
200 {
201
202 private Terminal terminalFrom;
203
204
205 private Terminal terminalTo;
206
207
208 private int numberAnnual;
209
210
211 private double fraction20ft;
212
213
214 private double fractionEmpty;
215
216
217 private Map<Company, Double> fractionOwners = new HashMap<Company, Double>();
218
219
220
221
222
223
224
225
226
227 public DemandCell(final Terminal terminalFrom, final Terminal terminalTo, final int numberAnnual,
228 final double fraction20ft, final double fractionEmpty, final Map<Company, Double> fractionOwners)
229 {
230 super();
231 this.terminalFrom = terminalFrom;
232 this.terminalTo = terminalTo;
233 this.numberAnnual = numberAnnual;
234 this.fraction20ft = fraction20ft;
235 this.fractionEmpty = fractionEmpty;
236 this.fractionOwners = fractionOwners;
237 }
238
239
240
241
242 public final Terminal getTerminalFrom()
243 {
244 return this.terminalFrom;
245 }
246
247
248
249
250 public final Terminal getTerminalTo()
251 {
252 return this.terminalTo;
253 }
254
255
256
257
258 public final int getNumberAnnual()
259 {
260 return this.numberAnnual;
261 }
262
263
264
265
266 public final double getFraction20ft()
267 {
268 return this.fraction20ft;
269 }
270
271
272
273
274 public final double getFractionEmpty()
275 {
276 return this.fractionEmpty;
277 }
278
279
280
281
282 public final Map<Company, Double> getFractionOwners()
283 {
284 return this.fractionOwners;
285 }
286
287 }
288
289 }