-
Notifications
You must be signed in to change notification settings - Fork 0
/
iMain.cpp
1468 lines (996 loc) · 27.6 KB
/
iMain.cpp
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
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# include "iGraphics.h"
# include <string.h>
#include <limits.h>
int flag_bfs=0;
int flag_dfs=0;
int flag_mst=0;
int flag_dijkstra=0;
int simulation_image=1;
int stage_1=0;
int stage_2=0;
int stage_3=0; //flow control variables
int stage_4=0;
int stage_5=0;
int source_choose_stage=1;
int source_D,dest_D;
int weighted=0;
int flag_D=0;
//text field data start
int char_flag=0; //text field variables
int char_top=-1;
#define char_MAX 30
int max_char=char_MAX;
int flag_off=1;
int flag_textfield=1;
int char_x=10;
unsigned long long numgen(void);
void blink_control(void);
int image_flag=0;
unsigned long long int value=0;
struct stack
{
char num[2];
double pos;
}stack[50];
void iText_Field(char* text)
{
//TEXT FIELD PORTION START
iSetcolor(0,0,64);
iFilledRectangle(0,20,640,80);
iSetcolor(255,255,255);
iFilledRectangle(320,30,310,60);
iText(20,40,text,GLUT_BITMAP_TIMES_ROMAN_24);
iSetcolor(0,0,0);
if(char_top>=0)
for(int i=0;i<=char_top;i++)
iText(stack[i].pos,50,stack[i].num,GLUT_BITMAP_TIMES_ROMAN_24); //printing the numbers
if(char_flag==0)
{
iLine(char_x+315,80,315+char_x,35); //blinking portion
char_flag=1;
}
}
//text field data finish
//graph input data start
int cost;
int flag=0;
//graph variables , vertex adding
#define MAX 100
int selection_flag1=-1;
int selection_flag2=-1;
int select_source=-1;
int count_edge=1;
int node_count=1;
#define MAX_NODE 100
unsigned long long int vertex_num,edge_num;
int adj_mat[MAX_NODE][MAX_NODE];
void adj_mat_print(void);
//graph input data finish
/// DFS data start
int dfs_stack[MAX_NODE];
int visited[MAX_NODE];
int dfs_top=-1;
int save_visited[MAX_NODE][MAX_NODE];
int iter_dfs=1;
int dfs_count=1;
int dfs_path[MAX_NODE][MAX_NODE];
struct dfs_track
{
int node;
int prev_node;
}dfs_track[MAX_NODE];
void pop(void)
{
if(dfs_top>=0)
{ int top_val=dfs_stack[dfs_top--];
return;
}
}
void push(int n)
{
dfs_stack[++dfs_top]=n;
}
void print_stack(void)
{
printf("\n\n");
for(int i=dfs_top;i>=0;i--)
printf("%d\n",dfs_stack[i]);
printf("\n\n");
}
void dfs(int source_node)
{
visited[source_node]=-1;
save_visited[iter_dfs][1]=source_node;
push(source_node);
print_stack();
while(dfs_top!=-1)
{
for(int i=1;i<=vertex_num;i++)
for(int j=1;j<=vertex_num;j++)
{
if(adj_mat[source_node][j]!=0 && visited[j]!=-1)
{
push(j);
visited[j]=-1;
dfs_track[++iter_dfs].node=j;
dfs_track[iter_dfs].prev_node=source_node;
save_visited[iter_dfs][1]=j;
print_stack();
source_node=j;
break;
}
}
int flag_b=0;
for(int i=1;i<vertex_num;i++)
if(adj_mat[source_node][i])
{
if(visited[i]!=-1)
{flag_b=1;
break;
}
}
if(!flag_b)
pop();
source_node=dfs_stack[dfs_top];
}
printf("\n\n");
for(int i=1;i<=iter_dfs;i++)
for(int j=1;j<=i;j++)
dfs_path[i][j]=save_visited[j][1];
for(int i=1;i<=iter_dfs;i++)
{for(int j=1;j<=vertex_num;j++)
printf("%d\t",dfs_path[i][j]);
printf("\n");
}
}
void dfs_count_control(void)
{
if((dfs_count>=1 && dfs_count<=iter_dfs+1) && stage_5==1)
dfs_count++;
}
//dfs data finish
//bfs data start
int visited_bfs[MAX_NODE];
int queue[MAX_NODE];
int queue_front=0;
int queue_count=0;
int iter_bfs=1;
int visit_index=0;
int save_visited_bfs[MAX_NODE][MAX_NODE];
int save_source_bfs[MAX_NODE][MAX_NODE];
int iter_pos=1;
int black_mat[MAX_NODE][MAX_NODE];
int grey_mat[MAX_NODE][MAX_NODE];
int count_bfs=1;
int dequeue(void)
{
if(queue_count!=0)
{
int front_val=queue[queue_front];
queue_front = (queue_front+1) % vertex_num;
queue_count--;
return front_val;
}
}
void enqueue(int n)
{
if(( queue_count-queue_front)!=vertex_num)
{
queue[((queue_count+queue_front) % vertex_num)]=n;
queue_count++;
}
}
void print_queue(void)
{
printf("\n\n\n");
for(int i=0;i<queue_count;i++)
printf("%d\n",queue[(queue_front+i)% vertex_num]);
printf("\n\n\n\n");
}
void bfs(int source_node_bfs)
{
enqueue(source_node_bfs);
while((queue_count)!=0)
{
visit_index=1;
source_node_bfs=dequeue();
save_source_bfs[iter_bfs][1]=source_node_bfs;
visited_bfs[source_node_bfs]=-1;
for(int i=1;i<=vertex_num;i++)
{
if(adj_mat[source_node_bfs][i]!=0 && visited_bfs[i]!=-1)
{
enqueue(i);
save_visited_bfs[iter_bfs][visit_index++]=i;
visited_bfs[i]=-1;
}
}
print_queue();
iter_bfs++;
}
for(int i=1;i<=iter_bfs;i++)
for(int j=1;j<=i;j++)
black_mat[i][j]=save_source_bfs[j][1];
printf("\n\n\n Source save:\n\n\n");
for(int i=1;i<=vertex_num;i++)
{for(int j=1;j<=vertex_num;j++)
printf("%d\t",black_mat[i][j]);
printf("\n");
}
printf("\n\n\n");
printf("Visit Save:\n\n\n");
for(int i=1;i<=vertex_num;i++)
{for(int j=1;j<=vertex_num;j++)
printf("%d\t",save_visited_bfs[i][j]);
printf("\n");
}
}
void bfs_count_control(void)
{
if((count_bfs>=1 && count_bfs<=iter_bfs+1) && stage_5==1)
count_bfs++;
}
//bfs data finish
//dijkstra data start
#define INFINITY 1<<16
#define BLACK 1 //flags
#define GREY 2
int iter_dijkstra=1;
int count_dijkstra=1;
int dijkstra_over=0;
int iter_track=1;
struct node_cost
{
int cost;
int color;
} node_cost[MAX_NODE][MAX_NODE];
struct Dijsktra_path_track
{
int node;
int prev_node;
}track_path_D[MAX_NODE];
int shortest_path[MAX_NODE]; //for taking Graph as input
int path_length=0;
int path_mat[MAX_NODE];
typedef struct VERTEX //vertex properties required for Dijkstra's algorithm
{
int previous_node;
int color;
unsigned long long int distance;
}VERTEX;
int Dijkstra(int source_node , int dest_node )
{
int nodes=1 , i , temp_path[MAX_NODE];
VERTEX path_info[MAX_NODE];
for(int i=1;i<=vertex_num;i++) //initializing the structure pat_info //sob gula re grey kore dilam , r distance infinity kore dilam
{
path_info[i].distance=INFINITY;
path_info[i].color=GREY;
node_cost[iter_dijkstra][i].color=GREY;
node_cost[iter_dijkstra][i].cost=-1;
}
path_info[source_node].color=BLACK; //source node blacked out kore , er distance zero kore dilum
path_info[source_node].distance=0;
path_info[source_node].previous_node=0;
node_cost[iter_dijkstra][source_node].color=BLACK;
node_cost[iter_dijkstra][source_node].cost=0;
iter_dijkstra++;
do
{
for(int i=1;i<=vertex_num;i++) //initializing the structure pat_info //sob gula re grey kore dilam , r distance infinity kore dilam
{
node_cost[iter_dijkstra][i].color=node_cost[iter_dijkstra-1][i].color;
node_cost[iter_dijkstra][i].cost=node_cost[iter_dijkstra-1][i].cost;
}
for(i=1;i<=vertex_num;i++)
{ if(adj_mat[source_node][i]>0 && path_info[i].color==GREY)
{
if((path_info[source_node].distance+adj_mat[source_node][i])< path_info[i].distance)
{
path_info[i].distance=path_info[source_node].distance+adj_mat[source_node][i];
path_info[i].previous_node=source_node;
node_cost[iter_dijkstra][i].cost=path_info[i].distance;
}
}
}
int min=INFINITY,i;
source_node=0;
for(i=1;i<vertex_num+1;i++)
if((path_info[i].color==GREY) && (path_info[i].distance<min))
{source_node=i;
min=path_info[i].distance;
}
if(source_node==0) //shesh iteration e source_node==0 hobena (mone hote pare je , shesh iteration e sob gulo black tai source_node er value 0 thake , but asole sob gula black hobena):D cause shesh iteration e , source_node==dest_node hobe
return 0;
path_info[source_node].color=BLACK;
node_cost[iter_dijkstra][source_node].color=BLACK;
iter_dijkstra++;
}while(source_node!=dest_node);
/** path_mat genarate kore , minimum path_distance ber kora and last e node_num pass kora nicher portion er intended kaj**/
int temp_mat[MAX_NODE];
source_node=dest_node;
int iter_path=vertex_num;
do
{ temp_mat[nodes]=source_node;
track_path_D[iter_path].node=source_node;
track_path_D[iter_path--].prev_node=path_info[source_node].previous_node;
source_node=path_info[source_node].previous_node;
nodes++;
}while(source_node!=0);
for(i=1;i<nodes;i++)
path_mat[i]=temp_mat[nodes-i];
for(int i=1;i<vertex_num;i++)
path_length+=adj_mat[path_mat[i]][path_mat[i+1]];
printf("Minimum Path:\n");
for(int i=1;i<nodes;i++)
printf("%d\t",path_mat[i]); //printing path_mat
printf("\n\n");
printf("Minimum Length = %d\n",path_length);
for(int i=1;i<=vertex_num;i++) //the simulation structure
{for(int j=1;j<=vertex_num;j++)
printf("%d\|%d ",node_cost[i][j].color,node_cost[i][j].cost);
printf("\n\n");
}
return nodes;
}
void dijkstra_count_control(void)
{
if((count_dijkstra>=1 && count_dijkstra<=iter_dijkstra) && stage_5==1)
count_dijkstra++;
}
void dijkstra_track_control(void)
{
if((iter_track>=1 && iter_track<=vertex_num) && dijkstra_over==1)
iter_track++;
}
//dijkstra data finish
//minimum spanning tree data start
int mst_complete=0;
int iter_mst=1;
int count_mst;
struct track_mst
{
int node;
int prev_node;
}track_mst[MAX_NODE];
int minKey(int key[], int mstSet[])
{
int min = INT_MAX, min_index;
for (int v = 1; v <= vertex_num; v++)
if (mstSet[v] == 0 && key[v] < min)
min = key[v], min_index = v;
return min_index;
}
void printMST(int parent[], int n, int adj_mat[MAX_NODE][MAX_NODE])
{
printf("Edge Weight\n");
for (int i = 2; i <=vertex_num; i++)
{printf("%d - %d %d \n", parent[i], i, adj_mat[i][parent[i]]);
track_mst[i].node=parent[i];
track_mst[i].prev_node=i;
count_mst++;
}
mst_complete=1;
}
void primMST(void)
{
int parent[MAX_NODE]; // Array to store constructed MST
int key[MAX_NODE]; // Key values used to pick minimum weight edge in cut
int mstSet[MAX_NODE]; // To represent set of vertices not yet included in MST
for (int i = 1; i <= vertex_num; i++)
key[i] = INT_MAX, mstSet[i] = 0;
key[1] = 0;
parent[1] = -1;
for (int count = 1; count < vertex_num; count++)
{
int u = minKey(key, mstSet);
mstSet[u] = 1;
for (int v = 1; v <=vertex_num; v++)
if (adj_mat[u][v] && mstSet[v] == 0 && adj_mat[u][v] < key[v])
{
parent[v] = u;
key[v] = adj_mat[u][v];
}
}
printMST(parent, vertex_num, adj_mat);
}
void mst_count_control(void)
{
if((iter_mst>=1 && iter_mst<=count_mst+1) && stage_5==1 && mst_complete==1)
iter_mst++;
}
//minimum spanning tree data finish
struct co_ordinates //vertex co-ordinates
{
double x;
double y;
int no;
}graph_nodes[MAX];
struct connections //edges(v_x,v_y) edgese between vertex 'x' and vertex 'y'
{
int v_x;
int v_y;
char cost[10];
}edges[MAX];
//number to string generator
char str_rev[100];
void num_to_string(int n)
{
char str[100];
int i=0;
while(n>0)
{
str[i++]=(n%10)+'0';
n/=10;
}
int len=i-1;
i=0;
while(len>=0)
{
str_rev[i++]=str[len--];
}
str_rev[i]='\0';
}
void Simulation_display(void)
{
iClear();
iSetcolor(0,0,255);
iFilledRectangle(0,735,1366,100);
iSetcolor(0,0,0);
iText(350,750,"GRAPH ALGORITHM SIMULATION",GLUT_BITMAP_HELVETICA_18);
iSetcolor(0,10,0);
iFilledRectangle(280,590,400,50);
iSetcolor(0,128,128);
iFilledRectangle(300,600,400,50);
iSetcolor(0,0,0);
iText(350,615,"Breadth First Search",GLUT_BITMAP_HELVETICA_18);
iSetcolor(0,10,0);
iFilledRectangle(280,440,400,50);
iSetcolor(0,128,128);
iFilledRectangle(300,450,400,50);
iSetcolor(0,0,0);
iText(350,465,"Depth First Search",GLUT_BITMAP_HELVETICA_18);
iSetcolor(0,10,0);
iFilledRectangle(280,290,400,50);
iSetcolor(0,128,128);
iFilledRectangle(300,300,400,50);
iSetcolor(0,0,0);
iText(350,315,"Minimum Spanning Tree(Prim)",GLUT_BITMAP_HELVETICA_18);
iSetcolor(0,10,0);
iFilledRectangle(280,140,400,50);
iSetcolor(0,128,128);
iFilledRectangle(300,150,400,50);
iSetcolor(0,0,0);
iText(350,165,"Dijkstra's Shortest Path",GLUT_BITMAP_HELVETICA_18);
}
void Create_Display(void)
{
iClear();
iSetcolor(0,0,255);
iFilledRectangle(0,0,160,1366);
iSetcolor(10,255,20);
iFilledRectangle(0,735,1366,100);
iSetcolor(255,1,1);
iText(300,750,"GRAPH ALGORITHM SIMULATION",GLUT_BITMAP_HELVETICA_18);
iSetcolor(0,100,255);
iRectangle(5,635,150,50); //Create Graph
iSetcolor(255,1,1);
iText(7,650,"CREATE GRAPH",GLUT_BITMAP_HELVETICA_18);
iSetcolor(0,100,255);
iRectangle(5,100,100,50); //Quit
iSetcolor(255,1,1);
iText(25,115,"QUIT",GLUT_BITMAP_HELVETICA_18);
}
/*
function iDraw() is called again and again by the system.
*/
void iDraw()
{
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _*/
//printf("flag = %d\n",flag);
//Main Display is shown and options are given to choose 1.Create A Graph , 2. Exit
if(!image_flag)
{
iSetcolor(0,0,0);
iFilledRectangle(0,0,1366,100);
}
if(simulation_image)
{
Simulation_display();
}
if(image_flag)
{
Create_Display();
}
//this portion will not be displayed after a choice selection has been made
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _*/
//printf("%d %d %d\n",stage_1,stage_2,stage_4);
//stage-1 starts when stage_1==1, taking vertex_num from user
if(stage_1)
{
iClear();
iText_Field("Enter Vertex Number:");
vertex_num=value;
if(vertex_num)
{
printf("Vertex num: %llu\n",vertex_num);
stage_1=0;
stage_2=1;
value=0;
}
}
//stage_1 finishes here , vertex_num has been taken , now stage_1==0 and stage_2==1
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _*/
//now , stage_2==1 so stage_2 starts , value for edge_num is taken here
if(stage_2)
{
iClear();
iText_Field("Enter Edge Number:");
edge_num=value;
if(edge_num)
{ printf("Edge num: %llu\n",edge_num);
stage_2=0;
flag=0;
value=0;
iClear();
stage_3=1;
}
}
//stage_2 finishes here , edge_num has been taken , now stage_2==0 , stage_3==1
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _*/
//this code_block is stage_3 , this is kept open , because the created nodes are always shown
for(int i=1;i<=count_edge;i++)
{
iSetcolor(0,0,1);
iLine(graph_nodes[edges[i].v_x].x,graph_nodes[edges[i].v_x].y,graph_nodes[edges[i].v_y].x,graph_nodes[edges[i].v_y].y);
iSetcolor(1,0,0);
iText((graph_nodes[edges[i].v_x].x+graph_nodes[edges[i].v_y].x)/2,(graph_nodes[edges[i].v_x].y+graph_nodes[edges[i].v_y].y)/2,edges[i].cost,GLUT_BITMAP_HELVETICA_18);
}
for(int i=1;i<=node_count;i++)
{ iSetcolor(259,259,259);
iFilledCircle(graph_nodes[i].x,graph_nodes[i].y,15,200);
iSetcolor(0,0,100);
num_to_string(graph_nodes[i].no);
iText(graph_nodes[i].x-25,graph_nodes[i].y,str_rev,GLUT_BITMAP_8_BY_13); //node creation print
//place your drawing codes here
}
//code for stage_3 finishes here , but this code block will run until the program has done it's job and it terminates
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _*/
//Stage_4 , is the pair-wise node selection part
iSetcolor(0,0,1);
if(count_edge<=edge_num)
{
if(selection_flag1>=0)
{ iSetcolor(0,0,1);
iCircle(graph_nodes[selection_flag1].x,graph_nodes[selection_flag1].y,12,200); //node selection print
}
if(selection_flag2>=0)
{
iCircle(graph_nodes[selection_flag2].x,graph_nodes[selection_flag2].y,12,200);
}
}
//printf("Count edge==%d\n",count_edge);
/*stage_4 cost taking portion*/
if(stage_4==1)
{
if(weighted)
{
iText_Field("Enter Cost For This Edge:");
cost=value;
if(cost)
{
printf("Cost = %d\n",cost);
adj_mat[edges[count_edge].v_x][edges[count_edge].v_y]=cost; //inserting cost to adj[i][j] and adj[j][i] indices
adj_mat[edges[count_edge].v_y][edges[count_edge].v_x]=cost;
num_to_string(cost);
strcpy_s(edges[count_edge].cost,str_rev);
iSetcolor(1,0,0);
flag=1;
stage_4=0;
cost=0;
value=0;
count_edge++;
}
}
else if(weighted==0)
{
//printf("%d %d %d\n\n",count_edge,edges[count_edge].v_x,edges[count_edge].v_y);
adj_mat[edges[count_edge].v_x][edges[count_edge].v_y]=1; //inserting cost to adj[i][j] and adj[j][i] indices
adj_mat[edges[count_edge].v_y][edges[count_edge].v_x]=1;
flag=1;
stage_4=0;
count_edge++;
iClear();
}
}
if(count_edge==edge_num+1 && stage_4==0 && edge_num!=0)
{
if(source_choose_stage)
{
if(flag_dfs==1)
{
iText_Field("Enter Source Node:");
source_D=value;
if(source_D>0)
{
dfs(source_D);
source_choose_stage=0;
stage_5=1;
iClear();
value=0;
stage_4=2;
}
}
else if(flag_bfs==1)
{
iText_Field("Enter Source Node:");
source_D=value;
if(source_D>0)
{
bfs(source_D);
source_choose_stage=0;
stage_5=1;
iClear();
value=0;
stage_4=2;
}
}
else if(flag_dijkstra==1)
{
if(!flag_D)
{
iText_Field("Enter Source Node:");
source_D=value;
printf("Destination node %d\n",source_D);
if(source_D>0)
flag_D=1;
value=0;
}
else if(flag_D==1)
{
iClear();
iText_Field("Enter Destination Node:");
dest_D=value;
printf("Destination node %d\n",dest_D);
if(dest_D>0)
flag_D=2;
}
else if(flag_D==2)
{ iClear();
Dijkstra(source_D,dest_D);
source_choose_stage=0;
stage_5=1;
value=0;
stage_4=2;
}
}
else if(flag_mst==1)
{primMST();
stage_5=1;
stage_4=2;
}
}
}
if(dijkstra_over)
{
if(iter_track!=vertex_num+1)
{
for(int i=1;i<=iter_track;i++)
{
if(track_path_D[i].node!=0 && track_path_D[i].prev_node!=0)
{
iSetcolor(1,0,0);
iSetcolor(0,1,0);
iLine(graph_nodes[track_path_D[i].node].x,graph_nodes[track_path_D[i].node].y,graph_nodes[track_path_D[i].prev_node].x,graph_nodes[track_path_D[i].prev_node].y);
iFilledCircle(graph_nodes[track_path_D[i].node].x,graph_nodes[track_path_D[i].node].y,12);
iFilledCircle(graph_nodes[track_path_D[i].prev_node].x,graph_nodes[track_path_D[i].prev_node].y,12);
}
}
}
}