-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TruckLifecycle separated to different file
- Loading branch information
KrKOo
committed
Dec 2, 2022
1 parent
26ec0ca
commit 3fb1bd1
Showing
4 changed files
with
200 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef __CONFIGURATION__H__ | ||
#define __CONFIGURATION__H__ | ||
|
||
struct Configuration | ||
{ | ||
// Time | ||
int simulationDuration; | ||
// Truck | ||
int truckCount; | ||
int truckFuelTankCapacity; | ||
double truckFuelConsumption; | ||
int truckCargoCapacityMin; | ||
int truckCargoCapacityMax; | ||
// Factory | ||
int warehouseCapacity; | ||
int packageManufacturingTime; | ||
// Loading | ||
int packageLoadTime; | ||
// Unloading | ||
int packageUnloadTime; | ||
int unloadExtraTimeMin; | ||
int unloadExtraTimeMax; | ||
}; | ||
|
||
#endif //!__CONFIGURATION__H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#include "DieselTruckLifecycle.hpp" | ||
|
||
extern Store warehouse; | ||
extern Facility loadingDock; | ||
extern Queue truckParkingQueue; | ||
|
||
// Stats | ||
extern Stat truckParkingTime; | ||
extern Histogram truckPackageCountHistogram; | ||
extern int packagesDelivered; | ||
|
||
DieselTruckLifecycle::DieselTruckLifecycle(int id, Configuration config) | ||
{ | ||
this->config = config; | ||
truck.SetName("Truck " + std::to_string(id)); | ||
truck.SetQueue(truckParkingQueue); | ||
fuelStore.SetName("FuelStore " + std::to_string(id)); | ||
fuelStore.SetCapacity(config.truckFuelTankCapacity); | ||
} | ||
|
||
void DieselTruckLifecycle::Behavior() | ||
{ | ||
fillFuel(); | ||
|
||
while (true) | ||
{ | ||
double distance = Uniform(10, 300); | ||
int packageCount = Uniform(config.truckCargoCapacityMin, config.truckCargoCapacityMax); | ||
|
||
int startTime = Time; | ||
Seize(truck); | ||
int endTime = Time; | ||
|
||
truckParkingTime(endTime - startTime); | ||
|
||
truckPackageCountHistogram(packageCount); | ||
load(packageCount); | ||
|
||
travel(distance); | ||
|
||
unload(packageCount); | ||
packagesDelivered += packageCount; | ||
|
||
travel(distance); | ||
|
||
Release(truck); | ||
} | ||
} | ||
|
||
void DieselTruckLifecycle::load(int packageCount) | ||
{ | ||
Seize(loadingDock); | ||
Enter(warehouse, packageCount); | ||
Wait(packageCount * config.packageLoadTime); | ||
Release(loadingDock); | ||
} | ||
|
||
void DieselTruckLifecycle::unload(int packageCount) | ||
{ | ||
// Unloading | ||
Wait(packageCount * config.packageUnloadTime); | ||
|
||
// Waiting for paperwork/in queue on the depo | ||
Wait(Uniform(config.unloadExtraTimeMin, config.unloadExtraTimeMax)); | ||
} | ||
|
||
void DieselTruckLifecycle::travel(double distance) | ||
{ | ||
if (distance > maxTravelDistance()) | ||
{ | ||
// Not enough fuel for the whole drive | ||
double distanceToFuelingStation = Uniform(0, maxTravelDistance()); | ||
consumeFuel(fuel(distanceToFuelingStation)); | ||
Wait(time(distanceToFuelingStation)); | ||
|
||
// At the fueling station | ||
fillFuel(); | ||
Wait(60); | ||
|
||
// Continue to the destination | ||
double remainingDistance = distance - distanceToFuelingStation; | ||
consumeFuel(fuel(remainingDistance)); | ||
Wait(time(remainingDistance)); | ||
} | ||
else | ||
{ | ||
// Enough fuel for the whole drive | ||
consumeFuel(fuel(distance)); | ||
Wait(time(distance)); | ||
} | ||
} | ||
|
||
void DieselTruckLifecycle::fillFuel() | ||
{ | ||
int fuelToFill = config.truckFuelTankCapacity - fuelStore.Used(); | ||
Enter(fuelStore, fuelToFill); | ||
fuelFilled(fuelToFill); | ||
} | ||
|
||
void DieselTruckLifecycle::consumeFuel(int fuel) | ||
{ | ||
Leave(fuelStore, fuel); | ||
} | ||
|
||
double DieselTruckLifecycle::maxTravelDistance() | ||
{ | ||
return fuelStore.Used() / config.truckFuelConsumption; | ||
} | ||
|
||
double DieselTruckLifecycle::time(double distance) // km -> min | ||
{ | ||
return distance / (60 / 70.0); // 70km/h | ||
} | ||
|
||
int DieselTruckLifecycle::fuel(double distance) | ||
{ | ||
return distance * config.truckFuelConsumption; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef __TRUCKLIFECYCLE__H__ | ||
#define __TRUCKLIFECYCLE__H__ | ||
|
||
#include <simlib.h> | ||
#include "Configuration.hpp" | ||
|
||
class DieselTruckLifecycle : public Process | ||
{ | ||
Store fuelStore; | ||
Facility truck; | ||
Stat fuelFilled; | ||
|
||
Configuration config; | ||
|
||
void Behavior(); | ||
|
||
void load(int packageCount); | ||
void unload(int packageCount); | ||
void travel(double distance); | ||
|
||
void fillFuel(); | ||
void consumeFuel(int fuel); | ||
double maxTravelDistance(); | ||
double time(double distance); | ||
int fuel(double distance); | ||
|
||
public: | ||
DieselTruckLifecycle(int id, Configuration config); | ||
}; | ||
|
||
#endif //!__TRUCKLIFECYCLE__H__ |
Oops, something went wrong.