-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestcase1.c
More file actions
592 lines (514 loc) · 15.7 KB
/
testcase1.c
File metadata and controls
592 lines (514 loc) · 15.7 KB
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
#include <stdio.h>
#include <stdlib.h>
#include "graph.h"
#include "priority_queue.h"
#include "time.h"
int main()
{
int choice, repeat, n, degree;
PtrAdjList G;
timeHistoryTable *T;
printf("WELCOME TO ROUTING!\n");
printf("Mini Project of Group 29 under TA Mr. Tanish Lad\n");
printf("\nBy\nAditya Malhotra(2020101052)\nParshva Bhadra(2020101001)\nAnubhav Pal(2020112012)\nKarnati Jahnavi(2020102052)\nAaryan Sharma(2020115008)\n\n");
/*
printf("Please enter the total number of vertices: \n");
scanf("%d", °ree);
*/
degree=8;
G = CreateEmptyGraph(degree);
T = createEmptyTimeHistoryTable(degree);
InsertEdge(G,1,2,10,3);
InsertEdge(G,1,6,6,12);
InsertEdge(G,2,4,2,18);
InsertEdge(G,2,5,3,17);
InsertEdge(G,3,2,19,2);
InsertEdge(G,3,4,20,1);
InsertEdge(G,4,3,11,0);
InsertEdge(G,4,8,11,4);
InsertEdge(G,4,1,5,10);
InsertEdge(G,5,1,12,8);
InsertEdge(G,5,6,8,9);
InsertEdge(G,6,4,7,13);
InsertEdge(G,7,8,10,15);
InsertEdge(G,8,4,5,19);
InsertEdge(G,8,3,11,4);
addTimeNode(G,T,1,1,10,5,6,5,2);
addTimeNode(G,T,1,7,8,7,8,9,6);
addTimeNode(G,T,2,1.5,2,2.5,2.35,2,4);
addTimeNode(G,T,2,3,3,3,3.5,3.5,5);
addTimeNode(G,T,3,18,20,19,19,20,2);
addTimeNode(G,T,3,20,20,19,19,20,4);
addTimeNode(G,T,4,18,20,11,11,10,3);
addTimeNode(G,T,4,11,11,12,11,12,8);
addTimeNode(G,T,4,5,6,5,6,5,1);
addTimeNode(G,T,5,12,12,12,13,13,1);
addTimeNode(G,T,5,8,9,9,9,8,6);
addTimeNode(G,T,6,1,20,20,19,19,4);
addTimeNode(G,T,7,11,11,11,11,11,8);
addTimeNode(G,T,8,6,6,6,6,6,4);
addTimeNode(G,T,8,12,12,11,12,11,3);
MENU:
printf("\nMenu:\n");
printf("To add an edge, Press 1\n");
printf("To delete an edge, Press 2\n");
printf("To update distance, Press 3\n");
printf("To update number of cars, Press 4\n");
printf("To find shortest distance, Press 5\n");
printf("To find least time, Press 6\n");
printf("To find a safe path, Press 7\n");
printf("To print the graph, Press 8\n");
printf("To print the time history table, Press 9\n");
printf("To exit the program, Press 10\n\n");
scanf("%d", &choice);
if (choice < 1 || choice >= 11)
{
printf("\nInvalid Command! Please Choose Again.\n");
goto MENU;
}
if (choice == 1)
{
printf("\nYou have selected to add an edge.\n");
printf("To continue, Press 1\nTo go back to the main menu, Press 0\n");
POINT1:
scanf("%d", &n);
if (n == 1)
{
int vertex1, vertex2, cars;
double length;
POINT11:
printf("\nEnter the vertices between which you want to insert an edge: \n");
scanf("%d%d", &vertex1, &vertex2);
printf("Enter the length of the edge: \n");
scanf("%lf", &length);
printf("Enter the number of cars on the edge: \n");
scanf("%d", &cars);
InsertEdge(G, vertex1, vertex2, length, cars);
printf("\nReady for next task\n");
printf("Do you want to add another edge?\n");
printf("If YES, Press 1 \nIf No, Press 0\n");
POINT12:
scanf("%d", &repeat);
if (repeat == 1)
{
goto POINT11;
}
if (repeat == 0)
{
goto MENU;
}
if (repeat != 1 || repeat != 0)
{
printf("Invalid Command! Please Enter Again.\n");
goto POINT12;
}
}
if (n == 0)
{
goto MENU;
}
if (n != 0 || n != 1)
{
printf("Invalid Command! Please Enter Again.\n");
goto POINT1;
}
}
if (choice == 2)
{
printf("\nYou have selected to delete an edge.\n");
printf("To continue, Press 1\nTo go back to the main menu, Press 0\n");
POINT2:
scanf("%d", &n);
if (n == 1)
{
int vertex1, vertex2;
POINT21:
printf("Enter the vertices between which you want to delete the edge:\n");
scanf("%d%d", &vertex1, &vertex2);
DeleteEdge(G, vertex1, vertex2);
printf("\nReady for next task\n");
printf("Do you want to delete another edge?\n");
printf("If YES, Press 1 \nIf No, Press 0\n");
POINT22:
scanf("%d", &repeat);
if (repeat == 1)
{
goto POINT21;
}
if (repeat == 0)
{
goto MENU;
}
if (repeat != 1 || repeat != 0)
{
printf("Invalid Command! Please Enter Again.\n");
goto POINT22;
}
}
if (n == 0)
{
goto MENU;
}
if (n != 0 || n != 1)
{
printf("Invalid Command! Please Enter Again.\n");
goto POINT2;
}
}
if (choice == 3)
{
printf("You have selected to update distance.\n");
printf("To continue, Press 1\nTo go back to the main menu, Press 0\n");
POINT3:
scanf("%d", &n);
if (n == 1)
{
int vertex1, vertex2;
double new_length;
POINT31:
printf("Enter the vertices between which you want to update distance:\n");
scanf("%d%d", &vertex1, &vertex2);
printf("Enter the new distance:\n");
scanf("%lf", &new_length);
UpdateDis(G, vertex1, vertex2, new_length);
printf("\nReady for next task\n");
printf("Do you want to update another distance?\n");
printf("If YES, Press 1 \nIf No, Press 0\n");
POINT32:
scanf("%d", &repeat);
if (repeat == 1)
{
goto POINT31;
}
if (repeat == 0)
{
goto MENU;
}
if (repeat != 1 || repeat != 0)
{
printf("Invalid Command! Please Enter Again.\n");
goto POINT32;
}
}
if (n == 0)
{
goto MENU;
}
if (n != 0 || n != 1)
{
printf("Invalid Command. Please Enter Again.\n");
goto POINT3;
}
}
if (choice == 4)
{
printf("You have selected to update number of cars. \n");
printf("To continue, Press 1\nTo go back to the main menu, Press 0\n");
POINT4:
scanf("%d", &n);
if (n == 1)
{
int vertex1, vertex2;
int new_cars;
POINT41:
printf("Enter the vertices between which you want to update number of cars:\n");
scanf("%d%d", &vertex1, &vertex2);
printf("Enter the updated number of cars:\n");
scanf("%d", &new_cars);
UpdateCars(G, vertex1, vertex2, new_cars);
printf("\nReady for next task\n");
printf("Do you want to update another number of cars?\n");
printf("If YES, Press 1 \nIf No, Press 0\n");
POINT42:
scanf("%d", &repeat);
if (repeat == 1)
{
goto POINT41;
}
if (repeat == 0)
{
goto MENU;
}
if (repeat != 1 || repeat != 0)
{
printf("Invalid Command! Please Enter Again.\n");
goto POINT42;
}
}
if (n == 0)
{
goto MENU;
}
if (n != 0 || n != 1)
{
printf("Invalid Command! Please Enter Again.\n");
goto POINT4;
}
}
if (choice == 5)
{
printf("You have selected to find shortest distance.\n");
printf("To continue, Press 1\nTo go back to the main menu, Press 0\n");
POINT5:
scanf("%d", &n);
if (n == 1)
{
int source, destination;
POINT51:
printf("Enter the source of the path: \n");
scanf("%d", &source);
printf("Enter the destination of the path: \n");
scanf("%d", &destination);
shortest_distance_choice4(G, source, destination);
printf("\nReady for next task\n");
printf("Do you want to find shortest distance between another source and destination?\n");
printf("If YES, Press 1 \nIf No, Press 0\n");
POINT52:
scanf("%d", &repeat);
if (repeat == 1)
{
goto POINT51;
}
if (repeat == 0)
{
goto MENU;
}
if (repeat != 1 || repeat != 0)
{
printf("Invalid Command! Please Enter Again.\n");
goto POINT52;
}
}
if (n == 0)
{
goto MENU;
}
if (n != 0 || n != 1)
{
printf("Invalid Command! Please Enter Again.\n");
goto POINT5;
}
}
if (choice == 6)
{
printf("You have selected to find least time. \n");
printf("To continue, Press 1\nTo go back to the main menu, Press 0\n");
POINT6:
scanf("%d", &n);
if (n == 1)
{
int source, destination;
POINT61:
printf("Please enter the source of path:\n");
scanf("%d", &source);
printf("Please enter the destination of the path:\n");
scanf("%d", &destination);
shortest_time_choice5(G, source, destination);
printf("\nReady for next task\n");
printf("Do you want to find least time between another source and destination?\n");
printf("If YES, Press 1 \nIf No, Press 0\n");
POINT62:
scanf("%d", &repeat);
if (repeat == 1)
{
goto POINT61;
}
if (repeat == 0)
{
goto MENU;
}
if (repeat != 1 || repeat != 0)
{
printf("Invalid Command! Please Enter Again.\n");
goto POINT62;
}
}
if (n == 0)
{
goto MENU;
}
if (n != 0 || n != 1)
{
printf("Invalid Command! Please Enter Again.\n");
goto POINT6;
}
}
if (choice == 7)
{
printf("You have selected to find a safe distance.\n");
printf("To calculate safe distance we need data of the previous five dats\n");
printf("To continue, Press 1\nTo go back to the main menu, Press 0\n");
POINT7:
scanf("%d", &n);
if (n == 1)
{
int m;
printf("Welcome to safe path Menu\n");
printf("To add data for previous five days, Press 1\n");
printf("To calculate safe path, Press 2\n");
printf("To go back to the Main Menu, Press 0\n");
printf("Enter your choice: ");
scanf("%d", &m);
if (m == 1)
{
int vertex1,vertex2;
double t1, t2, t3, t4, t5;
POINT70:
printf("Please enter the vertices between which you want to add data:\n");
scanf("%d%d", &vertex1, &vertex2);
printf("Enter the time taken for the last five days\n");
scanf("%lf %lf %lf %lf %lf", &t1, &t2, &t3, &t4, &t5);
addTimeNode(G, T, vertex1, t1, t2, t3, t4, t5, vertex2);
printf("Ready for next task\n");
printf("To add data for previous five days, Press 1\n");
printf("To calculate safe path, Press 2\n");
printf("To go back to the Main Menu, Press 0\n");
}
if (m == 2)
{
int source, destination;
POINT71:
printf("Please enter the source of path: \n");
scanf("%d", &source);
printf("Please enter the destination of the path:\n");
scanf("%d", &destination);
SafeAlgorithmStart(T, G, source, destination);
printf("Ready for next task\n");
printf("To add data for previous five days, Press 1\n");
printf("To calculate safe path, Press 2\n");
printf("To go back to the Main Menu, Press 0\n");
}
POINT72:
scanf("%d", &repeat);
if (repeat == 1)
{
goto POINT70;
}
if (repeat == 2)
{
goto POINT71;
}
if(repeat==0)
{
goto MENU;
}
if (repeat != 1 || repeat != 0)
{
printf("Invalid Command! Please Enter again.\n");
goto POINT72;
}
}
if (n == 0)
{
goto MENU;
}
if (n != 0 || n != 1)
{
printf("Invalid Command! Please Enter again.\n");
goto POINT7;
}
}
if (choice == 8)
{
printf("You have selected to print the graph.\n");
printf("To continue, Press 1\n To go back to the main menu , Press 0\n");
POINT8:
scanf("%d", &n);
if (n == 1)
{
POINT81:
PrintList(G);
printf("\nSuccessfully printed the graph.\n");
printf("Do you want to print the graph again?\n");
printf("If YES, Press 1 \nIf No, Press 0\n");
POINT82:
scanf("%d", &repeat);
if (repeat == 1)
{
goto POINT81;
}
if (repeat == 0)
{
goto MENU;
}
if (repeat != 1 || repeat != 0)
{
printf("Invalid Command! Please Enter Again.\n");
goto POINT82;
}
}
if (n == 0)
{
goto MENU;
}
if (n != 0 || n != 1)
{
printf("Invalid Command! Please Enter Again.\n");
goto POINT8;
}
}
if (choice == 9)
{
printf("You have selected to print the time history table.\n");
printf("To continue, Press 1\n To go back to the main menu , Press 0\n");
POINT9:
scanf("%d", &n);
if (n == 1)
{
POINT91:
printTimeHistoryTable(T);
printf("\nSuccessfully printed the time history table. \n");
printf("Do you want to print the time history table again?\n");
printf("If YES, Press 1 \nIf No, Press 0\n");
POINT92:
scanf("%d", &repeat);
if (repeat == 1)
{
goto POINT91;
}
if (repeat == 0)
{
goto MENU;
}
if (repeat != 1 || repeat != 0)
{
printf("Invalid Command! Please Enter Again.\n");
goto POINT92;
}
}
if (n == 0)
{
goto MENU;
}
if (n != 0 || n != 1)
{
printf("Invalid Command! Please Enter Again.\n");
goto POINT9;
}
}
if (choice == 10)
{
printf("You have selected to exit the program. \n");
printf("To continue, Press 1\nTo stay in the main menu, Press 0\n");
POINT10:
scanf("%d", &n);
if (n == 1)
{
DeleteList(G);
deleteMemoryOfTable(T);
printf("Thank You, Have a nice day!\n");
goto EXIT;
}
if (n == 0)
{
goto MENU;
}
if (n != 0 || n != 1)
{
printf("Invalid Command! Please Enter Again.\n");
goto POINT10;
}
}
EXIT:
return 0;
}