-
Notifications
You must be signed in to change notification settings - Fork 0
/
TruckLifecycle.cpp
63 lines (52 loc) · 1.39 KB
/
TruckLifecycle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "TruckLifecycle.hpp"
#include "globals.hpp"
// extern Store warehouse;
// extern Facility loadingDock;
// extern Queue truckParkingQueue;
// // Stats
// extern Histogram truckPackageCountHistogram;
// extern int packagesDelivered;
TruckLifecycle::TruckLifecycle(int id, TruckParams params, Configuration config)
{
this->params = params;
this->config = config;
truck.SetName("Truck " + std::to_string(id));
truck.SetQueue(truckParkingQueue);
fuelStore.SetName("FuelStore " + std::to_string(id));
fuelStore.SetCapacity(params.fuelCapacity);
}
void TruckLifecycle::load(int packageCount)
{
Enter(warehouse, packageCount);
Wait(packageCount * config.packageLoadTime);
}
void TruckLifecycle::unload(int packageCount)
{
// Unloading
Wait(packageCount * config.packageUnloadTime);
// Waiting for paperwork/in queue on the depo
Wait(Uniform(config.unloadExtraTimeMin, config.unloadExtraTimeMax));
}
void TruckLifecycle::travel(Way way)
{
Wait(way.time);
consumeFuel(fuel(way.distance));
}
int TruckLifecycle::fillFuel()
{
int fuelToFill = params.fuelCapacity - fuelStore.Used();
Enter(fuelStore, fuelToFill);
return fuelToFill;
}
void TruckLifecycle::consumeFuel(int fuel)
{
Leave(fuelStore, fuel);
}
double TruckLifecycle::maxTravelDistance()
{
return fuelStore.Used() / (double)params.fuelConsumption;
}
int TruckLifecycle::fuel(double distance)
{
return distance * params.fuelConsumption;
}