Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
DEVOLOPER-1 committed Dec 25, 2024
2 parents 3b8c289 + 43300eb commit 3778cf0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 142 deletions.
2 changes: 1 addition & 1 deletion Includes/Car.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Car
int nextDropOffTime;

void setStatus(string status);

int calcDuration(int distance);
public:
// Constructor
Car(string CarType, int speed, int HospitalID, int car_number);
Expand Down
82 changes: 5 additions & 77 deletions Includes/Organizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class Organizer {
int variableIndex;
int index;
bool running;
bool silentMode;

private:
Organizer();

Expand Down Expand Up @@ -103,7 +105,7 @@ class Organizer {
void SetPatientsCount(int * PatientsCount);
void SetCancellationsCount(int CancellationsCount);
void setTotalCars_in_AllHospitals(int Total_S_Cars_in_AllHospitals , int Total_N_Cars_in_AllHospitals);
void runSimulation(bool SilentMode); // Method to run the timestep simulation
void runSimulation();
bool isSimulationComplete(); // Method to check if the simulation is done

/*
Expand Down Expand Up @@ -139,6 +141,8 @@ class Organizer {
void receive(Car* car);

// methods to handle input file (Scenario)
void getProgramMode();

void loadInputFile();

void ReAssignBetterHospital(Request* request);
Expand All @@ -151,79 +155,3 @@ class Organizer {

};






// void simulateTimeStep(int timeStep){}
//
// void handleCarArrival(Car* car){}
//
// // void assignPatientToCar(Patient* patient, Car* car){}
//
//
//
// void callUIUpdate(int timeStep){}







/*
LinkedQueue<Request*> getRequests() { return requests; }
LinkedQueue<Request*> getCancellations() { return cancellations; }
LinkedQueue<Car*> getOutCars() { return outCars; }
LinkedQueue<Car*> getBackCars() { return backCars; }
*/





//Deprecated

// void loadInputFile() {
//
// cout<<"Reading File....."<<endl;
// this->InputFile.open(FileName);
// if (InputFile.is_open()) {
// string Currentline,NextLine;
// int SectionCounter{0};
//
// while (getline(InputFile, Currentline)) {
// while (getline(InputFile, NextLine, ' ')) {
// if (Currentline.empty()) {
// SectionCounter++;
// cout << "Section Counter -> " << SectionCounter << endl;
// continue;
// }
//
// // Process sections based on the SectionCounter
// if (SectionCounter == 0) {
// cout << "### HOSPITALS ###" << endl;
// cout << Currentline << endl;
// } else if (SectionCounter == 1) {
// cout << "### DISTANCE_MATRIX ###" << endl;
// cout << Currentline << endl;
// } else if (SectionCounter == 2) {
// cout << "### CAR_DISTRIBUTION ###" << endl;
// cout << Currentline << endl;
// } else if (SectionCounter == 3) {
// cout << "### REQUESTS ###" << endl;
// cout << Currentline << endl;
// } else if (SectionCounter == 4) {
// cout << "### CANCELLATIONS ###" << endl;
// cout << Currentline << endl;
// }
// }
// }
// InputFile.close();
// }
//
// }



60 changes: 2 additions & 58 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,12 @@
#include "Includes/Organizer.h"
using namespace std;

bool getProgramMode(){
char answer;
cout << "Please choose the way the Output file will be displayed\n(Y or y) for time step simulation\n(N or n) for silent mode: ";
cin >> answer;
while(answer != 'Y' && answer != 'y' && answer != 'N' && answer != 'n'){
cout << "Invalid input, please enter (Y) for time step simulation, (N) for silent mode: ";
cin >> answer;
}
if(answer == 'Y' || answer == 'y'){
return false;
}
else
{
return true;
}
}


int main()
{
ORG->loadInputFile();
bool SilentMode = getProgramMode();
ORG->runSimulation(SilentMode);

ORG->getProgramMode();
ORG->runSimulation();

//Hospital* hospitals[2];
//hospitals[0] = new Hospital(1, 2, 2, 3, 2);
//hospitals[1] = new Hospital(2, 2, 2, 3, 2);

// ORG->setHospital(*hospitals);
//
// LinkedQueue<Request*> requests;
// // dummy requests
// requests.enqueue(new Request("NP", 2, 1, 1, 5));
// requests.enqueue(new Request("SP", 3, 2, 1, 7));
// requests.enqueue(new Request("EP", 4, 3, 1, 9, 3));
// requests.enqueue(new Request("NP", 5, 4, 1, 5));
// requests.enqueue(new Request("SP", 5, 5, 1, 7));
// requests.enqueue(new Request("EP", 6, 6, 2, 9, 9));
// requests.enqueue(new Request("NP", 7, 7, 2, 5));
// requests.enqueue(new Request("SP", 8, 8, 2, 7));
// requests.enqueue(new Request("EP", 9, 9, 2, 9, 6));
// requests.enqueue(new Request("NP", 9, 10, 2, 5));
// ORG->setRequests(requests);

//int timestep = 0;
//while (++timestep <= 100)
//{
// cout << "Timestep: " << timestep << endl;
// ORG->distributeRequests(timestep);
// ORG->handleHospitals(timestep);
// if(timestep == 13)
// cout << "here\n";
// ORG->handleCars(timestep);
//
// //this_thread::sleep_for(2s);
// cout << "\n====================" << endl;
//}
}


// deprecated
/*
*/
12 changes: 9 additions & 3 deletions src/Car.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#pragma once
#include "../Includes/Car.h"
#include <cmath>

void Car::setStatus(string status)
{
this->status = status;
}

int Car::calcDuration(int distance)
{
return ceil( (double)distance / (double)speed );
}

Car::Car(string CarType, int speed, int HospitalID, int car_number) : CarType(CarType), speed(speed)
, HospitalID(HospitalID), request(nullptr), status("Ready"), nextPickupTime(0), nextDropOffTime(0)
{
Expand Down Expand Up @@ -49,14 +56,13 @@ void Car::assign(int timestep, Request* request)
logger->CalcFinishTime(logger->getPT(), request->getDistance(), speed);
logger->CalcBusyTime();

nextPickupTime = timestep + (request->getDistance() / speed);
nextDropOffTime = nextPickupTime + (request->getDistance() / speed);
nextPickupTime = timestep + calcDuration(request->getDistance());
}

void Car::pickUp()
{
setStatus("Loaded");

nextDropOffTime = nextPickupTime + calcDuration(request->getDistance());
}

void Car::cancel()
Expand Down
28 changes: 25 additions & 3 deletions src/Organizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Organizer::Organizer() : FileName("E:\\Coding\\C++\\Ambulance-Management-System\
, requests(), cancellations(), outCars(), backCars(), hospitals(nullptr), TotalSimulationTime(0),
HospitalsCount(0), Total_EP_Patients_in_AllHospitals(0), Total_SP_Patients_in_AllHospitals(0),
Total_NP_Patients_in_AllHospitals(0), CancellationsCount(0), Total_N_Cars_in_AllHospitals(0),
Total_S_Cars_in_AllHospitals(0), variableIndex(0), index(0), running(true)
Total_S_Cars_in_AllHospitals(0), variableIndex(0), index(0), running(true), silentMode(false)
{
HANDLE hWindows = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursorInfo;
Expand Down Expand Up @@ -137,15 +137,15 @@ void Organizer::distributeRequests(int timeStep)
}
}

void Organizer::runSimulation(bool SilentMode ) {
void Organizer::runSimulation() {
int timestep = 1;
UI ui;


while (true) {

distributeRequests(timestep);
if (SilentMode == false)
if (silentMode == false)
{
thread inputThread([this]() { this->getInputs(); });
ui.display(timestep, index);
Expand Down Expand Up @@ -212,6 +212,28 @@ void Organizer::handleCars(int timeSteps)

void Organizer::receive(Car* car) { outCars.enqueue(car, -(car->getPickedUpTime())); }

void Organizer::getProgramMode()
{
char answer;

cout << "Please choose the way the Output file will be displayed\n(Y or y) for time step simulation\n(N or n) for silent mode: ";
cin >> answer;

while (answer != 'Y' && answer != 'y' && answer != 'N' && answer != 'n') {
cout << "Invalid input, please enter (Y) for time step simulation, (N) for silent mode: ";
cin >> answer;
}

if (answer == 'Y' || answer == 'y') {
silentMode = false;
}

else
{
silentMode = true;
}
}

void Organizer::loadInputFile()
{
//cout << "Reading File....." << endl;
Expand Down

0 comments on commit 3778cf0

Please sign in to comment.