1
2
3
4 package org.opentrafficsim.water.demand;
5
6 import java.io.Serializable;
7
8 import org.djunits.value.vdouble.scalar.Time;
9 import org.opentrafficsim.water.role.Company;
10 import org.opentrafficsim.water.role.ShippingLine;
11 import org.opentrafficsim.water.statistics.ContainerTransportCO2BreakdownEnum;
12 import org.opentrafficsim.water.statistics.ContainerTransportCostBreakdownEnum;
13 import org.opentrafficsim.water.statistics.ContainerTransportFeeBreakdownEnum;
14 import org.opentrafficsim.water.statistics.ContainerTransportTimeBreakdownEnum;
15 import org.opentrafficsim.water.statistics.FullEmptyEnum;
16 import org.opentrafficsim.water.transfer.Terminal;
17
18 import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 public class Container implements Serializable
37 {
38
39 private static final long serialVersionUID = 1L;
40
41
42 private final DEVSSimulatorInterface.TimeDoubleUnit simulator;
43
44
45 private Terminal terminalFrom;
46
47
48 private Terminal terminalTo;
49
50
51 private Terminal terminalLastStacked;
52
53
54 private boolean empty;
55
56
57 private ShippingLine shippingLine;
58
59
60 private Time creationTime;
61
62
63 private Time stackArrivalTime;
64
65
66 private Time onShipTime;
67
68
69 private float[] transportCosts = new float[ContainerTransportCostBreakdownEnum.values().length];
70
71
72 private float[] transportFee = new float[ContainerTransportFeeBreakdownEnum.values().length];
73
74
75 private float[] transportKgCO2 = new float[ContainerTransportCO2BreakdownEnum.values().length];
76
77
78 private float[] transportTime = new float[ContainerTransportTimeBreakdownEnum.values().length];
79
80
81
82
83
84
85
86
87 public Container(final DEVSSimulatorInterface.TimeDoubleUnit simulator, final Terminal terminalFrom,
88 final Terminal terminalTo, final boolean empty, final ShippingLine shippingLine)
89 {
90 super();
91 this.simulator = simulator;
92 this.terminalFrom = terminalFrom;
93 this.terminalLastStacked = terminalFrom;
94 this.terminalTo = terminalTo;
95 this.empty = empty;
96 this.shippingLine = shippingLine;
97 this.creationTime = this.simulator.getSimulatorTime();
98 for (int i = 0; i < ContainerTransportCostBreakdownEnum.values().length; i++)
99 {
100 this.transportCosts[i] = 0.0f;
101 }
102 for (int i = 0; i < ContainerTransportFeeBreakdownEnum.values().length; i++)
103 {
104 this.transportFee[i] = 0.0f;
105 }
106 for (int i = 0; i < ContainerTransportCO2BreakdownEnum.values().length; i++)
107 {
108 this.transportKgCO2[i] = 0.0f;
109 }
110 for (int i = 0; i < ContainerTransportTimeBreakdownEnum.values().length; i++)
111 {
112 this.transportTime[i] = 0.0f;
113 }
114 }
115
116
117
118
119
120 public final void addTransportCost(final ContainerTransportCostBreakdownEnum costEnum, final double cost)
121 {
122 this.transportCosts[costEnum.ordinal()] += cost;
123 }
124
125
126
127
128
129 public final void addTransportFee(final ContainerTransportFeeBreakdownEnum feeEnum, final double fee)
130 {
131 this.transportFee[feeEnum.ordinal()] += fee;
132 }
133
134
135
136
137
138 public final void addTransportKgCO2(final ContainerTransportCO2BreakdownEnum co2Enum, final double kgCO2)
139 {
140 this.transportKgCO2[co2Enum.ordinal()] += kgCO2;
141 }
142
143
144
145
146
147 public final void addTransportTime(final ContainerTransportTimeBreakdownEnum timeEnum, final double time)
148 {
149 this.transportTime[timeEnum.ordinal()] += time;
150 }
151
152
153
154
155
156 public final double getTransportCost(final ContainerTransportCostBreakdownEnum costEnum)
157 {
158 return this.transportCosts[costEnum.ordinal()];
159 }
160
161
162
163
164
165 public final double getTransportFee(final ContainerTransportFeeBreakdownEnum feeEnum)
166 {
167 return this.transportFee[feeEnum.ordinal()];
168 }
169
170
171
172
173
174 public final double getTransportKgCO2(final ContainerTransportCO2BreakdownEnum co2Enum)
175 {
176 return this.transportKgCO2[co2Enum.ordinal()];
177 }
178
179
180
181
182
183 public final double getTransportTime(final ContainerTransportTimeBreakdownEnum timeEnum)
184 {
185 return this.transportTime[timeEnum.ordinal()];
186 }
187
188
189
190
191 public final double getSumTransportCost()
192 {
193 double sum = 0.0;
194 for (int i = 0; i < ContainerTransportCostBreakdownEnum.values().length; i++)
195 {
196 sum += this.transportCosts[i];
197 }
198 return sum;
199 }
200
201
202
203
204 public final double getSumTransportFee()
205 {
206 double sum = 0.0;
207 for (int i = 0; i < ContainerTransportFeeBreakdownEnum.values().length; i++)
208 {
209 sum += this.transportFee[i];
210 }
211 return sum;
212 }
213
214
215
216
217 public final double getSumTransportKgCO2()
218 {
219 double sum = 0.0;
220 for (int i = 0; i < ContainerTransportCO2BreakdownEnum.values().length; i++)
221 {
222 sum += this.transportKgCO2[i];
223 }
224 return sum;
225 }
226
227
228
229
230 public final double getSumTransportTime()
231 {
232 double sum = 0.0;
233 for (int i = 0; i < ContainerTransportTimeBreakdownEnum.values().length; i++)
234 {
235 sum += this.transportTime[i];
236 }
237 return sum;
238 }
239
240
241
242
243 @SuppressWarnings("checkstyle:needbraces")
244 public final void collectTerminalStatisticsAtContainerDestination()
245 {
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295 }
296
297
298
299
300 public final Terminal getTerminalFrom()
301 {
302 return this.terminalFrom;
303 }
304
305
306
307
308 public final Terminal getTerminalTo()
309 {
310 return this.terminalTo;
311 }
312
313
314
315
316 public final Terminal getTerminalLastStacked()
317 {
318 return this.terminalLastStacked;
319 }
320
321
322
323
324 public final void setTerminalFrom(final Terminal terminalFrom)
325 {
326 this.terminalFrom = terminalFrom;
327 }
328
329
330
331
332 public final void setTerminalTo(final Terminal terminalTo)
333 {
334 this.terminalTo = terminalTo;
335 }
336
337
338
339
340 public final void setTerminalLastStacked(final Terminal terminalLastStacked)
341 {
342 this.terminalLastStacked = terminalLastStacked;
343 }
344
345
346
347
348 public final boolean isEmpty()
349 {
350 return this.empty;
351 }
352
353
354
355
356 public final FullEmptyEnum fullEmpty()
357 {
358 if (this.empty)
359 {
360 return FullEmptyEnum.EMPTY;
361 }
362 return FullEmptyEnum.FULL;
363 }
364
365
366
367
368 public final Company getOwner()
369 {
370 return this.shippingLine;
371 }
372
373
374
375
376 public final ShippingLine getShippingLine()
377 {
378 return this.shippingLine;
379 }
380
381
382 @Override
383 public final String toString()
384 {
385 String full = this.empty ? "[EMPTY]" : "[FULL]";
386 return "Container from " + this.terminalFrom.getName() + " to " + this.terminalTo.getName() + " at "
387 + this.terminalLastStacked.getName() + " (owner " + this.shippingLine.getCode() + ") " + full;
388 }
389
390
391
392
393 public final String toShortString()
394 {
395 String full = this.empty ? "[E]" : "[F]";
396 return this.terminalFrom.getName() + "->" + this.terminalTo.getName() + "@" + this.terminalLastStacked.getName() + full;
397 }
398
399
400
401
402 public final Time getStackArrivalTime()
403 {
404 return this.stackArrivalTime;
405 }
406
407
408
409
410 public final void setStackArrivalTime()
411 {
412 this.stackArrivalTime = this.simulator.getSimulatorTime();
413 }
414
415
416
417
418 public final Time getCreationTime()
419 {
420 return this.creationTime;
421 }
422
423
424
425
426 public final Time getOnShipTime()
427 {
428 return this.onShipTime;
429 }
430
431
432
433
434 public final void setOnShipTime()
435 {
436 this.onShipTime = this.simulator.getSimulatorTime();
437 }
438
439 }