Skip to content

Commit

Permalink
Add save to sim
Browse files Browse the repository at this point in the history
  • Loading branch information
Khalidmamdou7 committed Jun 8, 2021
1 parent f2a5e85 commit 9b0b4ff
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion MarsExploration/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int main() {
MarsStation M;
M.load();
M.Simulate();

M.Save();
return 0;


Expand Down
24 changes: 12 additions & 12 deletions MarsExploration/MarsStation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ void MarsStation::assign()
int ED; // Execution Days
while (!WaitingEmergency->isEmpty())
{
if (AvailableER->dequeue(R))
if (AvailableER->dequeue(R) && R->getSpeed() != 0)
{
WaitingEmergency->dequeue(M);
}
else if (AvailableMR->dequeue(R))
else if (AvailableMR->dequeue(R) && R->getSpeed() != 0)
{
WaitingEmergency->dequeue(M);
}
else if (AvailablePR->dequeue(R))
else if (AvailablePR->dequeue(R) && R->getSpeed() != 0)
{
WaitingEmergency->dequeue(M);
}
Expand All @@ -90,7 +90,7 @@ void MarsStation::assign()

while (!WaitingPolar->isEmpty())
{
if (AvailablePR->dequeue(R))
if (AvailablePR->dequeue(R) && R->getSpeed() != 0)
{
WaitingPolar->dequeue(M);
M->setAssignedRover(R);
Expand All @@ -109,11 +109,11 @@ void MarsStation::assign()

while (!WaitingMount->isEmpty())
{
if (AvailableMR->dequeue(R))
if (AvailableMR->dequeue(R) && R->getSpeed() != 0)
{
WaitingMount->dequeue(M);
}
else if (AvailableER->dequeue(R))
else if (AvailableER->dequeue(R) && R->getSpeed() != 0)
{
WaitingMount->dequeue(M);
}
Expand Down Expand Up @@ -271,10 +271,10 @@ void MarsStation::Simulate() {
ExecuteEvents();
FinishedExecution();
FinishedCheckup();
autoP();
assign();
// Collect Statistics
ui->Output(this);
// save
Save();
}


Expand Down Expand Up @@ -389,7 +389,7 @@ void MarsStation::FinishedCheckup()


void MarsStation::autoP() {
Mission* pM = NULL;
Mission* pM = NULL;
while (WaitingMount->peek(pM)) {
if ((current_day - pM->getFD()) == mount_rovers_autoP) {
WaitingMount->dequeue(pM);
Expand Down Expand Up @@ -418,8 +418,8 @@ void MarsStation::Save() {
outputfile << "Rovers : " << counter_of_all_rovers << "[M:" << counter_of_mount_rovers << "," <<
"P:" << counter_of_polar_rovers << "," << "E:" << counter_of_emergency_rovers << "]" << endl;

outputfile << "Avg Wait :" << (sumWD/ counter_of_all_comp_missons)*100;
outputfile << "Avg Exec :" << (sumWD / counter_of_all_comp_missons)*100 <<endl;
outputfile << "Auto-promoted" << (AutoPcount / counter_of_mount_comp_missons) * 100;
outputfile << "Avg Wait :" << (counter_of_all_comp_missons == 0) ? 0 : (sumWD / counter_of_all_comp_missons)*100;
outputfile << "Avg Exec :" << (counter_of_all_comp_missons == 0) ? 0 : (sumED / counter_of_all_comp_missons)*100;
outputfile << "Auto-promoted" << (counter_of_mount_comp_missons == 0) ? 0 : (AutoPcount / counter_of_mount_comp_missons) * 100;
outputfile.close();
}
11 changes: 6 additions & 5 deletions MarsExploration/MarsStation.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,19 @@ class MarsStation
public:
MarsStation();

void AutoP();
void load();
void Simulate();
bool FinishedSimulation();
void ExecuteEvents(); // Execute the events that should be executed at that day
void FinishedExecution(); // Checks if missions finished execution
void FinishedCheckup(); // Checks if rovers finished checkup and move it to available rovers
int GetCurrentDay();
void assign();
void autoP();
void Save();
void justfortest();


PriorityQueue<Mission*>* getWEMList();
LinkedQueue<Mission*>* getWPMList();
LinkedQueue<Mission*>* getWMMList();
Expand All @@ -118,10 +123,6 @@ class MarsStation
LinkedQueue<Rover*>* getInCheckupMR();
LinkedQueue<Rover*>* getInCheckupPR();
LinkedQueue<Mission*>* getCompletedMissions();
void assign();
void autoP();
void Save();
void justfortest();

};

Expand Down
3 changes: 3 additions & 0 deletions MarsExploration/Output_File.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CD ID FD WD ED........................................................................................................................................................Missions : 0[M:0,P:0,E:0]
Rovers : 0[M:0,P:0,E:0]
Avg Wait :1Avg Exec :1Auto-promoted1
Binary file modified MarsExploration/x64/Debug/MarsExploration.tlog/link.read.1.tlog
Binary file not shown.

0 comments on commit 9b0b4ff

Please sign in to comment.