-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathklassen.cpp
1522 lines (1396 loc) · 59 KB
/
klassen.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 "initial_situation.cpp"
#include <stddef.h>
#include <iostream>
#include <time.h>
#include <stdio.h>
#include <vector>
#include <math.h>
#include <time.h>
#include <stdlib.h>
using namespace std;
class obstacle
{
public:
// constructors
obstacle(){};
obstacle(int nx, int ny, int q_obst, int q_dest, int q_pers){
x = nx;
y = ny;
setrgb(200,200,200);
quantity_obstacles = q_obst;
quantity_destinations = q_dest;
quantity_persons = q_pers;
};
obstacle(int nx, int ny, int f1, int f2, int f3, int q_obst, int q_dest, int q_pers){
x = nx;
y = ny;
setrgb(f1,f2,f3);
quantity_obstacles = q_obst;
quantity_destinations = q_dest;
quantity_persons = q_pers;
};
// constructors
// methods
void setrgb(int f1, int f2, int f3){
r = f1;
g = f2;
b = f3;
};
void moveto(int xn, int yn){
x = xn;
y = yn;
}
bool is_it_here(int qx, int qy){// has the object the coordinates (qx,qy) ?
if (x == qx && y == qy){
return true;
}
else {
return false;
}
}
// methods
//quantities
int quantity_obstacles;
int quantity_destinations;
int quantity_persons;
//coordinates
int x;
int y;
//colour
int r;
int g;
int b;
private:
};
//##################################################################################################################################
//##################################################################################################################################
class destination
{
public:
// constructors
destination(){};
destination(int a, int b,vector<obstacle> &obstvec, int q_obst, int q_dest, int q_pers){
x = a;
y = b;
setrgb(0,200,0);
quantity_obstacles = q_obst;
quantity_destinations = q_dest;
quantity_persons = q_pers;
if(corridor_conditions == false){
set_static_field_k(obstvec); //wird für den Fall des Korridors nicht benötigt
}
};
destination(int a, int b, int f1, int f2, int f3,vector<obstacle> &obstvec, int q_obst, int q_dest, int q_pers){
x = a;
y = b;
setrgb(f1,f2,f3);
quantity_obstacles = q_obst;
quantity_destinations = q_dest;
quantity_persons = q_pers;
if(corridor_conditions == false){
set_static_field_k(obstvec); //wird für den Fall des Korridors nicht benötigt
}
};
// constructors
// methods
void setrgb(int f1, int f2, int f3){
r = f1;
g = f2;
b = f3;
};
void moveto(int xn, int yn){
x = xn;
y = yn;
}
bool is_it_here(int qx, int qy){// has the object the coordinates (qx,qy) ?
if (x == qx && y == qy){
return true;
}
else {
return false;
}
}
// methods
//quantities
int quantity_obstacles;
int quantity_destinations;
int quantity_persons;
//coordinates
int x;
int y;
//coordinates
//colour
int r;
int g;
int b;
//colour
//Static field Sk, which is created by this destination:
int S_k[grid_width][grid_height];
bool could_a_person_go_to (int qx, int qy, vector<obstacle> &obstvec){//delivers true, if the person could stay at (x,y)/ could move to this cell
//###cells out of borders arent available for a person:
if ((qy >= grid_height) || (qx >= grid_width)){
return false;
}
if ((qy < 0) || (qx < 0)){
return false;
}
//###cells filled by an obstacle isnt available for a person:
bool return_value = true;
for(int i = 0; i < quantity_obstacles; i++){
//cout << "x: " << obstvec[i].x << ", y: " << obstvec[i].y << endl;
if((obstvec[i].x == qx) && (obstvec[i].y == qy)){
return_value = false;
}
}
return return_value;
}
vector<int> to_do;
vector<int> processed;
void set_static_field_k(vector<obstacle> &obstvec){
//Setzt alle Einträge von S_k auf 0
for(int g = 0; g < grid_width; g++){
for(int h = 0; h< grid_height; h++){
S_k[g][h] = 0;
}
}
//Trägt Anfangskoorinaten in den vector ein
to_do.push_back(x);
to_do.push_back(y);
int counter = 0;
while(true){
// sichert die aktuelle Größe des vectors to_do für die nächste for-Schleife
int ntodo = to_do.size();
if (ntodo % 2 != 0){//Fehleranzeige, falls was schief läuft
cout << "Ein Fehler ist augetreten! die Anzahl ntodo ist nicht durch zwei teilbar." << endl;
}
for(int j = 0; j < (ntodo / 2); j++){
//Schriebe das zugehörige Potential in das statische Feld:
S_k[to_do[0]][to_do[1]] = counter;
//cout << S_k[8][8] << endl;
//if(counter == 3){print_S_k();}
//Diese Koordinaten sind nun abgearbeitet und werden dem vector processed übergeben
processed.push_back(to_do[0]);
processed.push_back(to_do[1]);
//Suche Nachbarn für das Feld S_k mit den Koordinaten (to_do[0],to_do[1}) und schreibe diese in den vector to_do
int nh[8] = {//sind alle möglichen Nachbarn
to_do[0],to_do[1] + 1,
to_do[0] + 1,to_do[1],
to_do[0],to_do[1] - 1,
to_do[0] - 1,to_do[1]
};
for (int l = 0; l < 4; l++){//für jeden möglichen Nachbarn folgt:
if (could_a_person_go_to(nh[2*l],nh[2*l+1],obstvec) == false){// wenn eine Person hier nicht drauf darf
//cout << "Nicht erlaubte Felder could: " << nh[2*l]<< ";" << nh[2*l+1] <<endl;
continue;
}
//Ist der aktuell ausgewählte Nachbar schon im Vector processed oder to_do enthalten:
int con = false;
for(int a = 0; a < processed.size()/2; a++){
if (processed[2*a] == nh[2*l] && processed[2*a+1] == nh[2*l+1]){
con = true;
}
}
for(int b = 1; b < to_do.size()/2; b++){
if(to_do[2*b] == nh[2*l] && to_do[2*b+1] == nh[2*l+1]){
con = true;
}
}
if(con == true){
continue;
}
to_do.push_back(nh[2*l]);
to_do.push_back(nh[2*l+1]);
}
//Lösche nun die bearbeiteten Koordinaten (to_do[0],to_do[1])
to_do.erase(to_do.begin());
to_do.erase(to_do.begin());
}
if(to_do.size() == 0){
break;
}
counter++;
}
//Potentialfeld besitzt am Ausgang das größte Potential und nimmt von da an ab; also Werte müssen noch "umgekehrt" werden:
//Finden des größten Eintrags in S_k:
int max_pot = 0;
for(int i = 0; i < grid_width; i++){
for(int j = 0; j < grid_height; j++){
if(S_k[i][j] > max_pot){
max_pot = S_k[i][j];
}
}
}
//"umkehren" der Einträge: also Potential verläuft vom Eingang aus gesehen von groß nach klein
for(int i = 0; i < grid_width; i++){
for(int j = 0; j < grid_height; j++){
if(could_a_person_go_to(i,j,obstvec)){
S_k[i][j] = max_pot - S_k[i][j];
}
}
}
}
int get_S_k(int x, int y){
return S_k[x][y];
}
void print_S_k(){
cout << "----------------------------------------------------------------" << endl;
for(int j = 0; j < grid_height; j++){
for(int i = 0; i < grid_width; i++){
if (S_k[i][j] > 9 && S_k[i][j] <= 99){cout << " " << S_k[i][j] << ";" ;}
else if (S_k[i][j] > 99){cout << S_k[i][j] << ";" ;}
else {cout << " " << S_k[i][j] << ";" ;}
}
cout << endl;
}
}
//fuer das vereinigen der Ziele:
vector <int> dest_neighbours;
private:
};
//##################################################################################################################################
//##################################################################################################################################
class person
{
public:
// constructors
person(){};
person(int nx, int ny,vector<destination> &destvec, int q_obst, int q_dest, int q_pers){
x = nx;
y = ny;
ax = x;
ay = y;
aax = ax;
aay = ay;
int colour_variation = (rand() % 150) - 75; //leichte Farbvariation, damit die einzelnen Personen voneinander unterschieden werden können
setrgb(0,0,150 + colour_variation);
quantity_obstacles = q_obst;
quantity_destinations = q_dest;
quantity_persons = q_pers;
//###Zu set_w_S
int p_d[1]; //bevorzugtes Ziel
p_d[0] = rand() % quantity_destinations; // bevorzugtes Ziel wird zufällig ausgewählt
set_w_S(true,1,p_d, rand() % (quantity_destinations) + 1); //die Person kennt also mindestens eines der Ziele sehr gut .. der Rest wird zufällig entschieden
if(corridor_conditions == false){
set_S_normal(destvec);
}
set_D_on_zero();
//Zufälliges setzen des "Friction" Parameters:
friction = (rand() % 300) / 1000;
evacuated = false;
number_of_conflicts = 0;
};
person(int nx, int ny, int f1, int f2, int f3,vector<destination> &destvec, int q_obst, int q_dest, int q_pers){
x = nx;
y = ny;
ax = x;
ay = y;
aax = ax;
aay = ay;
setrgb(f1,f2,f3);
quantity_obstacles = q_obst;
quantity_destinations = q_dest;
quantity_persons = q_pers;
//###Zu set_w_S
int p_d[1]; //bevorzugtes Ziel
p_d[0] = rand() % quantity_destinations; // bevorzugtes Ziel wird zufällig ausgewählt
set_w_S(true,1,p_d, rand() % (quantity_destinations) + 1); //die Person kennt also mindestens eines der Ziele sehr gut .. der Rest wird zufällig entschieden
if(corridor_conditions == false){
set_S_normal(destvec);
}
set_D_on_zero();
//Zufälliges setzen des "Friction" Parameters:
friction = (rand() % 300) / 1000;
evacuated = false;
number_of_conflicts = 0;
};
// constructors
// methods
void setrgb(int f1, int f2, int f3){
r = f1;
g = f2;
b = f3;
};
double friction = 0.0; // Wahrscheinlichkeit, dass sich die Person nicht bewegt, obwohl sie sich bewegen sollte
void moveto(int xn, int yn, bool after_conflict=false){
double r = (rand() % 1000) / 1000.0; // Zufallszahl
if((evacuated == false && r >= friction) || (evacuated == false && after_conflict == false)){//Wenn die vor der Bewegung kein Konflikt stattgefunden hat wird die Bewegung auf jeden Fall ausgeführt; mit Konflikt nur zu einer bestimmten Wahrscheinlichkeit, die von der "friction" abhängt
//set_D(persvec, xn, yn, propability_arr_diff, propability_arr_dec, obstvec); -> jetzt in update_objekt_parameter
aax = ax;
aay = ay;
ax = x;
ay = y;
x = xn;
y = yn;
}
}
bool is_it_here(int qx, int qy){
if (x == qx && y == qy){
return true;
}
else {
return false;
}
}
bool could_I_go_to (int qx, int qy, vector<obstacle> &obstvec, vector<person> &persvec){//delivers true, if the person could stay at (x,y)/ could move to this cell
//###cells out of borders arent available for a person:
if ((qy >= grid_height) || (qx >= grid_width)){
return false;
}
if ((qy < 0) || (qx < 0)){
return false;
}
//###cells filled by a person arent available for a person:
if(is_there_a_person_on(qx,qy,persvec)){
return false;
}
//###cells filled by an obstacle arent available for a person:
bool return_value = true;
for(int i = 0; i < quantity_obstacles; i++){
//cout << "x: " << obstvec[i].x << ", y: " << obstvec[i].y << endl;
if((obstvec[i].x == qx) && (obstvec[i].y == qy)){
return_value = false;
}
}
// in all other cases:
return return_value;
}
bool is_there_a_person_on(int qx, int qy,vector<person> &persvec){
for(int i = 0; i < quantity_persons; i++){
if(qx == persvec[i].x && qy == persvec[i].y){
return true;
}
}
return false;
}
void print_coords(){
cout <<endl << "Ich bin bei x: " << x << "y: " << y << endl;
}
// methods
//quantities
int quantity_destinations;
int quantity_obstacles;
int quantity_persons;
//coordinates
int x;
int y;
//alte Koordinaten
int ax;
int ay;
//alte Koordinate der alten Koordinaten
int aax;
int aay;
//letzte Bewegungsrichtung
char last_movement_direction;
//vorletzte Bewegungsrichtung
char a_last_movement_direction;
char set_last_movement_direction(int ax, int ay, int jx, int jy){ //ax steht für "altes x", jx fuer "jetziges x", setzt die Variable last_movement_direction
if(jx > ax){
//Fehlerueberpruefung: ist die Bewegung genau 1 lang?:
if (jx != ax + 1 && evacuated == false && corridor_conditions ==false){
cout << "Fehler: Die Person hat sich nicht exakt um 1 bewegt,1" << endl;
}
if(jy != jy && evacuated == false&& corridor_conditions ==false){
cout << "Fehler: Bewegung der Person wurde falsch ausgeführt; x und y Koordinaten wurden gleichzeitig verändert" << endl;
}
return 'r';
}
else if(jx < ax){
//Fehlerueberpruefung: ist die Bewegung genau 1 lang?:
if (jx != ax - 1 && evacuated == false&& corridor_conditions ==false){
cout << "Fehler: Die Person hat sich nicht exakt um 1 bewegt,2" << endl;
}
if(jy != jy && evacuated == false&& corridor_conditions ==false){
cout << "Fehler: Bewegung der Person wurde falsch ausgeführt; x und y Koordinaten wurden gleichzeitig verändert" << endl;
}
return 'l';
}
else if(jy > ay){
//Fehlerueberpruefung: ist die Bewegung genau 1 lang?:
if (jy != ay + 1 && evacuated == false&& corridor_conditions ==false){
cout << "Fehler: Die Person hat sich nicht exakt um 1 bewegt,3" << endl;
}
if(jx != jx && evacuated == false&& corridor_conditions ==false){
cout << "Fehler: Bewegung der Person wurde falsch ausgeführt; x und y Koordinaten wurden gleichzeitig verändert" << endl;
}
return 'u';
}
else if(jy < ay){
//Fehlerueberpruefung: ist die Bewegung genau 1 lang?:
if (jy != ay - 1 && evacuated == false&& corridor_conditions ==false){
cout << "Fehler: Die Person hat sich nicht exakt um 1 bewegt,4" << endl;
}
if(jx != jx && evacuated == false&& corridor_conditions ==false){
cout << "Fehler: Bewegung der Person wurde falsch ausgeführt; x und y Koordinaten wurden gleichzeitig verändert" << endl;
}
return 'o';
}
else{//Person ist stehen geblieben
return 's';
}
}
//colour
int r;
int g;
int b;
// ###### Dynamic floor field DZur Uni Potsdam(Brandenburg):
double k_D = 1;
int panic_par;
int iterat_val;
int D[grid_width][grid_height];
void set_D_on_zero()
{
//setzt D feld auf null
for (int i = 0; i < grid_width; i++)
{
for(int j = 0; j < grid_height; j++){
D[i][j] = 0;
}
}
}
void set_D_3 (vector <person> &persvec, int j)
{
if (k_D!=0)
{
for (int i=0; i< persvec.size(); i++) //gehe alle personen durch
{
if (i!=j) ///nicht von der eigenen spur beeinflussen
{
if((reject_other_D_fields == true && followed_the_pers_my_S(persvec[i],2) == true) || reject_other_D_fields == false) ///bei mehreren zielen kann eine spur nur entstehen wenn die person in die gleich richtung laeuft
{
if ((persvec[i].ax!=persvec[i].x || persvec[i].ay!=persvec[i].y) && persvec[i].evacuated == false) /// überprüfe ob sich die person i bewegt hat
{
persvec[j].D[persvec[i].ax][persvec[i].ay]++;
}
}
if (followed_the_pers_my_S(persvec[i], 2)==false && reject_other_D_fields ==true) ///bei mehreren zielen kann, wenn eine pers von mir weg läuft, diese person mein d feld in die richtung der person kauputtmachen (--)
{
if ((persvec[i].ax!=persvec[i].x || persvec[i].ay!=persvec[i].y) && persvec[i].evacuated == false) /// überprüfe ob sich die person i bewegt hat
{
persvec[j].D[persvec[i].ax][persvec[i].ay]--;
}
}
/*
else
{
cout << "Fehler in set_D" << endl;
}*/
}
}
}
}
void decay_dyn_f(vector <int> &propability_arr_dec, vector <person> &persvec, int i)
{
if(decay_param == 0){return;}
bool grid_full=true;
//geht die gesamte fläche durch
for (int x=0; x< grid_width; x++)
{
for (int y=0; y<grid_height; y++)
{
int d_abs_beginn = abs(persvec[i].D[x][y]);
for (int j=0; j<d_abs_beginn; j++) ///je staerker das d feld am puntk x y ist, desto stärker kann es zerfallen
{
//zerfall des d Feldes:
//-----------------------------
//schreibe wahrscheinlichkeitsarray
for (int k=0; k < propability_arr_dec.size(); k++)
{
propability_arr_dec[k]=0;
}
if (decay_param!=0)
{
for (int k=0; k<decay_param ; k++)
{
propability_arr_dec[k]=1;
}
}
/*if (i==1)
{
cout << "Person " << i << " hat die Koordinaten: (x;y) = " << "(" << persvec[i].x << ";" << persvec[i].y << ")" << endl;
cout << "D-Feld von Person "<< i << " ungleich null am Punkt: (x;y) = " <<"("<<x<<";"<<y<<")" << endl;
cout << "############################" << endl;
}*/
//generiere zufällige zahl und überprüfe ob d feld zerfallen soll
int r_2=rand()%100;
if (propability_arr_dec[r_2]==1) //verifikation: D feld soll sich auflösen
{
//if (/*falls 1 Nachbar frei ist*/ persvec[i].D[x][y+1]==0 || persvec[i].D[x][y-1]==0 || persvec[i].D[x+1][y]==0 || persvec[i].D[x-1][y]==0 || /*falls 2 Nachbarn frei sind*/ persvec[i].D[x+1][y]==persvec[i].D[x][y+1]==0 || persvec[i].D[x-1][y]==persvec[i].D[x][y+1]==0 || persvec[i].D[x-1][y]==persvec[i].D[x][y-1]==0 || persvec[i].D[x+1][y]==persvec[i].D[x][y-1]==0 || /*falls 3 Nachbarn frei sind*/ persvec[i].D[x-1][y]==persvec[i].D[x][y+1]==persvec[i].D[x+1][y]==0 || persvec[i].D[x][y-1]==persvec[i].D[x-1][y]==persvec[i].D[x][y+1]==0 || persvec[i].D[x-1][y]==persvec[i].D[x][y-1]==persvec[i].D[x+1][y]==0 || persvec[i].D[x][y-1]==persvec[i].D[x+1][y]==persvec[i].D[x][y+1]==0)
//{
/*if (i==1)
{
cout << "-------------------------------------------" << endl;
cout << "Zerfall findet bei Person "<< i<< " am Punkt: (x;y) = " <<"("<<x<<";"<<y<<") statt."<< endl;
cout << "--------------------------------------------" << endl;
}*/
if(persvec[i].D[x][y] > 0){
persvec[i].D[x][y]--;
}
else{
persvec[i].D[x][y]++;
}
//grid_full=false;
//}
/*
//falls das d feld komplett voll ist, zerfällt es trz iwo am rand
if (grid_full==true)
{
int x_rand = rand () %grid_width;
int y_rand = rand () %grid_height;
int which_side = rand() %4;
switch (which_side)
{
case 0:
persvec[i].D[0][y_rand]=0;
case 1:
persvec[i].D[x_rand][0]=0;
case 2:
persvec[i].D[grid_width-1][y_rand]=0;
case 3:
persvec[i].D[x_rand][grid_height-1]=0;
}
}
*/
}
}
}
}
}
void diffusion_dyn_f(vector <int > &propability_arr_diff, vector <person> &persvec, int xn, int yn, int i, vector<obstacle> &obstvec, vector <int> &propability_arr_dec)
{
if(diffusion_param == 0){return;}
bool grid_full=true;
//gehe ganzen grundriss durch und überprüfe ob sich das d feld verteilen soll
for (int x=0; x< grid_width; x++)
{
for (int y=0; y<grid_height; y++)
{
for (int k=0; k<abs(persvec[i].D[x][y]); k++) ///je stärker das d feld desto schneller kann es sich verteilen
{
//Verteilung des D-Felds
//------------
//schreibe wahrscheinlichkeitsarray
for (int k=0; k <propability_arr_diff.size(); k++)
{
propability_arr_diff[k]=0;
}
if (diffusion_param!=0)
{
for (int k=0; k<diffusion_param ; k++)
{
propability_arr_diff[k]=1;
}
}
//generiere zufallszahl und überprüfe ob sich das d feld verteilen soll
int r_1=rand () %100;
if (propability_arr_diff[r_1]==1) //verifikation: D feld soll sich verteilen
{
int which_cell=rand ()%4; //zu welcher zelle propagiert das d-feld?
if (which_cell==0)
{
if (x-1!=xn && y!=yn)
{
if (can_d_field_be_here(x-1, y, obstvec)==true)
{
if (persvec[i].D[x][y]>0)
{
persvec[i].D[x-1][y]++;
//persvec[i].D[x][y]--; ///d feld verwischt
}
else
{
persvec[i].D[x-1][y]--;
//persvec[i].D[x][y]++; ///d feld verwischt
}
}
grid_full=false;
}
else if (x+1!=xn && y!=yn)
{
if (can_d_field_be_here(x+1, y, obstvec)==true)
{
if (persvec[i].D[x][y]>0)
{
persvec[i].D[x+1][y]++;
//persvec[i].D[x][y]--; ///d feld verwischt
}
else
{
persvec[i].D[x+1][y]--;
//persvec[i].D[x][y]++; ///d feld verwischt
}
}
grid_full=false;
}
else if (x!=xn && y-1!=yn)
{
if (can_d_field_be_here(x, y-1, obstvec)==true)
{
if (persvec[i].D[x][y]>0)
{
persvec[i].D[x][y-1]++;
//persvec[i].D[x][y]--; ///d feld verwischt
}
else
{
persvec[i].D[x][y-1]--;
//persvec[i].D[x][y]++; ///d feld verwischt
}
}
grid_full=false;
}
else if (x!=xn && y+1!=yn)
{
if (can_d_field_be_here(x, y+1, obstvec)==true)
{
if (persvec[i].D[x][y]>0)
{
persvec[i].D[x][y+1]++;
//persvec[i].D[x][y]--; ///d feld verwischt
}
else
{
persvec[i].D[x][y+1]--;
//persvec[i].D[x][y]++; ///d feld verwischt
}
}
grid_full=false;
}
}
else if (which_cell==1)
{
if (x+1!=xn && y!=yn)
{
if (can_d_field_be_here(x+1, y, obstvec)==true)
{
if (persvec[i].D[x][y]>0)
{
persvec[i].D[x+1][y]++;
//persvec[i].D[x][y]--; ///d feld verwischt
}
else
{
persvec[i].D[x+1][y]--;
//persvec[i].D[x][y]++; ///d feld verwischt
}
}
grid_full=false;
}
else if (x!=xn && y-1!=yn)
{
if (can_d_field_be_here(x, y-1, obstvec)==true)
{
if (persvec[i].D[x][y]>0)
{
persvec[i].D[x][y-1]++;
//persvec[i].D[x][y]--; ///d feld verwischt
}
else
{
persvec[i].D[x][y-1]--;
//persvec[i].D[x][y]++; ///d feld verwischt
}
}
grid_full=false;
}
else if (x!=xn && y+1!=yn)
{
if (can_d_field_be_here(x, y+1, obstvec)==true)
{
if (persvec[i].D[x][y]>0)
{
persvec[i].D[x][y+1]++;
//persvec[i].D[x][y]--; ///d feld verwischt
}
else
{
persvec[i].D[x][y+1]--;
//persvec[i].D[x][y]++; ///d feld verwischt
}
}
grid_full=false;
}
else if (x-1!=xn && y!=yn)
{
if (can_d_field_be_here(x-1, y, obstvec)==true)
{
if (persvec[i].D[x][y]>0)
{
persvec[i].D[x-1][y]++;
//persvec[i].D[x][y]--; ///d feld verwischt
}
else
{
persvec[i].D[x-1][y]--;
//persvec[i].D[x][y]++; ///d feld verwischt
}
}
grid_full=false;
}
}
else if (which_cell==2)
{
if (x!=xn && y-1!=yn)
{
if (can_d_field_be_here(x, y-1, obstvec)==true)
{
if (persvec[i].D[x][y]>0)
{
persvec[i].D[x][y-1]++;
//persvec[i].D[x][y]--; ///d feld verwischt
}
else
{
persvec[i].D[x][y-1]--;
//persvec[i].D[x][y]++; ///d feld verwischt
}
}
grid_full=false;
}
else if (x!=xn && y+1!=yn)
{
if (can_d_field_be_here(x, y+1, obstvec)==true)
{
if (persvec[i].D[x][y]>0)
{
persvec[i].D[x][y+1]++;
//persvec[i].D[x][y]--; ///d feld verwischt
}
else
{
persvec[i].D[x][y+1]--;
//persvec[i].D[x][y]++; ///d feld verwischt
}
}
grid_full=false;
}
else if (x-1!=xn && y!=yn)
{
if (can_d_field_be_here(x-1, y, obstvec)==true)
{
if (persvec[i].D[x][y]>0)
{
persvec[i].D[x-1][y]++;
//persvec[i].D[x][y]--; ///d feld verwischt
}
else
{
persvec[i].D[x-1][y]--;
//persvec[i].D[x][y]++; ///d feld verwischt
}
}
grid_full=false;
}
else if (x+1!=xn && y!=yn)
{
if (can_d_field_be_here(x+1, y, obstvec)==true)
{
if (persvec[i].D[x][y]>0)
{
persvec[i].D[x+1][y]++;
//persvec[i].D[x][y]--; ///d feld verwischt
}
else
{
persvec[i].D[x+1][y]--;
//persvec[i].D[x][y]++; ///d feld verwischt
}
}
grid_full=false;
}
}
else if (which_cell==3)
{
if (x!=xn && y+1!=yn)
{
if (can_d_field_be_here(x, y+1, obstvec)==true)
{
if (persvec[i].D[x][y]>0)
{
persvec[i].D[x][y+1]++;
//persvec[i].D[x][y]--; ///d feld verwischt
}
else
{
persvec[i].D[x][y+1]--;
//persvec[i].D[x][y]++; ///d feld verwischt
}
}
grid_full=false;
}
else if (x-1!=xn && y!=yn)
{
if (can_d_field_be_here(x-1, y, obstvec)==true)
{
if (persvec[i].D[x][y]>0)
{
persvec[i].D[x-1][y]++;
//persvec[i].D[x][y]--; ///d feld verwischt
}
else
{
persvec[i].D[x-1][y]--;
//persvec[i].D[x][y]++; ///d feld verwischt
}
}
grid_full=false;
}
else if (x+1!=xn && y!=yn)
{
if (can_d_field_be_here(x+1, y, obstvec)==true)
{
if (persvec[i].D[x][y]>0)
{
persvec[i].D[x+1][y]++;
//persvec[i].D[x][y]--; ///d feld verwischt
}
else
{
persvec[i].D[x+1][y]--;
//persvec[i].D[x][y]++; ///d feld verwischt
}
}
grid_full=false;
}
else if (x!=xn && y-1!=yn)
{
if (can_d_field_be_here(x, y-1, obstvec)==true)
{
if (persvec[i].D[x][y]>0)
{
persvec[i].D[x][y-1]++;
//persvec[i].D[x][y]--; ///d feld verwischt
}
else
{
persvec[i].D[x][y-1]--;
//persvec[i].D[x][y]++; ///d feld verwischt
}
}
grid_full=false;
}
}
}
}
}
}
if (grid_full==true && diffusion_param !=0) //sollte nicht passieren, vermeidet fehler
{
decay_dyn_f(propability_arr_dec, persvec, i);
}
}
bool can_d_field_be_here (int qx, int qy, vector<obstacle> &obstvec)
{
//delivers true, if the d field could stay at (x,y)/ could move to this cell
//###cells out of borders arent available for d feld:
if ((qy >= grid_height) || (qx >= grid_width))
{
return false;
}
if ((qy < 0) || (qx < 0))
{
return false;
}
//###cells filled by an obstacle arent available for d feld:
for(int i = 0; i < quantity_obstacles; i++)
{
if((obstvec[i].x == qx) && (obstvec[i].y == qy))
{
return false;
}
}
return true;
}
void set_panic_par(vector <person> &persvec, int i, int iteration)
{
if(panik_aktiviert == false){return;} // wenn der Panik Parameter nicht beachtet werden soll, wird diese Funktion abgebrochen
if (iteration==0)
{
persvec[i].iterat_val=0;
}
///rising panic parameter
if (persvec[i].had_a_conflict==true)
{
persvec[i].panic_par++;
persvec[i].iterat_val=persvec[i].iteration;
/*r=0;
g=255;
b=0;*/
}
///zerfall vom panikparameter