-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathASIMOV.nlogo
2143 lines (1820 loc) · 64.9 KB
/
ASIMOV.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
;;=====================================================================================================================================================================================
;;=====================================================================================================================================================================================
;;;
;;; A S I M O V
;;;
;;=====================================================================================================================================================================================
;;=====================================================================================================================================================================================
;;==========================================================================================================================================
;; V A R I A B L E I N I T I A L I Z A T I O N
;;==========================================================================================================================================
;;Create animats and assign qualities
globals [Addiction_Cycle_Phase switch_time stop_time hermi-color flab-color drug-color]
breed [Cslugs Cslug]
breed [nociceptors nociceptor] ;ie the pain receptors
breed [probos proboscis]
breed [flabs flab]
breed [hermis hermi]
breed [fauxflabs fauxflab]
breed [drugs drug]
Cslugs-own [ Somatic_Map App_State App_State_Switch ExpReward_pos ExpReward_neg Incentive Nutrition Satiation speed turn-angle
sns_betaine sns_betaine_left sns_betaine_right sns-pain-left sns-pain-right sns-pain-caud sns-pain spontaneous-pain pain pain-switch
Vh sns_hermi sns_hermi_left sns_hermi_right alpha_hermi beta_hermi lambda_hermi delta_Vh hermcount hermcount_history
Vf sns_flab sns_flab_left sns_flab_right alpha_flab beta_flab lambda_flab delta_Vf flabcount fauxflabcount flabcount_history
Vd sns_drug sns_drug_left sns_drug_right delta_Vd alpha_drug beta_drug lambda_drug drugcount drugcount_history drug_reward
R R_hermi R_flab R_drug RewardExperience deg_sensitization IN M M0 W1 W2 W3 dW3 W4 W5 RewardExperience_history
]
nociceptors-own [parent painval id hit]
probos-own [parent phase]
patches-own [odor_flab odor_hermi odor_betaine odor_drug]
to startup
setup
end
;-----------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------
;;==========================================================================================================================================
;; S E T U P P R O C E D U R E S
;;==========================================================================================================================================
to setup
clear-all
; sets up first phase of Addiction Cycle, to be used when Addiction_Cycle is turned ON
set Addiction_Cycle_Phase "No Drug"
;set switch_time 15000
set switch_time 15000
set stop_time 60000; was 150000
set hermi-color 85
set flab-color 135
set drug-color 45
;---------------------------------------------------------------------------------
; Spawns a Cslug
;---------------------------------------------------------------------------------
create-Cslugs 1 [
;sets shape, size, color, and position of pleuro
set shape "Cslug" ; "octo"
set color orange - 2
set size 16
set heading 0
;creates 7 sensors for pain detection
repeat 7 [
hatch-nociceptors 1 [
set hidden? true
set shape "dot"
set size 3
set parent myself
let idnum ((count nociceptors) mod 7)
let labels ["snsrOL" "snsrOR" "snsrUL" "snsrUR" "snsrBL" "snsrBR" "snsrBM"]
set id (item idnum labels)
if id = "snsrOL"[
set hidden? false
]
if id = "snsrOR"[
set hidden? false
]
]
]
;updates pain sensor position
update-nociceptor-position
;sets baseline spontaneous pain activity
set spontaneous-pain 2
;sets initial values for feeding network variables (nutrition, incentive salience, somatic map, and satiation)
set Nutrition 0.5
set Incentive 0
set Somatic_Map 0
set Satiation 0.5
;sets initial habituation/sensitization parameters for Homeostatic Reward Circuit (HRC):
set W1 1
set W2 0.2
set W3 1
set W4 0.1
set W5 0.1
set M0 10 ;Baseline activity for M
;set R_drug 0.5
set drug_reward 30
set drugcount_history [];
set hermcount_history [];
set flabcount_history [];
set RewardExperience_history [];
;Preliminary Rescorla-Wagner parameters for learning Hermi & Flab odors. V is learned value of an odor, alpha is the salience
;(or noticeability) of an odor, beta is the learning rate, and lambda sets the maximum value of learning (between 0 and 1).
set Vf 0
set Vh 0
set Vd 0
set alpha_hermi 0.5
set beta_hermi 1
set lambda_hermi 1
set alpha_flab 0.5
set beta_flab 1
set lambda_flab 1
set alpha_drug 0.5
set beta_drug 1
set lambda_drug 1
;Give Cslug a feeding apparatus for decorative effect
hatch-probos 1 [
set shape "airplane"
set size size / 2
set parent myself
]
;Track Cslug's path
pen-down
]
;---------------------------------------------------------------------------------
; Spawns Prey and Drug
;---------------------------------------------------------------------------------
if Presentation-Mode = false[
;creates flabellina prey
create-flabs flab-populate [
set shape "circle"
set size 1
set color flab-color
setxy random-xcor random-ycor
]
;creates hermissenda prey
create-hermis hermi-populate [
set shape "circle"
set size 1
set color hermi-color
setxy random-xcor random-ycor
]
;creates faux flabellina prey
; create-fauxflabs fauxflab-populate [
; set shape "circle"
; set size 1
; set color blue
; setxy random-xcor random-ycor
; ]
;creates drug
create-drugs drug-populate [
set shape "circle"
set size 1
set color drug-color
setxy random-xcor random-ycor
]
]
reset-ticks
end
;-----------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------
;;==========================================================================================================================================
;; U P D A T E P R O C E D U R E S
;;==========================================================================================================================================
to go
;---------------------------------------------------------------------------------
; User Actions
;---------------------------------------------------------------------------------
;; allow user to drag things around
if mouse-down? [
ask Cslugs [
if distancexy mouse-xcor mouse-ycor < 3 [setxy mouse-xcor mouse-ycor]
]
ask flabs [
if distancexy mouse-xcor mouse-ycor < 3 [setxy mouse-xcor mouse-ycor]
]
ask hermis [
if distancexy mouse-xcor mouse-ycor < 3 [setxy mouse-xcor mouse-ycor]
]
ask drugs [
if distancexy mouse-xcor mouse-ycor < 3 [setxy mouse-xcor mouse-ycor]
]
]
;---------------------------------------------------------------------------------
; Updates Prey and Drug Populations
;---------------------------------------------------------------------------------
ifelse Presentation-Mode[
if count hermis > 1 [ask hermis [die]]
if count flabs > 1 [ask flabs [die]]
if count fauxflabs > 1 [ask fauxflabs[die]]
if count drugs > 1 [ask drugs [die]]][
create-flabs flab-populate - count flabs [
set shape "circle"
set size 1
set color flab-color
setxy random-xcor random-ycor
]
if flab-populate < count flabs [
ask n-of (count flabs - flab-populate) flabs [die]
]
create-hermis hermi-populate - count hermis [
set shape "circle"
set size 1
set color hermi-color
setxy random-xcor random-ycor
]
if hermi-populate < count hermis [
ask n-of (count hermis - hermi-populate) hermis [die]
]
; create-fauxflabs fauxflab-populate - count fauxflabs [
; set shape "circle"
; set size 1
; set color blue
; setxy random-xcor random-ycor
; ]
if not Addiction_Cycle[
create-drugs drug-populate - count drugs [
set shape "circle"
set size 1
set color drug-color
setxy random-xcor random-ycor
]
if drug-populate < count drugs [
ask n-of (count drugs - drug-populate) drugs [die]
]
]
]
;---------------------------------------------------------------------------------
; Updates Odors
;---------------------------------------------------------------------------------
; Initialize, deposit, diffuse, and evaporate odors
ask hermis [set odor_hermi 0.5]
ask hermis [set odor_betaine 0.5]
ask flabs [set odor_flab 0.5]
ask flabs [set odor_betaine 0.5]
ask fauxflabs [set odor_flab 0.5]
ask fauxflabs [set odor_betaine 0.5]
ask drugs [set odor_drug 0.5]
;; diffuse odors
diffuse odor_hermi 0.5
diffuse odor_flab 0.5
diffuse odor_betaine 0.5
diffuse odor_drug 0.5
;; evaporate odors
ask patches [
set odor_hermi 0.95 * odor_hermi
set odor_flab 0.95 * odor_flab ; changed from 0.98 to 0.95
set odor_betaine 0.95 * odor_betaine
set odor_drug 0.95 * odor_drug
recolor-patches
]
;=================================================================================
;
; Cslug Actions (update of Cslug variables)
;
;=================================================================================
ask Cslugs [
;updates sensor values and locations, see function below for details
update-sensors
;updates proboscis and pleurobranchaea movement
update-proboscis
set speed 0.3
set turn-angle -1 + random-float 2
;------------------------------------------------------;
; Sets values for odor and pain sensation
;------------------------------------------------------;
;; Detecting prey and pain
set sns_hermi (sns_hermi_left + sns_hermi_right ) / 2
set sns_betaine (sns_betaine_left + sns_betaine_right) / 2
set sns_flab (sns_flab_left + sns_flab_right ) / 2
set sns_drug (sns_drug_left + sns_drug_right ) / 2
set sns-pain ((sns-pain-left + sns-pain-right ) / 2)
; ;if the drug type is heroin, if consumed, it will directly suppress pain sensation.
; ;(This suppression effect will decay over time after the drug consumption.)
; set h-suppression 0.99 * h-suppression
;sets an upper limit for pain (via logistic function).
; Note that for creating the pain response map, apply_pain was set at 10
set pain 10 / (1 + e ^ (- 2 * (sns-pain + spontaneous-pain) + 10 ))
;pain-switch will switch the signs of Reward State and Pain in Appetitive State when Pain is greater than Reward State
; (Effectively, this causes pain and reward state to be in reciprocal inhibition.
; In the presence of enough pain, positive rewards will ease the effect of pain,
; while negative rewards will exacerbate it.)
;set pain-switch 2 / (1 + e ^ (- 7 * (RewardExperience - pain + 2.1))) - 1;
;set pain-switch 1 - 2 / (1 + e ^ (- 10 * (sns-pain - 0.7)));
set pain-switch 1 - 2 / (1 + e ^ (- 10 * (sns-pain - 0.2)));
;-----------------------------------------------------------------;
; APPROACH AND AVOIDANCE BEHAVIORS
;=================================================================;
;------------------------------------------------------;
; Sets positive and negative expected reward
;------------------------------------------------------;
;sets positive expected reward (based on satiation, sns-betaine, sns-hermi, sns-drug, associative value for sns-hermi, and associative value for sns-drug)
set ExpReward_pos sns_betaine / (1 + (0.05 * Vh * sns_hermi) - 0.006 / Satiation) + 3.0 * Vh * sns_hermi + 8.0 * Vd * sns_drug;
;set ExpReward_pos sns_betaine / (4 - 0.032 / Satiation) + 0.33 * Vh * sns_hermi + 2.5 * Vd * sns_drug;
;sets negative reward (based on pain, sns-flab, and associative value for for sns-flab)
;set ExpReward_neg 0.33 * Vf * sns_flab; + pain; R-
set ExpReward_neg 0.59 * Vf * sns_flab; + pain; R-
; sets decrease in nutrition, satiation (based only on nutrition), and incentive salience (based on positive and negative reward)
set Nutrition Nutrition - 0.0005 * Nutrition ; Nutritional state declines with time
ifelse Fix-var1: [set Satiation fix-satiation] [set Satiation 1 / ((1 + 0.7 * exp(-4 * Nutrition + 2)) ^ (2))]
set Incentive ExpReward_pos - ExpReward_neg;
;------------------------------------------------------;
; Sets Somatic Map
;------------------------------------------------------;
;; Exponent variables for somatic map, which basically determine interaction and "priority" of the sensations
let H (sns_hermi - sns_flab - sns_drug - sns-pain)
let F (sns_flab - sns_hermi - sns_drug - sns-pain)
let D (sns_drug - sns_hermi - sns_flab - sns-pain)
let P (pain)
;; sets somatic map variable, transforms sensory input into a "place code"
set Somatic_Map (- ((sns_flab_left - sns_flab_right) / (1 + exp (-50 * F)) + (sns_hermi_left - sns_hermi_right) / (1 + exp (-50 * H)) + (sns_drug_left - sns_drug_right) / (1 + exp (-50 * D))+(sns-pain-left - sns-pain-right)/(1 + exp (-50 * P))))
;------------------------------------------------------;
; Sets Appetitive State
;------------------------------------------------------;
; sets Appetitve State
;set App_State 0.01 + (1 / (1 + exp(- (0.75 * Incentive - 9 * satiation - 1.8 * pain-switch * (RewardExperience - Pain) ))) + 0.1 * ((App_State_Switch - 1) * 0.5)); + 0.25
set App_State 0.01 + (1 / (1 + exp(- (0.75 * Incentive - 9 * satiation - 1.8 * Pain - 1.8 * pain-switch * RewardExperience))) + 0.1 * ((App_State_Switch - 1) * 0.5)); + 0.25
; The switch for approach-avoidance
set App_State_Switch (((-2 / (1 + exp(-100 * (App_State - 0.245)))) + 1))
;;set speed
set speed 0.3
;set the turning angle based on appetitive state switch and somatic map
set turn-angle (2 * App_State_Switch) / (1 + exp (3 * Somatic_Map)) - App_State_Switch
rt turn-angle
; if the immobilize switch is ON, then fixes Cslug in place, but it can still turn (for testing purposes)
ifelse immobilize = true[
fd 0
][
fd speed
]
;-----------------------------------------------------------------;
; PREY AND DRUG CONSUMPTION
;=================================================================;
;----------------------------------------------------------
;consumption of hermissenda
let hermitarget other (turtle-set hermis) in-cone (0.4 * size) 45
if any? hermitarget [
set Nutrition Nutrition + count hermitarget * 0.3
set R_hermi R_hermi + count hermitarget ;sets (positive) reward input to HRC based on number of hermissenda consumed
set hermcount hermcount + 1
ifelse Presentation-Mode [ask hermitarget [die]][ask hermitarget [setxy random-xcor random-ycor]]
set delta_Vh alpha_hermi * beta_hermi * (lambda_hermi - Vh)
set Vh Vh + delta_Vh ; The Rescorla-Wagner Learning Algorithm
;output-print word "Hermi eaten at tick " ticks
set hermcount_history lput ticks hermcount_history
]
;----------------------------------------------------------
;consumption of flabellina
let flabtarget other (turtle-set flabs) in-cone (0.4 * size) 45
if any? flabtarget [
set Nutrition Nutrition + count flabtarget * 0.3
set R_flab R_flab - count flabtarget ;sets (negative) reward input to HRC based on number of flabellina consumed
set flabcount flabcount + 1
ifelse Presentation-Mode [ask flabtarget [die]][ask flabtarget [setxy random-xcor random-ycor]]
set delta_Vf alpha_flab * beta_flab * (lambda_flab - Vf)
set Vf Vf + delta_Vf ; The Rescorla-Wagner Learning Algorithm
;output-print word "Flab eaten at tick " ticks
set flabcount_history lput ticks flabcount_history
]
;----------------------------------------------------------
;consumption of flabellina
let fauxflabtarget other (turtle-set fauxflabs) in-cone (0.4 * size) 45
if any? fauxflabtarget [
set Nutrition Nutrition + count fauxflabtarget * 0.3
set R_flab R_flab + count flabtarget ;sets (positive) reward input to HRC based on number of faux flabellina consumed
set fauxflabcount fauxflabcount + 1
ifelse Presentation-Mode [ask fauxflabtarget [die]][ask fauxflabtarget [setxy random-xcor random-ycor]]
set delta_Vf alpha_flab * beta_flab * (0 - Vf)
set Vf Vf + delta_Vf; Odor_flab is linked to ExpReward, a virtual extinction mechanism
]
;----------------------------------------------------------
;consumption of drug
let drugtarget other (turtle-set drugs) in-cone (0.4 * size) 45
ifelse any? drugtarget [
set Nutrition Nutrition + count drugtarget * 0
set R_drug R_drug + drug_reward * count drugtarget ;:::::::::: Half-dose = 1.5, Full-dose = 3
set drugcount drugcount + 1
ifelse Presentation-Mode [ask drugtarget [die]][ask drugtarget [setxy random-xcor random-ycor]]
ifelse drug_reward > 0
[set delta_Vd alpha_drug * beta_drug * (lambda_drug - Vd)]
[set delta_Vd alpha_drug * 0.5 * (0 - Vd)]
set Vd Vd + delta_Vd;
; ;if the drug type is heroin, if consumed, it will directly suppress pain sensation.
; ifelse Drug-Type = "Heroin" [set h-suppression 5] [set h-suppression 0]
; output-print word "Drug eaten at tick " ticks
set drugcount_history lput ticks drugcount_history
][
]
;update procedure for calculating input and output of HRC (see function details below)
update-RewardExperience
]
;---------------------------------------------------------------------------------------------------
; Prey and Drug Control (updates movement of flabellina, hermissenda, faux flabellina, and drug)
;---------------------------------------------------------------------------------------------------
ask flabs [
rt -1 + random-float 2
ifelse immobilize = true [ fd 0][fd 0.02]
]
ask hermis [
rt -1 + random-float 2
ifelse immobilize = true [ fd 0][fd 0.02]
]
ask fauxflabs [
rt -1 + random-float 2
ifelse immobilize = true [ fd 0][fd 0.02]
]
ask drugs [
rt -1 + random-float 2
ifelse immobilize = true [ fd 0][fd 0.02]
]
;---------------------------------------------------------------------------------------------------
; Updates ticks (units of time) and timers
;---------------------------------------------------------------------------------------------------
tick
if ticks = stop_time [stop] ; definite end of an epoch of play
if ticks > 0 and (ticks mod switch_time) = 0 [switch_on]
end
;-----------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------
;;==========================================================================================================================================
;; O T H E R U P D A T E F U N C T I O N S
;;==========================================================================================================================================
;---------------------------------------------------------------------------------
; Updates proboscis movement (Function)
;=================================================================================
to update-proboscis
ask probos [
set heading [heading] of parent
setxy ([xcor] of parent) ([ycor] of parent)
ifelse ([sns_betaine_left] of parent > 5.5) or ([sns_betaine_right] of parent > 5.5)
[set phase (phase + 1) mod 20]
[set phase 0]
fd (0.15 * size) + (0.1 * phase)
]
end
;---------------------------------------------------------------------------------
; Updates values and positions of sensors (Function)
;=================================================================================
to update-sensors
let me self
update-nociceptor-position
;colors pain sensors to show pain value
ask nociceptors [
if id = "snsrOL"[
set color scale-color red [sns-pain-left] of parent 0 0.8
]
if id = "snsrOR"[
set color scale-color red [sns-pain-right] of parent 0 0.8
]
]
;----------------------------------------------------------
;sensation of flabellina odor on left side
let odor_flab_left [odor_flab] of patch-left-and-ahead 40 (0.4 * size)
ifelse odor_flab_left > 1e-7
[set sns_flab_left 7 + (log odor_flab_left 10)]
[set sns_flab_left 0]
;sensation of flabellina odor on right side
let odor_flab_right [odor_flab] of patch-right-and-ahead 40 (0.4 * size)
ifelse odor_flab_right > 1e-7
[set sns_flab_right 7 + (log odor_flab_right 10)]
[set sns_flab_right 0]
;----------------------------------------------------------
;sensation of hermissenda odor on left side
let odor_hermi_left [odor_hermi] of patch-left-and-ahead 40 (0.4 * size)
ifelse odor_hermi_left > 1e-7
[set sns_hermi_left 7 + (log odor_hermi_left 10)]
[set sns_hermi_left 0]
;sensation of hermissenda odor on right side
let odor_hermi_right [odor_hermi] of patch-right-and-ahead 40 (0.4 * size)
ifelse odor_hermi_right > 1e-7
[set sns_hermi_right 7 + (log odor_hermi_right 10)]
[set sns_hermi_right 0]
;----------------------------------------------------------
;sensation of betaine odor on left side
let odor_betaine_left [odor_betaine] of patch-left-and-ahead 40 (0.4 * size)
ifelse odor_betaine_left > 1e-7
[set sns_betaine_left 7 + (log odor_betaine_left 10)]
[set sns_betaine_left 0]
;sensation of betaine odor on right side
let odor_betaine_right [odor_betaine] of patch-right-and-ahead 40 (0.4 * size)
ifelse odor_betaine_right > 1e-7
[set sns_betaine_right 7 + (log odor_betaine_right 10)]
[set sns_betaine_right 0]
;----------------------------------------------------------
;sensation of drug odor on left side
let odor_drug_left [odor_drug] of patch-left-and-ahead 40 (0.4 * size)
ifelse odor_drug_left > 1e-7
[set sns_drug_left 7 + (log odor_drug_left 10)]
[set sns_drug_left 0]
;sensation of drug odor on right side
let odor_drug_right [odor_drug] of patch-right-and-ahead 40 (0.4 * size)
ifelse odor_drug_right > 1e-7
[set sns_drug_right 7 + (log odor_drug_right 10)]
[set sns_drug_right 0]
;----------------------------------------------------------
;set sns-pain-left sum [painval] of (nociceptors with [id = one-of["snsrOL" "snsrUL" "snsrBL"] and parent = me])
;set sns-pain-right sum [painval] of (nociceptors with [id = one-of["snsrOR" "snsrUR" "snsrBR"] and parent = me])
;set sns-pain-caud sum [painval] of (nociceptors with [id = one-of["snsrBL" "snsrBR" "snsrBM"] and parent = me])
;sensation of pain
set sns-pain-left 0.9 * sns-pain-left
set sns-pain-right 0.9 * sns-pain-right
end
;---------------------------------------------------------------------------------
; Updates positions of pain sensors (Function)
;=================================================================================
to update-nociceptor-position
ask nociceptors[
let x-par [xcor] of parent
let y-par [ycor] of parent
let hd-par [heading] of parent
let sz-par [size] of parent
ifelse id = "snsrOL"[
setxy (x-par + 0.4 * sz-par * sin (hd-par - 40)) (y-par + 0.4 * sz-par * cos (hd-par - 40))
][
ifelse id = "snsrOR"[
setxy (x-par + 0.4 * sz-par * sin (hd-par + 40)) (y-par + 0.4 * sz-par * cos (hd-par + 40))
][
ifelse id = "snsrUL"[
setxy (x-par + 0.3 * sz-par * sin (hd-par - 100)) (y-par + 0.3 * sz-par * cos (hd-par - 100))
][
ifelse id = "snsrUR"[
setxy (x-par + 0.3 * sz-par * sin (hd-par + 100)) (y-par + 0.3 * sz-par * cos (hd-par + 100))
][
ifelse id = "snsrBL"[
setxy (x-par + 0.35 * sz-par * sin (hd-par - 150)) (y-par + 0.35 * sz-par * cos (hd-par - 150))
][
ifelse id = "snsrBR"[
setxy (x-par + 0.35 * sz-par * sin (hd-par + 150)) (y-par + 0.35 * sz-par * cos (hd-par + 150))
][
setxy (x-par + 0.46 * sz-par * sin (hd-par - 180)) (y-par + 0.46 * sz-par * cos (hd-par - 180))
]
]
]
]
]
]
]
end
;---------------------------------------------------------------------------------
; Homeostatic Reward Circuit Calculations (Function)
;=================================================================================
to update-RewardExperience
;sets reward inputs, which decay over time
set R_hermi 0.98 * R_hermi
set R_flab 0.98 * R_flab
set R_drug 0.999 * R_drug
;Sets Reward Input to neuron M, with a baseline activity of M0
set R (W1 * R_drug + W2 * IN + W4 * R_hermi + W5 * R_flab + M0)
;Positive feedback loop for reward input
set IN (W2 * R)
;Response of neuron M, based on the dynamic synaptic weight W3 and Reward Input (R)
set M (W3 * R)
;Change in W3 depends on neuron M activity, neuron M baseline (M0), and Reward Input (R)
set dW3 ((M0 - M) / R) / 1000
set W3 (W3 + dW3)
;sets Reward State value as a logistic function of neuron M activity minus its baseline. Basically indicates how much neuron M activity differs from baseline.
; (Reward State is the output of the Homeostatic Reward Circuit (HRC) to Appetitive State)
ifelse Fix-var2: [set RewardExperience Fix-RewardExp][set RewardExperience -15 + 30 / (1 + e ^ (-(M - M0)))]
set RewardExperience_history lput RewardExperience RewardExperience_history
end
;---------------------------------------------------------------------------------
; Recolors patches based on odor value (Function)
;=================================================================================
to recolor-patches
ifelse odor_flab > odor_hermi [
set pcolor scale-color flab-color odor_flab 0 0.6
][
set pcolor scale-color hermi-color odor_hermi 0 0.9
]
end
;-----------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------
;;==========================================================================================================================================
;; U S E R A P P L I C A T I O N F U N C T I O N S
;;==========================================================================================================================================
;=======================================================================================================
; Functions for Presentation Mode
;=======================================================================================================
;
; Presentation Mode:
; ---------------------------
; Cslug is immobilized, except for turning, and can be fed or
; presented with prey or drug, to monitor approach-avoidance turns
; To start, set Presentation-Mode to ON, and click on the Present button.
; Note that Satiation can be fixed via the Fix-var1 switch and fix-satiation slider,
; and Reward Experience can be fixed via the Fix-var2 switch and fix-RewardExperience slider.
;-------------------------------------------------------------------------------------------------------
;---------------------------------------------------------------------------------------------------
; Presentation of Prey or Drug (function)
;---------------------------------------------------------------------------------------------------
; INSTRUCTIONS: Choose prey or drug type from the Presentation-Choice
; drop-down menu, then click on the Present button. This will spawn the
; selected item on the left side of Cslug, which may cause it to turn away
; or towards the item.
;---------------------------------------------------------------------------------------------------
to Present
if Presentation-Mode = true[
;ask Cslugs[set pain 0]
clear-patches
let xc 9
let yc 13
set immobilize true
ask hermis [die]
ask flabs [die]
ask fauxflabs[die]
ask drugs [die]
ask Cslugs [
set heading 0
setxy 0 0
]
if Presentation-Choice = "Drug vs Hermi"[
create-drugs 1 [set odor_drug 0.5 set shape "circle" set size 1 set color drug-color setxy (- xc) yc]
create-hermis 1 [set odor_hermi 0.5 set odor_betaine 0.5 set shape "circle" set size 1 set color hermi-color setxy xc yc]
]
if Presentation-Choice = "Drug vs Flab"[
create-drugs 1 [set odor_drug 0.5 set shape "circle" set size 1 set color drug-color setxy (- xc) yc]
create-flabs 1 [set odor_flab 0.5 set odor_betaine 0.5 set shape "circle" set size 1 set color flab-color setxy xc yc]
]
if Presentation-Choice = "Hermi vs Flab"[
create-hermis 1 [set odor_hermi 0.5 set odor_betaine 0.5 set shape "circle" set size 1 set color hermi-color setxy (- xc) yc]
create-flabs 1 [set odor_flab 0.5 set odor_betaine 0.5 set shape "circle" set size 1 set color flab-color setxy xc yc]
]
if Presentation-Choice = "None"[
]
if Presentation-Choice = "Hermi"[
create-hermis 1 [set odor_hermi 0.5 set odor_betaine 0.5 set shape "circle" set size 1 set color hermi-color setxy (- xc) yc]
]
if Presentation-Choice = "Drug"[
create-drugs 1 [set odor_drug 0.5 set shape "circle" set size 1 set color drug-color setxy (- xc) yc]
]
if Presentation-Choice = "Flab"[
create-flabs 1 [set odor_flab 0.5 set odor_betaine 0.5 set shape "circle" set size 1 set color flab-color setxy (- xc) yc]
]
]
end
;---------------------------------------------------------------------------------------------------
; Feeding Cslug with Prey or Drug (function)
;---------------------------------------------------------------------------------------------------
; INSTRUCTIONS: Choose prey or drug type from the Feeding-Choice
; drop-down menu, then click on the Feed button. This will spawn the
; selected item right at the mouth of Cslug, effectively feeding it the item.
;---------------------------------------------------------------------------------------------------
to Feed
if Presentation-Mode = true[
clear-patches
let xc 0
let yc 6
set immobilize true
ask hermis [die]
ask flabs [die]
ask fauxflabs[die]
ask drugs [die]
ask Cslugs [
set heading 0
setxy 0 0
]
if Feeding-Choice = "Hermi"[
create-hermis 1 [set odor_hermi 0.5 set odor_betaine 0.5 set shape "circle" set size 1 set color hermi-color setxy xc yc]
]
if Feeding-Choice = "Drug"[
create-drugs 1 [set odor_drug 0.5 set shape "circle" set size 1 set color drug-color setxy xc yc]
]
if Feeding-Choice = "Odorless Drug"[
create-drugs 1 [set odor_drug 0 set shape "circle" set size 1 set color drug-color setxy xc yc]
]
if Feeding-Choice = "Flab"[
create-flabs 1 [set odor_flab 0.5 set odor_betaine 0.5 set shape "circle" set size 1 set color flab-color setxy xc yc]
]
]
end
;=======================================================================================================
; Pain Application (Functions)
;=======================================================================================================
; To apply a painful stimulus to Cslug, set the pain value via the apply_pain slider,
; and click on the Poke-Left or Poke-Right button.
;-------------------------------------------------------------------------------------------------------
to Poke-Left
ask Cslugs[
set sns-pain-left sns-pain-left + Apply_Pain
]
end
to Poke-Right
ask Cslugs[
;set pain 1
set sns-pain-right sns-pain-right + apply_pain
]
end
;=============================================================================================================
; Addiction Cycle
;=============================================================================================================
; The Addiction Cycle mode will start off a series of events that causes the forager to go
; through the phases of addiction over the course of 60000 ticks.
;
; Before enabling the Addiction Cycle Mode, make sure Presentation_Mode and Immobilize are both OFF.
; The easiest way to to make sure everything is ready and set up for the Addiction Cycleis is to click on the Reset to Default Settings button at the bottom center of the interface. The populations of hermi and flab can be set beforehand to the desired amounts. These will not change throughout the addiction cycle. If desired, variables can also be fixed beforehand, but it is recommended to observe the Addiction Cycle without the fixation of any variables.
;
; Once everything is ready and set as desired, set the Addiction_Cycle switch to ON. It is recommended to not alter any controls during this process in order to observe a fully-functioning Addiction Cycle, but above all, please refrain
; from altering the drug population sliders during this process. Take note of the graph of the total prey and drug consumed and how it changes throughout the phases of the Addiction Cycle.The Addiction Cycle
; takes a total of 60000 ticks to complete.
;
; The forager will start out in an environment with no drugs and only prey in the No-Drug phase.
; In the Drug Introduced phase, 5 drugs are spawned, allowing the forager to start
; drug consumption. Note that drug consumption typically occurs when the forager is
; very hungry, or by accident, if it was trying to consume another prey nearby.
; The next phase is the Drug Removed phase, where all drugs are removed. During this phase
; The forager is likely to undergo withdrawal and recovery from withdrawal.
; Following this is the Drug Without Reward phase, where 6 drug items are spawned again, emitting the same drug odor,
; but providing no reward instead of a high positive reward.
; In the beginning of this phase the forager is likely to demonstrate cravings by resuming drug consumption
; to some extent, due to the strong learned association, but over time as associative strength goes down, its
; drug consumption rate should be lower than before in the phase where the drug was first introduced.
;-------------------------------------------------------------------------------------------------------------
to switch_on
ifelse Addiction_Cycle_Phase = "No Drug" [
if any? drugs[ask drugs [die]]
create-drugs 6[
set shape "circle"
set size 1
set color drug-color
setxy random-xcor random-ycor
set odor_drug 0.5
]
set Addiction_Cycle_Phase "Drug Introduced"
][
ifelse Addiction_Cycle_Phase = "Drug Introduced" [
if any? drugs[ask drugs [die]]
set Addiction_Cycle_Phase "Drug Removed"
][
if Addiction_Cycle_Phase = "Drug Removed" [
if any? drugs[ask drugs [die]]
create-drugs 6[
set shape "circle"
set size 1
set color drug-color
setxy random-xcor random-ycor
set odor_drug 0.5
]
ask Cslugs [ set drug_reward 0]
set Addiction_Cycle_Phase "Drug Without Reward"
; ][
;
; if Addiction_Cycle_Phase = "Drug Removed" [
; ask Cslugs [ set drug_reward 0]
; set Addiction_Cycle_Phase "Drug Without Reward"
; ]
]
]
]
end
;=======================================================================================================
; Reset to Default Settings (Function)
;=======================================================================================================
; All adjustable sliders and controls on the interface are reset to their default setting.
;-------------------------------------------------------------------------------------------------------
to reset
Setup
set Presentation-Mode false
set immobilize false
set Presentation-Choice "None"
set Feeding-Choice "Drug"
set fix-RewardExp 0
set fix-satiation 0.5
set fix-Incentive 3
set Fix-var1: false
set Fix-var2: false
set Fix-var3: false
set Addiction_Cycle false
set hermi-populate 4
set flab-populate 4
set drug-populate 4
set apply_pain 10
end
@#$#@#$#@
GRAPHICS-WINDOW
211
10
732
543
51
50
4.9703
1
10
1
1
1
0
1
1
1
-51
51
-50
50
1
1
1
ticks
30.0
BUTTON
5
10
72
43
SETUP
setup
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
136
10
199
43
GO
Go
T
1
T
OBSERVER
NIL
NIL
NIL