forked from FaresAtef1/Shipping-Company
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompany.h
285 lines (158 loc) · 5.67 KB
/
Company.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#pragma once
#include "Event.h"
#include "CancelEvent.h"
#include "PreparationEvent.h"
#include "PromoteEvent.h"
#include "Queue.h"
#include "PriorityQueue.h"
#include "LinkedList.h"
#include "Cargo.h"
#include "Truck.h"
#include "NormalTruck.h"
#include "SpecialTruck.h"
#include "VIPTruck.h"
#include"UI.h"
#include <fstream>
#include<string>
class Company
{
int AutoPromotion;
int MaxW;
int NumberOfAutoPromotions;
Queue < Event* > EventsList;
Queue<Cargo*> WaitingSpecialCargos;
PriorityQueue<Cargo*> WaitingVIPCargos;
LinkedList<Cargo*> WaitingNormalCargos;
PriorityQueue<Truck*> MovingTrucks;
Queue<Cargo*> DeliveredCargos;
Queue<NormalTruck*> EmptyNormalTrucks;
Queue<SpecialTruck*> EmptySpecialTrucks;
Queue<VIPTruck*> EmptyVIPTrucks;
Queue<Truck*> LoadingTrucks;
Queue<NormalTruck*> NormalCheckUpTrucks;
Queue<SpecialTruck*> SpecialCheckUpTrucks;
Queue<VIPTruck*> VIPCheckUpTrucks;
Truck* NormalLoadingTruck;
Truck* SpecialLoadingTruck;
Truck* VIPLoadingTruck;
public:
//The Funcion Responsible for The Simulation
void Simulate(int Type, string InputFile);
// CONSTRUCTORS
Company();
//-----------------------------------------------------//
// ENQUEUING/INSERTING FUNCTIONS
// function to enqueue a cargo into Waiting Special Queue
void enqueueWSC(Cargo* SC);
// function to enqueue a cargo into Waiting VIP Queue
void enqueueWVC(Cargo* VC,int Priority);
// function to insert a cargo into Waiting Normal List
void insertWNC(Cargo* NC);
// function to insert a cargo in the beginning of the Waiting Normal List
void insertFirstWNC(Cargo* NC);
// function to enqueue a cargo into Events Queue
void AddEvent(Event* E);
// function to enqueue a cargo into Delivered queue
void EnqueueDC(Cargo* SC);
// function to enqueue moving truck int moving trucks queue
void EnqueueMT(Truck* MT);
//-----------------------------------------------------//
// DEQUEUEING/REMOVING FUNCTIONS
// function to remove a cargo from Waiting Normal List according to ID
Cargo* RemoveWNC(int id);
// function to Dequeue a cargo from Waiting VIP Cargos
bool DequeueWVC(Cargo*& VC);
// function to Dequeue a cargo from Waiting Special Cargos
bool DequeueWSC(Cargo*& SC);
// function to Dequeue an event from Events Queue
bool DequeueEvent(Event*& E);
// function to Remove First cargo from Waiting Normal Cargos List
bool RemoveFirstWNC(Cargo*& NC);
//-----------------------------------------------------//
// PRINTING OF QUEUES/LISTS FUNCTIONS BY CALLING PRINT FUNCTIONG IN QUEUES
// function to print Waiting Normal Cargos List
void PrintWNC();
// function to print Waiting Speical Cargos Queue
void PrintWSC();
// function to print Waiting VIP Cargos
void PrintWVC();
// function to print Delivered Cargos Queue
void PrintDC();
//function to print empty normal trucks
void PrintENT();
//function to print empty special trucks
void PrintEST();
//function to print empty VIP trucks
void PrintEVT();
//function to print moving trucks
void PrintMovingTrucks();
//function to print normal checkup trucks
void PrintNCT();
//function to print special checkup trucks
void PrintSCT();
//function to print VIP checkup trucks
void PrintVCT();
//-----------------------------------------------------//
// LOADING FUNCTION
void LoadFile(string Input);
//-----------------------------------------------------//
// OTHER FUNCTIONS
//function to return count of all Waiting Cargos
int WaitingNormalCount();
int WaitingSpecialCount();
int WaitingVIPCount();
//function to get the number of loading trucks
int GetLoadingTruckCount();
//function to get number of empty trucks
int GetEmptyTruckCount();
//function to get number of moving cargos
int GetMovingCargoCount();
//function to get number of incheckup trucks
int GetCheckupCount();
//function to return count of all Delivered Cargos
int DeliveredCount();
//function to get the waiting index
int GetWaitingIndex(int ID);
//function to Get AutoPromotion
int GetAutoPromotion();
//function to Set AutoPromotion
void SetAutoPromotion(int AP);
//function to Autopromote
void AutoPromote(Time CurrentTime);
//function to load cargos
void LoadCargos(int& NLT, int& SLT, int& VLT,Time CurrentTime);
//function to Deliver cargos
void DeliverCargos(Time Current);
// function to move a truck from moving to avail
void MoveToAvail();
// function to move a truck from moving to checkup
void MoveToCheckUp(Time Current);
//function to move from checkup to avail
void MoveCheckUpToAvail(Time Current);
//fuction to set the normal loading truck
void SetNormalLoadingTruck(Truck* Nptr);
//fuction to set the special loading truck
void SetSpecialLoadingTruck(Truck* Sptr);
//fuction to set the VIP loading truck
void SetVIPLoadingTruck(Truck* Vptr);
//fuction to get the normal loading truck
Truck* GetNormalLoadingTruck();
//function to get the special loading truck
Truck* GetSpecialLoadingTruck();
//fuction to get the VIP loading truck
Truck* GetVIPLoadingTruck();
// fuction to handle the maxw rule
void HandleMaxW(int& NLT, int& SLT, Time CurrentTime);
//funtion to execute events
void ExecuteEvents(Event*& CurrentEvent,Time CurrentTime);
//function to increment the counters in the simulation function
void AdvanceSimTime(int& hour, int& day, int& NLT, int& SLT, int& VLT);
//function to generate the output file
void GenerateOutputFile(Time EndSimTime);
//function to check that all cargos is delivered
bool AllIsDelivered();
//function to decrement returning hours
void DecrementReturningHours();
//function to handle the delivery failure
void DeliveryFailure(Truck* MT);
};