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
97 public final void addDemand(final Terminal terminalFrom, final Terminal terminalTo, final int numberAnnual,
98 final double fraction20ft, final double fractionEmpty, final Map<Company, Double> fractionOwners)
99 {
100 DemandCell demandCell =
101 new DemandCell(terminalFrom, terminalTo, numberAnnual, fraction20ft, fractionEmpty, fractionOwners);
102 addDemand(demandCell);
103 }
104
105
106
107
108
109
110 public final DemandCell getDemand(final Terminal terminalFrom, final Terminal terminalTo)
111 {
112 if (this.demandMap.containsKey(terminalFrom))
113 {
114 return this.demandMap.get(terminalFrom).get(terminalTo);
115 }
116 return null;
117 }
118
119
120
121
122
123 public final Map<Terminal, DemandCell> getDemandMapFrom(final Terminal terminalFrom)
124 {
125 return this.demandMap.get(terminalFrom);
126 }
127
128
129
130
131
132 public final Map<Terminal, DemandCell> getDemandMapTo(final Terminal terminalTo)
133 {
134 Map<Terminal, DemandCell> toMap = new HashMap<Terminal, DemandCell>();
135 for (Terminal from : this.demandMap.keySet())
136 {
137 for (Terminal to : this.demandMap.get(from).keySet())
138 {
139 if (terminalTo.equals(to))
140 {
141 toMap.put(from, this.demandMap.get(from).get(to));
142 }
143 }
144 }
145 return toMap;
146 }
147
148
149
150
151
152 public final Set<DemandCell> getDemandSetFrom(final Terminal terminalFrom)
153 {
154 return new HashSet<DemandCell>(this.demandMap.get(terminalFrom).values());
155 }
156
157
158
159
160
161 public final Set<DemandCell> getDemandSetTo(final Terminal terminalTo)
162 {
163 Set<DemandCell> toSet = new HashSet<DemandCell>();
164 for (Terminal from : this.demandMap.keySet())
165 {
166 for (Terminal to : this.demandMap.get(from).keySet())
167 {
168 if (terminalTo.equals(to))
169 {
170 toSet.add(this.demandMap.get(from).get(to));
171 }
172 }
173 }
174 return toSet;
175 }
176
177
178
179
180 public final DEVSSimulatorInterface.TimeDoubleUnit getSimulator()
181 {
182 return this.simulator;
183 }
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201 public class DemandCell
202 {
203
204 private Terminal terminalFrom;
205
206
207 private Terminal terminalTo;
208
209
210 private int numberAnnual;
211
212
213 private double fraction20ft;
214
215
216 private double fractionEmpty;
217
218
219 private Map<Company, Double> fractionOwners = new HashMap<Company, Double>();
220
221
222
223
224
225
226
227
228
229
230 public DemandCell(final Terminal terminalFrom, final Terminal terminalTo, final int numberAnnual,
231 final double fraction20ft, final double fractionEmpty, final Map<Company, Double> fractionOwners)
232 {
233 super();
234 this.terminalFrom = terminalFrom;
235 this.terminalTo = terminalTo;
236 this.numberAnnual = numberAnnual;
237 this.fraction20ft = fraction20ft;
238 this.fractionEmpty = fractionEmpty;
239 this.fractionOwners = fractionOwners;
240 }
241
242
243
244
245 public final Terminal getTerminalFrom()
246 {
247 return this.terminalFrom;
248 }
249
250
251
252
253 public final Terminal getTerminalTo()
254 {
255 return this.terminalTo;
256 }
257
258
259
260
261 public final int getNumberAnnual()
262 {
263 return this.numberAnnual;
264 }
265
266
267
268
269 public final double getFraction20ft()
270 {
271 return this.fraction20ft;
272 }
273
274
275
276
277 public final double getFractionEmpty()
278 {
279 return this.fractionEmpty;
280 }
281
282
283
284
285 public final Map<Company, Double> getFractionOwners()
286 {
287 return this.fractionOwners;
288 }
289
290 }
291
292 }