Skip to content

Commit

Permalink
Final touches
Browse files Browse the repository at this point in the history
  • Loading branch information
KrKOo committed Dec 4, 2022
1 parent a3bfdf8 commit 44b557c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
18 changes: 9 additions & 9 deletions ArgumentParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ArgumentParser::ArgumentParser(int argc, char **argv)
Arguments ArgumentParser::parse(Arguments &defaultArguments)
{
Arguments arguments = defaultArguments;
const char *shortOptions = "d:e:s:m";
const char *shortOptions = "hd:e:s:m";
struct option longOptions[] = {
{"help", no_argument, 0, 'h'},
{"df", required_argument, 0, DIESEL_CAPACITY},
Expand Down Expand Up @@ -78,14 +78,14 @@ Arguments ArgumentParser::parse(Arguments &defaultArguments)

void ArgumentParser::printHelp()
{
std::cout << "-d Diesel truck count" << std::endl;
std::cout << "-e Electric truck count" << std::endl;
std::cout << "-s Simulation duration" << std::endl;
std::cout << "-m Package manufacturing time" << std::endl;
std::cout << "--df Diesel fuel capacity" << std::endl;
std::cout << "--ef Electric battery capacity" << std::endl;
std::cout << "--dc Diesel fuel consumption /1km" << std::endl;
std::cout << "--ec Electric battery consumption /1km" << std::endl;
std::cout << "-d <count> Diesel truck count" << std::endl;
std::cout << "-e <count> Electric truck count" << std::endl;
std::cout << "-s <minutes> Simulation duration" << std::endl;
std::cout << "-m <minutes> Package manufacturing time" << std::endl;
std::cout << "--df <ml> Diesel fuel capacity" << std::endl;
std::cout << "--ef <Wh> Electric battery capacity" << std::endl;
std::cout << "--dc <ml/km> Diesel fuel consumption" << std::endl;
std::cout << "--ec <Wh/km> Electric battery consumption" << std::endl;
}

std::string ArgumentParser::getArgument()
Expand Down
13 changes: 7 additions & 6 deletions ElectricTruckLifecycle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void ElectricTruckLifecycle::Behavior()
Seize(truck);

// 2 * distance because we need to go there and back
int filledAtFactory = checkFuelAndFuelUpIfNeeded(2 * way.distance);
int filledAtFactory = checkFuelAndFuelUpIfNeeded(2 * way.distance, true);
if (filledAtFactory > 0)
{
electricityChargedAtFactory(filledAtFactory);
Expand All @@ -39,7 +39,7 @@ void ElectricTruckLifecycle::Behavior()
packagesDelivered += packageCount;

// Charge up, if we previously couldn't charge it more
int filledAtDestination = checkFuelAndFuelUpIfNeeded(way.distance);
int filledAtDestination = checkFuelAndFuelUpIfNeeded(way.distance, false);
if (filledAtDestination > 0)
{
electricityChargedAtDestination(filledAtDestination);
Expand All @@ -52,15 +52,15 @@ void ElectricTruckLifecycle::Behavior()
}
}

int ElectricTruckLifecycle::checkFuelAndFuelUpIfNeeded(double distance)
int ElectricTruckLifecycle::checkFuelAndFuelUpIfNeeded(double distance, bool atFactory)
{
int filled = 0;
if (distance > maxTravelDistance())
{
int initialFuel = fuelStore.Used();
int newFuelLevel = fillFuel(distance);
filled = newFuelLevel - initialFuel;
Wait(fuelingTime(initialFuel, newFuelLevel));
Wait(fuelingTime(initialFuel, newFuelLevel, atFactory));
}

return filled;
Expand All @@ -78,13 +78,14 @@ int ElectricTruckLifecycle::fillFuel(double distance)
}

// function sqrt(x) <0-1> * MAX_CHARGE_TIME
double ElectricTruckLifecycle::fuelingTime(double initialLevel, double finalLevel)
double ElectricTruckLifecycle::fuelingTime(double initialLevel, double finalLevel, bool atFactory)
{
double chargeTime = atFactory ? FACTORY_CHARGE_TIME : DEPO_CHARGE_TIME;
double initialLevelPercentage = initialLevel / params.fuelCapacity;
double finalLevelPercentage = finalLevel / params.fuelCapacity;

double initialTimePercentage = initialLevelPercentage * initialLevelPercentage;
double finalTimePercentage = finalLevelPercentage * finalLevelPercentage;

return (finalTimePercentage - initialTimePercentage) * MAX_CHARGE_TIME;
return (finalTimePercentage - initialTimePercentage) * chargeTime;
}
7 changes: 4 additions & 3 deletions ElectricTruckLifecycle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
#include "Configuration.hpp"
#include "TruckLifecycle.hpp"

#define MAX_CHARGE_TIME 300 // 5 hours
#define FACTORY_CHARGE_TIME 150 // 2.5 hours
#define DEPO_CHARGE_TIME 570 // 9.5 hours

class ElectricTruckLifecycle : public TruckLifecycle
{
void Behavior();
int checkFuelAndFuelUpIfNeeded(double distance);
int checkFuelAndFuelUpIfNeeded(double distance, bool atFactory);
int fillFuel(double distance);
double fuelingTime(double initialLevel, double finalLevel);
double fuelingTime(double initialLevel, double finalLevel, bool atFactory);

public:
ElectricTruckLifecycle(int id, TruckParams params, Configuration config);
Expand Down

0 comments on commit 44b557c

Please sign in to comment.