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