-
Notifications
You must be signed in to change notification settings - Fork 0
/
hospital.nlogo
6689 lines (6351 loc) · 186 KB
/
hospital.nlogo
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
;; Differs respect 10m in replenish-stands as a task here
;; With respect 9m model chages the SNIR computation
;; 4) under construction a discrete event LBT, 6-12-2017
;; 5) I have realize that we must indicate clearly the end of TM
;; 6) I am going to adjust the "time to complete"
;; 7) compute the time to complete a group of tags redings
;; 8) going to change GO and add discrete event engine
;; 9) change begin-service
;; TEST1 is to test max-TM = 4s
;; THIS IS EQUAL TO FSA_CON_6 BUT WITH PALLET REORGANIZATION
;; There is a Pc capture and prob error.
;; The prob of capture is (1/2)^(s-1)
;; new from _03 : Power Outage
;; tags-loose-memory ----counting
;; efficiency = cs/(K)
;; TEST CONTINUOUS INVENTORY
;;
breed [ readers reader ]
;breed [ readers reader ]
breed [ checkouts checkout ]
breed [ charts chart ]
undirected-link-breed [ rris rri ]
breed [ tags tag ]
breed [ pallets pallet ]
breed [ trucks truck ]
breed [ supervisors supervisor ]
trucks-own [
pallets-in-truck
total-pallets
time-entered-queue
]
pallets-own [
num-tags-in-pallet
tags-in-pallet
still-not-inventoried ; true if pallet is being inventoried
;pallet-distance ; min ( list random normal [2,1] 3 ) or U[ 2 - 1 , 2 + 1 ] metros
; also max (list min (list random-normal 2 0.8 3) 1)
dx-to-center-of-reader
dy-to-center-of-reader
; my-truck
]
charts-own [
num-tags-in-chart
tags-in-chart
still-not-inventoried ; true if pallet is being inventoried
chart-distance ; min ( list random normal [2,1] 3 ) or U[ 2 - 1 , 2 + 1 ] metros
; also max (list min (list random-normal 2 0.8 3) 1)
time-entered-queue
]
readers-own [ ; we are serving a complete truck, at the moment
truck-being-served ; current truck occupying the server
pallet-being-served
frame frame-size my-tags
cs ce cc cs-t ce-t cc-t
TM? LM? contention? collide?
TM-time LM-time ; LM >= 0.005s, TM <=4s
efficiency throughput
num-of-collisions
; readers use 2 modes: LM, TM
next-start-LM-time ; if the reader comes from TM has to be + 0.1s
next-start-TM-time
next-completion-time
;
reader-power-tx ; fixed for my simulations 2W EIRP
reader-power-rx
;
number-of-tag-outages
;reader-height_1 ; h1 even frame
;reader-height_2 ; odd frame
reader-gain-tx-rx ;
reader-frequency ; reader carrier frequency
reader-sensitivity
reader-read-error
reader-outage-count
even-frame? ; to know alternative frames: even h1=1.4 and odd h1= 2.2
cycle ; count the periodic reading cycles of a block of pallets
tag-selection-filter ; to select a group of tags, each cycle one different
; the number of groups depends on the global interface variable 'num-tag-groups'
delta ; is the minimum number of contention trials
;
reader-type ; "io-type" "inventory-type" "sensing-type"
]
checkouts-own [ ; we are serving a complete truck, at the moment
;truck-being-served ; current truck occupying the server
;pallet-being-served
chart-being-served
frame frame-size my-tags
cs ce cc cs-t ce-t cc-t
TM? LM? contention? collide?
TM-time LM-time ; LM >= 0.005s, TM <=4s
efficiency throughput
num-of-collisions
; readers use 2 modes: LM, TM
next-start-LM-time ; if the reader comes from TM has to be + 0.1s
next-start-TM-time
next-completion-time
;
checkout-power-tx ; fixed for my simulations 2W EIRP
checkout-power-rx
;
number-of-tag-outages
checkout-height_1_tx ; _1 even frame
checkout-height_1_rx
checkout-height_2_tx ; _2 odd frame
checkout-height_2_rx
checkout-gain-tx-rx ;
checkout-frequency ; reader carrier frequency
checkout-sensitivity
checkout-read-error
checkout-outage-count
even-frame? ; to know alternative frames: even h1=1.4 and odd h1= 2.2
delta ; is the minimum number of contention trials
]
tags-own [
time-entered-queue
time-entered-service
my-inventory-slot
inventoried?
time-of-inventory
;
distance-to-checkout_1_fw ; there are two readers per docking portal
distance-to-checkout_1_bw
distance-to-checkout_2_fw
distance-to-checkout_2_bw
distance-to-reader
; the postition of the tag in the pallet
; relative to pallet-position
tag-x ; U(-0.75 , 0.75) + pallet-distance gives D of my alculations ; This is my 'D'
D_1 D_2
tag-y ; U(0.10, 1.20) This is my 'h2'
tag-z
tag-power-rx ; to see if there is a power outage or not
; which depends on R that is ( D + (h1+h2)^2 /(2D) )
tag-outage? ; it can be not powered depends of the position in the pallet
tag-gain
tag-sensitivity
q_e_rcn_fw
shadow_fw
outage-count-of-this-tag
; time-being-inventoried-first
inventoried-first?
tag-round-not-located ; count the number of times is NOT located
; next a random number given to the tag at creation
; the reader must points to them in a round robin fashion by 'tag-selection-filter'
tag-id-group
in-chart? ; 'true' if it goes in a chart, 'false' otherwise
sensor?
sample-count
tag-die-time ; only for the visitors
;my-pallet
;my-reader
person?
]
;__includes ["phiDFSA.nls"]
; show phiDFSA 50 0.02 ; N and T
supervisors-own [
next-lookup-time
product-searched ; the tag to lookup, the agent tag
cf ; count the founds
cnf ; count the not founds
; active?
]
globals [
xy-file xy-file-chk
queue-file
queue-length
num-of-queue-samples ; 1, 2, ....50
p-loss-file
p-loss-list
time-id-first-file ;to save samples of first id time of tags
time-samples-count ; to count samples of first id time of tags
;
known-file
lookup-file
;;
; Q 1..15 ; determine the number of slotSS (K= 2^Q)
t1S t1C t1E ; times of successful collision and empty slot 1
tS tC tE ; times of successful collision and empty any slot in frame 2..2^Q
min-LM max-TM TM-to-LM-time ; time limits for receiver mode plus the time after TM
tiny-num
tau ; propagation time by metre of the reader's signal
queue ; waiting line
queue-chk
arrival-count ; Arrival process (for trucks, for now)
next-arrival-time
next-departure-time ; Departure process of pallets
next-reorganization-time
next-replenish-time
;
;now the entrance of visitors and departure
next-p-arrival-time
next-p-departure-time
;
;next-lookup-time ; lookup process
; Statistics for average load/usage of queue and servers
stats-start-time
total-truck-queue-time
total-tag-queue-time
total-tag-service-time
total-truck-service-time
total-chart-queue-time
total-chart-service-time
; Statistics for average time-in-queue and time-in-service
total-time-in-queue
total-time-in-queue-chk
total-time-in-system
total-time-in-system-chk
total-queue-throughput
total-queue-throughput-chk
total-system-throughput
total-system-throughput-chk
; Theoretical measures, computed analytically using classic queueing theory
expected-utilization
expected-queue-length
expected-queue-time
; Anonymous procedures
end-run-task
arrive-task
complete-service-task
complete-service-task-chk
; reset-stats-task ; unnecessary for now
; plus
start-LM-task
start-TM-task
departure-task
lookup-task
reorganization-task
replenish-task
p-arrival-task
p-departure-task
tags-die-task
;;;
;;variables for BS reporters
total-system-throughput-sg
total-charts-thoughput-sg
total-tags-inventoried
;; next 2 vars to get the average ratio
;total-tags-singulated-sim
;total-tags-sim
average-inv-ratio
inv-count
;pallets-in-queue
;tags-in-queue
reader-utilization-percent
avg-queue-length
final-length-queue
total-num-arrivals
avg-time-queue-of-tags
avg-time-in-system-of-tags
total-simulation-time-sg
mean-num-collisions-sg
total-num-of-collisions
;; Network
mean-num-links
;;;;;; Link Budgets
empty-frames-TM
tags-loose-memory ; counts all tags that losses memory
; -----
polarz-mismatch ; X ~ 0.5
pow-tx-coefficient ; \tau ~ 1
modulation-factor ; M ~0.25 indicates the energy reflected by the tag for 0's and 1's
on-object-gain-penalty ; \Theta ~ 1.2
path-blockages ; B ~ 1
fading-factor-fw
fading-factor-bw
fading-factor-bw-a ; bistatic collocated
fading-factor-bw-b ; bistatic dislocated
;portal-width ; anchura del portal
c
;
noise-figure_dB
noise-density_dBm_Hz
max-rx-BW
rician-factor rician-factor_dB
;sigma ; std deviation of SHADOWING
;
tags-with-one-outage
tags-with-two-outage
radians-to-degrees
;
tag-with-interf-decod-well
tag-with-interf-decod-bad
tag-unique-with-errors
max-num-of-outages
total-pallets-thoughput
total-charts-throughput
total-outages
;
total-offered-load-of-charts
total-offered-load-of-tags
total-offered-load-of-tags-sg
total-offered-load-of-charts-sg
;
warehouse-capacity ; all pallets in warehouse
total-departures ; counts the num of departures
total-inventory-cycles ; counts the num of inventory cycles
;
total-lookup-errors ; errors of lookup of all supervisors
total-lookups ; total lookups of all supervisors
maxnum-fail-inventories ; total rounds of no locating a tag to declare is not known its loc.
super ; used to compute a monitor in the user interface
;
total-swaps
diameter-x
diameter-y
total-initial-tags
total-p-arrivals ; number of pallets in an arrival will be a counter
;;
num-known-samples ; to count the number of samles of inventoried-first? tags / total tags ratio
moments-of-arrivals
;
allreaders-set
sys-time-file
;
total-visitor-arrivals
total-visitor-departures
total-visitors-die
visitor-detect-count
;
avg-cycles-of-sns
avg-cycles-of-io
avg-cycles-of-inv
pb-error
;
avg-f-inv
avg-f-io
avg-f-sns
f-count
avg-utl
utl
avg-pe-io
]
;to startup
; setup
;end
to setup-timeconstants
set t1S 0.00283 set t1C 0.00074 set t1E 0.00046 ; slot 1 of PQuery
set tS 0.00258 set tC 0.00049 set tE 0.00021 ; slots 2..K of QRep
;set min-LM 0.005
set min-LM LM-group
set max-TM 4 set TM-to-LM-time 0.1 ; time limits for each mode NOW 0, BEFORE 0.1 as standards
set empty-frames-TM 0.00109 ; time threshold of 3 frames empty and Pquery empty after completition
set tiny-num 0.000000001 ; 1ns
set tau 0.000000003 ; 3ns, propagation time by metre of the reader's signal
set tags-loose-memory 0 ; to count the tags left expire the memory time.
end
to setup-globals
;set xy-file "locations200R.txt"
;set xy-file "locations20R.txt"
;set xy-file "locations50R.txt"
;set xy-file "locations1R.txt"
;set xy-file "locations3R.txt"
set xy-file (word "_readers-xy-" num-readers ".txt")
set xy-file-chk (word "_checkouts-xy-" num-checkouts ".txt")
;set queue-file (word "queue-length-" num-readers "-" mean-departure-rate "-" mean-tags-per-pallet "-" num-pallets-by-side "-" max-order-percent "-" time-between-inventories "-" ceiling-to-floor-distance ".txt")
; set queue-file (word "queue-length-" num-checkouts "-" num-readers "-" minimum-stock-level "-" time-between-inventories "-" num-of-content-intervals-inv num-of-content-intervals-io num-of-content-intervals-sns
; "-" behaviorspace-run-number ".txt")
; set num-of-queue-samples 0
; set queue-length (list )
; ;;
; ;set p-loss-file (word "p-loss-" num-readers "-" mean-departure-rate "-" mean-tags-per-pallet "-" num-pallets-by-side "-" max-order-percent "-" time-between-inventories "-" ceiling-to-floor-distance "-" behaviorspace-run-number ".txt")
; set p-loss-file (word "p-loss-" num-checkouts "-" num-readers "-" minimum-stock-level "-" time-between-inventories "-" num-of-content-intervals-inv num-of-content-intervals-io num-of-content-intervals-sns "-" behaviorspace-run-number ".txt")
; set p-loss-list (list )
; if file-exists? p-loss-file [ file-delete p-loss-file ]
; ;;
; ;set time-id-first-file (word "t-id-first-" num-readers "-" mean-departure-rate "-" mean-tags-per-pallet "-" num-pallets-by-side "-" max-order-percent "-" time-between-inventories "-" ceiling-to-floor-distance "-" behaviorspace-run-number ".txt")
; set time-id-first-file (word "t-id-first-" num-checkouts "-" num-readers "-" minimum-stock-level "-" time-between-inventories "-" num-of-content-intervals-inv num-of-content-intervals-io num-of-content-intervals-sns "-" behaviorspace-run-number ".txt")
; set time-samples-count 0 ; to count the number of samples in the file
; if file-exists? time-id-first-file [ file-delete time-id-first-file ]
; ;;
; ;set known-file (word "known-ratio-" num-readers "-" mean-departure-rate "-" mean-tags-per-pallet "-" num-pallets-by-side "-" max-order-percent "-" time-between-inventories "-" ceiling-to-floor-distance "-" behaviorspace-run-number ".txt")
; set known-file (word "known-ratio-" num-checkouts "-" num-readers "-" minimum-stock-level "-" time-between-inventories "-" num-of-content-intervals-inv num-of-content-intervals-io num-of-content-intervals-sns "-" behaviorspace-run-number ".txt")
; if file-exists? known-file [ file-delete known-file ]
; ;;
; ;set lookup-file (word "lookup-ratio" "-" num-readers "-" mean-departure-rate "-" mean-tags-per-pallet "-" num-pallets-by-side "-" max-order-percent "-" time-between-inventories "-" ceiling-to-floor-distance "-" behaviorspace-run-number ".txt")
; set lookup-file (word "lookup-ratio" "-" num-checkouts "-" num-readers "-" minimum-stock-level "-" time-between-inventories "-" num-of-content-intervals-inv num-of-content-intervals-io num-of-content-intervals-sns "-" behaviorspace-run-number ".txt")
; if file-exists? lookup-file [ file-delete lookup-file ]
; ;;
; ;set sys-time-file (word "sys-time-" num-readers "-" num-checkouts "-" mean-departure-rate "-" mean-tags-per-pallet "-" num-pallets-by-side "-" max-order-percent "-" time-between-inventories "-" ceiling-to-floor-distance "-" behaviorspace-run-number ".txt")
; set sys-time-file (word "sys-time-" num-checkouts "-" num-readers "-" minimum-stock-level "-" time-between-inventories "-" num-of-content-intervals-inv num-of-content-intervals-io num-of-content-intervals-sns "-" behaviorspace-run-number ".txt")
; if file-exists? sys-time-file [ file-delete sys-time-file ]
;;
set queue []
set queue-chk []
set next-arrival-time 0
set next-departure-time 0
;now the entrance of visitors and departure
set next-p-arrival-time 0
set next-p-departure-time 0
;
set arrival-count 0
;set-default-shape readers "square 2" ; circle
;set-default-shape checkouts "circle 2" ; circle 2
;set-default-shape readers "square 2" ; circl
set-default-shape tags "x"
set stats-start-time 0
; now the globals for the Link budget
set polarz-mismatch 0.5 ; X ~ 0.5
set pow-tx-coefficient 1 ; \tau ~ 1
set modulation-factor 0.25 ; M indicates the energy reflected by the tag for 0's and 1's
set on-object-gain-penalty 1.2
set path-blockages 1
;set fading-factor-fw 10 ;10 ; 10 for a P(outage >= 0.05 ) con K = 3dB
;set fading-factor-bw 1 ;126 ; Monostatic
;set fading-factor-bw-a 40 ; Bistatic Collated. Griffin solo dice que es menor q monostatic
;set fading-factor-bw-b 32 ; 32 Bistatic Dislocated
set fading-factor-fw 1
set fading-factor-bw 1
set fading-factor-bw-a 1
set fading-factor-bw-b 1
;set portal-width 5 ; meters or width
set c 300000000 ; speed of light
set noise-figure_dB 22
set noise-density_dBm_Hz -174
set max-rx-BW 1600000
set rician-factor_dB 3
set rician-factor (10 ^ (rician-factor_dB / 10 ) )
set sigma 1.94 ; This is the sigma for shadowing
set tags-with-one-outage 0
set tags-with-two-outage 0
set radians-to-degrees (180 / pi)
set tag-with-interf-decod-well 0 ; to count when there are 1 tag resolved well from varius
set tag-with-interf-decod-bad 0 ; to count when there are no a tag resolved well from varius
set tag-unique-with-errors 0 ; when 1 tag in a slot is bad decod.
set max-num-of-outages 5 ; before was 5
;;;
set total-offered-load-of-charts 0
set total-offered-load-of-tags 0
;;;
set warehouse-capacity ( num-readers * ( num-pallets-by-side ^ 2 ) ) ; number of pallets
set total-departures 0
set total-inventory-cycles 0
set total-lookup-errors 0
set total-lookups 0
set maxnum-fail-inventories 10
set total-swaps 0
set diameter-x 0 set diameter-y 0
set total-initial-tags (warehouse-capacity * mean-tags-per-pallet)
set total-p-arrivals 0 ; number of pallets in an arrival will be a counter
;
set num-known-samples 0
set moments-of-arrivals 0
set inv-count 0 ; to compute inv-ratio averaged
end
to setup
clear-all
;random-seed behaviorspace-run-number
if not different-seed? [random-seed 100]
reset-ticks
reset-stats
setup-globals
setup-timeconstants
ask patches [ set pcolor blue - 3 ]
setup-readers
;setup-checkouts
set allreaders-set (turtle-set readers checkouts)
setup-supervisors
setup-tasks
;reset-ticks
;reset-stats
; now we set de pallets under the reader
; with proc arrive for each reader
setup-tags-under
;schedule-arrival
schedule-departure
if swap-pallets? and (num-readers > 1) [ schedule-reorganization ]
ask supervisors [ schedule-lookup ]
schedule-replenish ; only if replenish is en event-queue
schedule-p-arrival
schedule-p-departure
end
to setup-supervisors
create-supervisors num-supervisors [
set next-lookup-time 0
set product-searched nobody
set cf 0
set cnf 0
;set active? true
set hidden? true
]
end
;to setup-checkouts
; ifelse new-netw? [
; ifelse random-topology? [
; create-checkouts num-checkouts [
; set color green ; means idle state 'red' is active
; setxy random-xcor random-ycor
; set size 3
; set cs-t 0 set cc-t 0 set ce-t 0
; set TM-time 0 set LM-time 0
; set TM? false
; set LM? false
; set contention? false
; set collide? false
; set num-of-collisions 0
; set frame 0
; set chart-being-served nobody
; set next-completion-time 0
; set checkout-gain-tx-rx 5 ; 7dBi
; set checkout-power-tx 0.8 ; 800 mW, or, 29 dBm
; set checkout-frequency (865700000) ; center frequency of Ch1
; set checkout-read-error 0
; set checkout-outage-count 0
; set checkout-height_1_tx height_1_tx; _1 even frame
; set checkout-height_1_rx height_1_rx
; set checkout-height_2_tx height_2_tx ; _2 odd frame
; set checkout-height_2_rx height_2_rx
; set even-frame? false
; set checkout-sensitivity (10 ^ (sensitivity-in-reader / 10)) / 1000 ;0.1E-10; -80 ;dBm
; set delta 1
; ]
; ] [ spawn-by-row "chk" ]
; write-readers-xy xy-file-chk "chk" ] [
; read-readers-xy xy-file-chk "chk" ]
; ;ask checkouts [ create-rris-with other (turtle-set checkouts readers) in-radius interf-rri-radius ]
; ask (turtle-set checkouts readers) [ create-rris-with other (turtle-set checkouts readers) in-radius interf-rri-radius ]
; ;ask rris [ show (10 * link-length) ]
;end
to setup-readers
ifelse new-netw? [
ifelse random-topology? [
create-readers num-readers [
set color green ; means idle state 'red' is active
setxy random-xcor random-ycor
set size 3
set cs-t 0 set cc-t 0 set ce-t 0
set TM-time 0 set LM-time 0
set TM? false
set LM? false
set contention? false
set collide? false
set num-of-collisions 0
set frame 0
set truck-being-served nobody
set pallet-being-served nobody
set next-completion-time 0
set reader-gain-tx-rx 5 ; 7dBi
set reader-power-tx 0.8 ; 800 mW, or, 29 dBm
set reader-frequency (865700000) ; center frequency of Ch1
set reader-read-error 0
set reader-outage-count 0
set even-frame? false
set cycle 0
set tag-selection-filter 0 ; [0..num-tag-groups]
set reader-sensitivity (10 ^ (sensitivity-in-reader / 10)) / 1000 ;0.1E-10; -80 ;dBm
set delta num-of-content-intervals-inv
]
] [ spawn-by-row "read" ]
write-readers-xy xy-file "rd"
] [
;read-readers-xy xy-file "rd"
]
;ask (turtle-set checkouts readers) [ create-rris-with other (turtle-set checkouts readers) in-radius interf-rri-radius ]
ask (readers with [reader-type != "io"] ) [ create-rris-with other readers in-radius interf-rri-radius ]
ask (readers with [reader-type = "io"]) [ create-rris-with other readers in-radius (interf-rri-radius + dst) ]
;ask rris [ show (10 * link-length) ]
end
to spawn-by-row [ tpe ]
; Get a range of coordinate values
let half-step 0.5 * distance-var-x
;let d-vals ( range ( min-pxcor + half-step ) ( max-pxcor ) distance-var-x )
let d-vals ( range ( min-pxcor + half-step ) ( min-pxcor + (readers-per-row * distance-var-x)) distance-var-x )
;let dc-vals ( range ( min-pycor + half-step ) ( max-pycor ) distance-var-y )
let dc-vals ( range ( min-pxcor + half-step ) ( min-pycor + (readers-per-column * distance-var-y)) distance-var-y )
; Create an empty list to build into
let possible-coords []
; For each possible vertical value, map all horizontal values in order and
; combine these into an ordered list starting at the lowest px and py coords
foreach dc-vals [
d ->
set possible-coords ( sentence possible-coords map [ i -> (list i d) ] d-vals )
]
;show (list length possible-coords possible-coords)
; Use the number of readers to sublist the possible coordinates, and
; create a turtle at each of the coordinate combinations left.
let max-positions length possible-coords
;if tpe = "read" [
if max-positions > (num-readers + num-checkouts) [
;set max-positions (num-readers + num-checkouts)
set max-positions (num-readers + readers-per-row) ; want an extra row
]
if tpe = "read" [
let use-coords sublist possible-coords 0 (max-positions) ;num-checkouts max-positions
;print use-coords
let room-count 0
foreach use-coords [
coords ->
set room-count (room-count + 1) ;show room-count
;if (room-count <= (num-readers / 2)) or (room-count > (num-readers / 2 + readers-per-row)) [
if (room-count < (floor num-readers / 4)) or ((room-count > (floor num-readers / 4) + 1) and (room-count <= (floor num-readers / 2) )) or
((room-count > (num-readers / 2 + readers-per-row)) and (room-count < (num-readers / 2 + readers-per-row + (floor num-readers / 4)))) or (room-count > (num-readers / 2 + readers-per-row + (floor num-readers / 4) + 1) ) [
create-readers 1 [
set color green ; means idle state 'red' is active
setxy item 0 coords item 1 coords
;set shape "dot"
set size 3
set cs-t 0 set cc-t 0 set ce-t 0
set TM-time 0 set LM-time 0
set TM? false
set LM? false
set contention? false
set collide? false
set num-of-collisions 0
set frame 0
set truck-being-served nobody
set pallet-being-served nobody
set next-completion-time 0
set reader-gain-tx-rx 5 ; 7dBi
set reader-power-tx 0.8 ; 800 mW, or, 29 dBm
set reader-frequency (865700000) ; center frequency of Ch1
set reader-read-error 0
set reader-outage-count 0
set even-frame? false
set cycle 0
set tag-selection-filter 0 ; [0..num-tag-groups]
set reader-sensitivity (10 ^ (sensitivity-in-reader / 10)) / 1000 ;0.1E-10; -80 ;dBm
set delta num-of-content-intervals-io
ifelse (room-count <= (num-readers / 2)) [
set reader-type "inv"
set shape "square 2"
set delta num-of-content-intervals-inv
] [
set reader-type "sns"
set shape "circle 2"
set delta num-of-content-intervals-sns
]
] ; create
] ; if room-count
;
;if (room-count = ((num-readers / 2) + 1) + 0 ) or (room-count = (num-readers / 2 + readers-per-row - 0)) [
;if (room-count >= ((num-readers / 2) + 1) + 0 ) and (room-count <= (num-readers / 2 + readers-per-row - 0)) [ ; 10R
;if (room-count = ((num-readers / 2) + 1) ) or (room-count = (num-readers / 2 + readers-per-row )) [
;if (room-count = ((num-readers / 2) + 1) + 0 ) or (room-count = ((num-readers / 2) + 1) + 2 ) or (room-count = ((num-readers / 2) + 1) + 4 ) or (room-count = ((num-readers / 2) + 1) + 6 ) or (room-count = (num-readers / 2 + readers-per-row - 0))
if (room-count = (floor (num-readers / 4) + 1) + 0 ) or (room-count = ((num-readers / 2) + 1) + 0 ) or (room-count = (num-readers / 2 + readers-per-row - 0))
or (room-count = (num-readers / 2 + readers-per-row + (floor (num-readers / 4) + 1)) )
[
create-readers 1 [
set color green ; means idle state 'red' is active
setxy item 0 coords item 1 coords
;set shape "dot"
set size 3
set cs-t 0 set cc-t 0 set ce-t 0
set TM-time 0 set LM-time 0
set TM? false
set LM? false
set contention? false
set collide? false
set num-of-collisions 0
set frame 0
set truck-being-served nobody
set pallet-being-served nobody
set next-completion-time 0
set reader-gain-tx-rx 5 ; 7dBi
set reader-power-tx 0.8 ; 800 mW, or, 29 dBm
set reader-frequency (865700000) ; center frequency of Ch1
set reader-read-error 0
set reader-outage-count 0
set even-frame? false
set cycle 0
set tag-selection-filter 0 ; [0..num-tag-groups]
set reader-sensitivity (10 ^ (sensitivity-in-reader / 10)) / 1000 ;0.1E-10; -80 ;dBm
set delta num-of-content-intervals-io
set reader-type "io"
set shape "triangle 2"
]
]
] ; foreach
] ; if
; if tpe = "chk" [
; ;if num-checkouts >= 1 [
; let use-coords sublist possible-coords 0 (num-checkouts )
; foreach use-coords [
; coords ->
; create-checkouts 1 [
; set color green ; means idle state 'red' is active
; setxy item 0 coords item 1 coords
; ;set shape "dot"
; set size 3
; set cs-t 0 set cc-t 0 set ce-t 0
; set TM-time 0 set LM-time 0
; set TM? false
; set LM? false
; set contention? false
; set collide? false
; set num-of-collisions 0
; set frame 0
; set chart-being-served nobody
; set next-completion-time 0
; set checkout-gain-tx-rx 5 ; 7dBi
; set checkout-power-tx 0.8 ; 800 mW, or, 29 dBm
; set checkout-frequency (865700000) ; center frequency of Ch1
; set checkout-read-error 0
; set checkout-outage-count 0
; set checkout-height_1_tx height_1_tx; _1 even frame
; set checkout-height_1_rx height_1_rx
; set checkout-height_2_tx height_2_tx ; _2 odd frame
; set checkout-height_2_rx height_2_rx
; set even-frame? false
; set checkout-sensitivity (10 ^ (sensitivity-in-reader / 10)) / 1000 ;0.1E-10; -80 ;dBm
; set checkout-read-error 0
; set delta 1
; ] ; create
; ] ; foreach
; ; ];if
; ] ; if chk
end
to write-readers-xy [ fxy p ]
if file-exists? fxy [ file-delete fxy ]
file-open fxy
; ifelse p = "rd" [
; ask readers [
; file-write xcor
; file-write ycor ]
; file-close
; ] [
; ask checkouts [
; file-write xcor
; file-write ycor ]
; file-close
; ]
end
;to read-readers-xy [ fxy p ]
; if file-exists? fxy [
; file-open fxy
; ifelse p = "rd" [
; while [ not file-at-end? ] [
; create-readers 1 [
; set color green ; means idle state 'red' is active
; setxy file-read file-read
; set size 3
; set cs-t 0 set cc-t 0 set ce-t 0
; set TM-time 0 set LM-time 0
; set TM? false
; set LM? false
; set contention? false
; set collide? false
; set num-of-collisions 0
; set frame 0
; set truck-being-served nobody
; set pallet-being-served nobody
; set next-completion-time 0
; set reader-gain-tx-rx 5 ; 7dBi
; set reader-power-tx 0.8 ; 800 mW, or, 29 dBm
; set reader-frequency (865700000) ; center frequency of Ch1
; set reader-read-error 0
; set reader-outage-count 0
; set even-frame? false
; set cycle 0
; set tag-selection-filter 0 ; [0..num-tag-groups]
; set reader-sensitivity (10 ^ (sensitivity-in-reader / 10)) / 1000 ;0.1E-10; -80 ;dBm
; set delta 1
; ] ; create
; ] ;while
; ] [
; while [ not file-at-end? ] [
; create-checkouts 1 [
; set color green ; means idle state 'red' is active
; setxy file-read file-read
; ;set shape "dot"
; set size 3
; set cs-t 0 set cc-t 0 set ce-t 0
; set TM-time 0 set LM-time 0
; set TM? false
; set LM? false
; set contention? false
; set collide? false
; set num-of-collisions 0
; set frame 0
; set chart-being-served nobody
; set next-completion-time 0
; set checkout-gain-tx-rx 5 ; 7dBi
; set checkout-power-tx 0.8 ; 800 mW, or, 29 dBm
; set checkout-frequency (865700000) ; center frequency of Ch1
; set checkout-read-error 0
; set checkout-outage-count 0
; set checkout-height_1_tx height_1_tx; _1 even frame
; set checkout-height_1_rx height_1_rx
; set checkout-height_2_tx height_2_tx ; _2 odd frame
; set checkout-height_2_rx height_2_rx
; set even-frame? false
; set checkout-sensitivity (10 ^ (sensitivity-in-reader / 10)) / 1000 ;0.1E-10; -80 ;dBm
; set checkout-read-error 0
; set delta 1
; ] ; create
; ] ;while
; ]
; file-close
; ]
;end
to-report random-tween-uniform [ a b ]
report ( a + random (b - a + 1) )
end
to-report random-tween [ a b ]
report a + random-float (b - a)
end
to-report frequency [ i lst ]
report length filter [? -> ? = i] lst
end
to check-queue-length-and-write
;let len length queue
;if ticks >= (150 * num-of-queue-samples) and (num-of-queue-samples <= 100) [ ; this is for max num iterations of 15000
; a max of 100 samples taken 100 ticks by 100 ticks
if ticks >= (10 * num-of-queue-samples) and (num-of-queue-samples <= 1000) [ ; this is for max num iterations of 10000
;if ticks >= (100 * num-of-queue-samples) and (num-of-queue-samples <= 100) [ ; this is for max num iterations of 10000
; if each 500 then <= 50; it depends of the max-num-of-iterations this example are 25000
let len length queue-chk
;let pallets-in-queue ( sum map [i -> [total-pallets] of i ] queue-chk ) ; total pallets in queue
;let tags-in-queue ( sum map [ i -> sum [ [ num-tags-in-pallet ] of pallets-in-truck ] of i ] queue-chk ) ; total tags in queue
let tags-in-queue (sum map [i -> [num-tags-in-chart] of i ] queue-chk)
;set queue-length lput (list ticks len pallets-in-queue tags-in-queue ) queue-length
set queue-length lput (list ticks len tags-in-queue ) queue-length
set num-of-queue-samples (num-of-queue-samples + 1)
]
end
to write-queue-file [ f-queue ]
if file-exists? f-queue [ file-delete f-queue ]
file-open f-queue
foreach range ( length queue-length ) [ ? ->
file-write ( first item ? queue-length ) ;the time ticks
file-write ( item 1 item ? queue-length ) ; the length of the queue
;file-write ( item 2 item ? queue-length ) ; total pallets in queue
file-write ( last item ? queue-length ) ; total tags in queue
file-print ""
]
file-close
end
to-report sigmoid [f a b]
report (1 / ( 1 + (exp (-1 * a * f + b) ) ) )
end
to compute-utl-averages
ifelse ticks >= 10 [
let f-sns (mean [cycle] of readers with [reader-type = "sns"] / ticks)
set avg-f-sns ((avg-f-sns) * (f-count - 1) + f-sns) / f-count
let f-io (mean [cycle] of readers with [reader-type = "io"] / ticks)
set avg-f-io ((avg-f-io) * (f-count - 1) + f-io) / f-count
let f-inv (mean [cycle] of readers with [reader-type = "inv"] / ticks)
set avg-f-inv ((avg-f-inv) * (f-count - 1) + f-inv) / f-count
; let a1 0.488272 let b1 2.6855
; let a2 48.8272 let b2 2.6855
; let a3 4842.72 let b3 2.6855
let a1 8.7889 let b1 10.9861
let a2 8.7889 let b2 6.59167
let a3 439.445 let b3 21.9722
set utl ((sigmoid f-sns a1 b1) * (sigmoid f-io a2 b2) * (sigmoid f-inv a3 b3))
set avg-utl ((avg-utl) * (f-count - 1) + utl) / f-count
let pe-io (ifelse-value (total-visitors-die > 0) [1 - (visitor-detect-count / total-visitors-die)][0])
set avg-pe-io ((avg-pe-io) * (f-count - 1) + pe-io) / f-count
set f-count (f-count + 1)
] [
set f-count (f-count + 1)
]
end
to check-frequencies-and-utl
if ticks >= (10 * f-count) [
compute-utl-averages
]
end
to check-known-samples-and-write
; take a sample each 100 seconds or 10 seconds
;if ticks >= (100 * num-known-samples) and (num-known-samples <= 10000) [ ; this is for max num iterations of 15000
if ticks >= (10 * num-known-samples) and (num-known-samples <= 10000) [ ; this is for max num iterations of 15000
write-known-tags-ratio "0"
set num-known-samples ( num-known-samples + 1 )
]
write-known-tags-ratio "1"
end
;; Sets up anonymous procedures for event queue
to setup-tasks
set end-run-task [[?ignore] -> end-run]
; new
;set arrive-task [[?ignore] -> arrive-chart] ; change 'arrive' to 'arrive-chart' (in each call does 'arrive-task nobody' to create a truck)
;
set start-LM-task [[?reader] -> start-LM ?reader]
set start-TM-task [[?reader] -> start-TM ?reader]
set complete-service-task [[?reader] -> complete-service ?reader]
;new:
;set complete-service-task-chk [[?checkout] -> complete-service-chk ?checkout]
;
set departure-task [[?ignore] -> departure]
set lookup-task [[?supervisor] -> lookup ?supervisor]
set reorganization-task [[?ignore] -> reorganization]
;set reset-stats-task [[?ignore] -> reset-stats]
;set replenish-task [[?ignore] -> replenish-stands]
set p-arrival-task [[?ignore] -> visitor-arrival]
set p-departure-task [[?ignore] -> visitor-departure]
set tags-die-task [[?tags] -> tags-die ?tags]
end
;;
to go
set total-inventory-cycles min [ cycle ] of readers
ifelse ticks < max-run-time [;and total-inventory-cycles <= 50 [;and ( length queue <= 1000) [
;ifelse total-inventory-cycles <= max-inventory-cycles [
;ifelse total-lookups < max-lookups [
;ifelse arrival-count <= max-num-of-arrivals [
;
;check-queue-length-and-write
;check-known-samples-and-write
check-frequencies-and-utl
;
let next-event []
let event-queue (list (list max-run-time end-run-task nobody)) ; ---OJO do not coment this lline
;[[500000 (anonymous command from: procedure SETUP-TASKS: [end-run]) nobody]]
let next-reader-to-complete next-reader-complete ; reader with min of next-completion-time
;;;--
; ; -- Next the GO of continuous:
; show event-queue
; [[0.2196804243547807 (anonymous command from: procedure SETUP-TASKS: [arrive]) nobody] [500000 (anonymous......
if (is-turtle? next-reader-to-complete) [ ; la primera vez no pq es 'nobody'
set event-queue (fput
(list
([next-completion-time] of next-reader-to-complete)
complete-service-task
next-reader-to-complete)
event-queue)
]
;;;;
let next-reader-to-start-LM next-reader-LM
if (is-turtle? next-reader-to-start-LM) [
set event-queue (fput
(list
([next-start-LM-time] of next-reader-to-start-LM)
start-LM-task
next-reader-to-start-LM)
event-queue)
]
let next-reader-to-start-TM next-reader-TM
if (is-turtle? next-reader-to-start-TM) [
set event-queue (fput
(list
([next-start-TM-time] of next-reader-to-start-TM)
start-TM-task
next-reader-to-start-TM)
event-queue)
]
;;;-------------
; departures? OFF in this case
if departures? [
set event-queue (
fput (list next-departure-time departure-task nobody) event-queue )
]
;;;-------------
set event-queue (
fput (list next-p-arrival-time p-arrival-task nobody) event-queue )
set event-queue (
fput (list next-p-departure-time p-departure-task nobody) event-queue )
;;;-------------
;set event-queue (
; fput (list next-replenish-time replenish-task nobody) event-queue )
;
if swap-pallets? and (num-readers > 1) [
set event-queue (
fput (list next-reorganization-time reorganization-task nobody) event-queue )
]
;
let next-supervisor-to-lookup next-supervisor
set super next-supervisor-to-lookup
; ask next-supervisor-to-lookup [
; if next-lookup-time < (3 * 60) [ set next-lookup-time ( next-lookup-time + 180 + random-float 30 ) ]
; ]
if (is-turtle? next-supervisor-to-lookup) [