-
Notifications
You must be signed in to change notification settings - Fork 0
/
viridian.nlogo
1582 lines (1437 loc) · 42 KB
/
viridian.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
breed [producers producer]
breed [consumers consumer]
breed [products product]
directed-link-breed [ownerships ownership]
globals [
n-producers ; how many producers to simulate?
n-consumers ; how many consumers to simulate?
start-capital-factor ; starting capital for producers (factor to be multiplied with production cost of product)
start-capital-con ; starting capital for consumers
fixed-costs-prop ; what fraction of capital must producer pay each round?
fixed-costs ; what fixed amount must producer pay each round?
milieus ; list of consumer milieus
milieu-fractions ; what fractions of all consumers belong to the milieus?
milieu-colors ; each milieu has a different turtle color
product-classes ; different classes of products with different properties
min-max-lifespans ; for each product class: minimum and maximum of average lifespan range of products
min-max-costs ; for each product class: minimum and maximum of the production cost (if producer wants to earn her spendings, she needs the customer to pay at least this amount)
lifespan-variances ; for each product class: variance of average lifespan
lifespan-vs-sust ; for each product class: function mapping [0..10] (sustainability) onto [0..1] (0 means min-lifespan, 1 means max-lifespan)
cost-vs-sust ; for each product class: function mapping [0..10] (sustainability) onto [0..1] (0 means min-cost, 1 means max-cost)
price-vs-prest ; for each product class: function mapping [0..10] (prestige) onto [0..1] (0 means min-cost, 1 means max-cost)
product-weights ; for each product class: how are products weighted with respect to each other?
income-distributions ; for each milieu: what is a typical income distribution?
consumption-needs ; for each milieu: how are the typical consumption needs? (avg/std for each product class)
similarity-needs ; for each milieu: how are the typical similarity needs? (avg/std)
similarity-tols ; for each milieu: how much is similarity of consumption allowed to deviate?
sust-weights ; for each milieu: how is sustainability typically weighted (between 0 and 1)? (avg/std)
prest-weights ; for each milieu: how is prestige typically weighted (between 0 and 1)? (avg/std)
wmin ; globally: what is the smallest possible weight (none of the three dimensions sust., prest., price shall be completely unconsidered)
wmax ; globally: what is the largest possible weight
sust-mins ; for each milieu: how good must sustainability at least be to consider prodcuer?
prest-mins ; for each milieu: how good must prestige at least be to consider prodcuer?
score-tols ; for the score value calculated for each consumer product combination, how much lower
; than the maximum can the score value be before the consumer stops buying at the
; producer? (how "loyal" is the consumer?)
]
producers-own [
capital ; the current amount of money owned by the producer
product-class ; what class is the produced product in?
product-class-index ; what is the index of that product class? (useful for lookup in lists)
sustainability ; how sustainable is the produced product?
lifespan ; determined by product-class and sustainability: how many ticks until the produced product is on average broken (since it's been bought)?
lifespan-variance ; determined by product-class and sustainability: how much can actual lifespan deviate from average lifespan?
prestige ; how high is the prestige/quality (in terms of luxury, not longevity) of the product?
cost ; what is the production cost per product?
price ; at what price does the producer decide to sell her product?
n-products ; how many products to produce each tick?
n-sale ; how many products has producer sold this tick?
]
consumers-own [
milieu
income
capital ; how much money does the consumer currently have?
suppliers ; list of producers (one per product class) where this consumer currently buys products
consumption-need ; how much consumption does the individual want/need? (for each product class)
similarity-need ; how much can consumption behaviour deviate from peers?
similarity-tol ; how much may consumption deviate from similarity goal?
sust-weight ; how important is sustainable consumption?
prest-weight ; how important is prestige/quality (luxury) of products?
price-weight ; how important is a low price of products? (sum of sust-weight, prest-weight, price-weight is 1)
sust-min ; how sustainable must consumption at least be?
prest-min ; how much prestige must consumption at least have?
score-tol ; how loyal is the consumer? how much score deviation is tolerated?
]
products-own [
product-class ; what class does this product belong to?
product-class-index ; what is the index of that product class? (useful for lookup in lists)
; quantity ; how much of the product is currently stored in this product store? store individual products so this is always 1.
; priority ; how urgent does the consumer this product belongs to need more of it? store this not in the product, but in the consumer.
sustainability ; how sustainable was this product produced?
lifespan ; how many ticks until this product is on average broken (since it's been bought)?
lifespan-variance ; how much can actual lifespan deviate from average lifespan?
prestige ; how much prestige does the consumer get from owning this product? (how high is the quality?)
price ; for how much is/was this product sold?
age ; how many ticks since product was bought?
]
;;; GENERAL USEFUL FUNCTIONS MISSING IN NETLOGO ;;;
; report index of (first occurrence of) item in list
; create the cumulative sum of a list
to-report cumsum [lst]
let result []
let cs 0
foreach lst [ x ->
let new-val cs + x
set result lput new-val result
set cs new-val
]
report result
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup
clear-all
setup-globals
setup-consumers
setup-producers
reset-ticks
end
to setup-globals
set n-producers 100
set n-consumers 100
set start-capital-factor 10
set start-capital-con 2000
set fixed-costs-prop 0.1
set fixed-costs 100
set product-classes [
"food"
"textiles"
"mobility-car"
"mobility-alt"
"IT"
"others"
]
set min-max-lifespans [
[1 1] ; food
[1 20] ; textiles
[20 50] ; mobility-car
[1 20] ; mobility-alt
[10 30] ; IT
[10 50] ; others
]
set min-max-costs [
[50 1000] ; food
[100 2000] ; textiles
[500 40000] ; mobility-car
[50 200] ; mobility-alt
[200 10000] ; IT
[100 4000] ; others
]
set lifespan-variances [
0 ; food
3 ; textiles
10 ; mobility-car
3 ; mobility-alt
5 ; IT
5 ; others
]
set lifespan-vs-sust (list
[ x -> 1 ] ; food
[ x -> x / 10 ] ; textiles
[ x -> x / 10 ] ; mobility-car
[ x -> x / 10 ] ; mobility-alt
[ x -> x / 10 ] ; IT
[ x -> x / 10 ] ; others
)
set cost-vs-sust (list
[ x -> x / 10 ] ; food
[ x -> x / 10 ] ; textiles
[ x -> x / 10 ] ; mobility-car
[ x -> 1 - x / 10 ] ; mobility-alt
[ x -> x / 10 ] ; IT
[ x -> x / 10 ] ; others
)
set price-vs-prest (list
[ x -> x / 10 ] ; food
[ x -> x / 10 ] ; textiles
[ x -> x / 10 ] ; mobility-car
[ x -> x / 10 ] ; mobility-alt
[ x -> x / 10 ] ; IT
[ x -> x / 10 ] ; others
)
set product-weights [
0.05 ; food
0.15 ; textiles
0.30 ; mobility-car
0.05 ; mobility-alt
0.15 ; IT
0.30 ; others
]
set milieus [
"eco-aware"
"conservative"
"prestige-seeking"
"small-income"
]
set milieu-fractions [
0.2
0.5
0.2
0.1
]
set milieu-colors [
green
gray
pink
blue
]
set income-distributions [
[500 500 1000 1000 1000 2000 2000 2000 2000 2000 2000 2000 3000 4000]
[500 500 1000 1000 1000 1000 1000 1000 1000 2000 2000 2000 3000 4000]
[500 1000 1000 1000 1000 2000 2000 2000 2000 2000 2000 3000 3000 3000 4000 4000]
[500 500 500 500 500 500 1000 1000 1000]
]
set consumption-needs [ ; average number of products bought per tick:
; [mean std] if owns 0, [mean std] if owns 1, [mean std] if owns 2, [mean std] if owns 3 or more
[ ; food
[[1 0] [0 0] [0 0] [0 0]] ; eco
[[1 0] [0 0] [0 0] [0 0]] ; conservative
[[1 0] [0 0] [0 0] [0 0]] ; prestige
[[1 0] [0 0] [0 0] [0 0]] ; small income
]
[ ; textiles
[[1 0] [0.2 0.1] [0.15 0.05] [0.01 0.01]] ; eco
[[1 0] [0.5 0.3] [0.3 0.2] [0.05 0.05]] ; conservative
[[1 0] [0.8 0.2] [0.5 0.2] [0.1 0.1]] ; prestige
[[1 0] [0.1 0.1] [0.1 0.1] [0 0]] ; small income
]
[ ; mobility-car
[[0.5 0.2] [0.1 0.1] [0.01 0.01] [0 0]] ; eco
[[1 0] [0.3 0.3] [0.01 0.01] [0 0]] ; conservative
[[1 0] [0.5 0.2] [0.2 0.2] [0.1 0.1]] ; prestige
[[0.7 0.2] [0.1 0.1] [0 0] [0 0]] ; small income
]
[ ; mobility-alt
[[0.8 0.2] [0.1 0.1] [0.01 0.01] [0 0]] ; eco
[[0.3 0.2] [0.1 0.1] [0 0] [0 0]] ; conservative
[[0.1 0.1] [0.1 0.1] [0 0] [0 0]] ; prestige
[[0.7 0.2] [0.1 0.1] [0 0] [0 0]] ; small income
]
[ ; IT
[[0.8 0.2] [0.1 0.1] [0.01 0.01] [0 0]] ; eco
[[1 0] [0.5 0.3] [0.01 0.01] [0 0]] ; conservative
[[1 0] [0.7 0.3] [0.3 0.2] [0 0]] ; prestige
[[0.7 0.2] [0.1 0.1] [0 0] [0 0]] ; small income
]
[ ; other goods (luxury)
[[0.8 0.2] [0.1 0.1] [0.01 0.01] [0 0]] ; eco
[[1 0] [0.5 0.3] [0.01 0.01] [0 0]] ; conservative
[[1 0] [0.7 0.3] [0.3 0.2] [0 0]] ; prestige
[[0.7 0.2] [0.1 0.1] [0 0] [0 0]] ; small income
]
]
set similarity-needs [ ; mean standard-deviation
[5 3] ; 5 +/- 3 eco
[7 3] ; 7 +/- 3 conservative
[9 1] ; 9 +/- 1 prestige
[5 3] ; 5 +/- 3 small income
]
set similarity-tols [ ; how many points deviation is allowed?
3 ; eco
5 ; conservative
2 ; prestige
3 ; small income
]
set sust-weights [ ; mean standard-deviation
[0.6 0.1] ; 0.6 +/- 0.1 eco
[0.2 0.1] ; 0.2 +/- 0.1 conservative
[0.1 0.1] ; 0.1 +/- 0.1 prestige
[0.1 0.1] ; 0.1 +/- 0.1 small income
]
set prest-weights [ ; mean standard-deviation
[0.2 0.1] ; eco
[0.3 0.1] ; conservative
[0.6 0.1] ; prestige
[0.4 0.1] ; small income
]
set wmin 0.05 ; at least 5 % consideration for each dimension (sustainability/prestige/price)
set wmax 1. - 2. * wmin
set sust-mins [ ; min expectation of sustainability
5 ; eco
2 ; conservative
0 ; prestige
0 ; small income
]
set prest-mins [ ; min expectation of prestige
1 ; eco
3 ; conservative
5 ; prestige
2 ; small income
]
set score-tols [ ; loyalty towards prodcuers
2 ; eco
3 ; conservative
1 ; prestige
1 ; small income
]
end
to-report safe-random-normal [nmin nmax nmean std]
let number random-normal nmean std
if number < nmin [ set number nmin ]
if number > nmax [ set number nmax ]
report number
end
; consumer method, for the tradeoff system driving consumer's buying behavior
to-report draw-weights [i] ; i is index of milieu
let a -1.
let b -1.
let c -1.
while [c < 0] [
set a safe-random-normal wmin wmax item 0 item i sust-weights item 1 item i sust-weights
set b safe-random-normal wmin wmax item 0 item i prest-weights item 1 item i prest-weights
let c-try 1. - a - b
; Need to check if the coordinates defined by this tuple (whose sum is 1) lie inside and not too close to the
; edges of a triangle whose corners define one of the three extremes (e.g. a 1, the others 0).
; This means that none of the three weights shall be smaller than a certain minimum (epsilon).
; For the first 2, it is already ensured, but need to check 3rd one.
if c-try >= wmin [
set c c-try
]
]
report (list a b c)
end
to setup-consumers
create-consumers n-consumers [
set shape "turtle"
set suppliers []
repeat length product-classes [
set suppliers lput nobody suppliers
]
set milieu 0
]
let i 0
foreach milieus [ m ->
let f (item i milieu-fractions)
ask n-of round (f * n-consumers) consumers with [milieu = 0] [set milieu m]
ask consumers with [milieu = m] [
set income one-of item i income-distributions
set capital start-capital-con
set consumption-need []
foreach consumption-needs [ cn ->
set consumption-need lput (
map [ j -> safe-random-normal 0 1 item 0 item j item i cn item 1 item j item i cn ] range 4
) consumption-need
]
set similarity-need safe-random-normal 0 10 item 0 item i similarity-needs item 1 item i similarity-needs
set similarity-tol item i similarity-tols
let weight-list draw-weights i
set sust-weight item 0 weight-list
set prest-weight item 1 weight-list
set price-weight item 2 weight-list
set sust-min item i sust-mins
set prest-min item i prest-mins
setxy sust-weight * max-pxcor prest-weight * max-pycor
set color item i milieu-colors
]
set i i + 1
]
end
; consumer method, returns list of consumer demands
to-report consumer-demand [pc-index]
let pc item pc-index product-classes
let n-prods count ownership-neighbors with [product-class = pc]
if n-prods > 3 [ set n-prods 3 ]
report item n-prods item pc-index consumption-need
end
; what is exepctation value for next tick's consumption of a certain product class?
; observer method
to-report demand [pc-index] ; index of the product class
report sum [consumer-demand pc-index] of consumers
end
; report demands of all product classes
; observer method
to-report demands
let result []
let pc-index 0
while [pc-index < length product-classes] [
set result lput (demand pc-index) result
set pc-index pc-index + 1
]
report result
end
; observer method
to-report cumulative-demand [pc-index] ; index of the product class
let ids sort [who] of consumers ; because order of 'of' is random, use the sorted whos for defined order
let cs cumsum map [ x ->
[consumer-demand pc-index] of consumer x
] ids
set cs map [ x -> x / demand pc-index ] cs
report lput 1 but-last cs
end
; producers look at consumers' wishes, so must be created after consumers
to setup-producers
create-producers n-producers [
setup-producer
]
end
to setup-producer
hide-turtle
; setxy random-xcor random-ycor
; select a random product class, with probability corresponding to demand (the product-class never changes across lifetime of producer)
; first calculate cumulative probabilities from the demands
let demands-sum sum demands
let demands-cumsum map [ x -> x / demands-sum ] cumsum demands
; draw a random number n between 0 and 1, the product class index is the index of the first cumsum entry larger than that number
let n random-float 1
set product-class-index position true map [ x -> n < x ] demands-cumsum
set product-class item product-class-index product-classes
orient-producer
set capital start-capital-factor * cost
end
; the producer decides (maybe redecides) about sustainability and prestige of her product
to orient-producer
let i product-class-index
; determine a randomly selected customer on which to orient the production (sustainability and prestige)
let n random-float 1
let target position true map [ x -> x > n ] cumulative-demand i
set target item target sort [who] of consumers ; this line should not be needed because consumers' who starts at 0,
; but just to be sure (if letting consumers die, this might be needed)
; this does not work any more with the tradeoff system of consumers
; set sustainability [sustainability-need] of consumer target
; set sustainability [(sust-weight - wmin) / (wmax - wmin) * 10] of consumer target ; project weight on full range (0..10)
; alternative:
let smin [sust-weight * 10] of consumer target
set sustainability (random-float (10 - smin)) + smin
let min-lifespan item 0 item i min-max-lifespans
let max-lifespan item 1 item i min-max-lifespans
let lifespan-f (item i lifespan-vs-sust)
let dynamic-value (runresult lifespan-f sustainability)
set lifespan (max-lifespan - min-lifespan) * dynamic-value + min-lifespan
; set lifespan random-float (max-lifespan - min-lifespan) + min-lifespan
set lifespan-variance item i lifespan-variances
; this does not work any more with the tradeoff system of consumers
; set prestige [prestige-need] of consumer target
; draw a random target consumer again, then:
; set prestige [(prest-weight - wmin) / (wmax - wmin) * 10] of consumer target ; project weight on full range (0..10)
; alternative:
let pmin [prest-weight * 10] of consumer target
set prestige (random-float (10 - pmin)) + pmin
let min-cost item 0 item i min-max-costs
let max-cost item 1 item i min-max-costs
let cost-f (item i cost-vs-sust)
let price-f (item i price-vs-prest)
let sust-factor (runresult cost-f sustainability)
let prest-factor (runresult price-f prestige)
ifelse (sust-factor > prest-factor) [
; the product shall not have a price lower than cost, so include low prest-factor
; in the production cost
set cost (max-cost - min-cost) * (mean list sust-factor prest-factor) + min-cost
set price cost
]
[
; the product's production cost is only determined by sust-factor (low cost),
; but the high prestige comes at a higher price for consumer
set cost (max-cost - min-cost) * sust-factor + min-cost
let min-price cost
let max-price (max-cost - min-cost) * (mean list sust-factor prest-factor) + min-cost
; choose a random price between production cost and prestige boosted cost
set price (max-price - min-price) * random-float 1 + min-price
]
set n-products -1
set n-sale 0
end
to go
ask producers [pay-costs] ; some producers may die
create-new-producers ; create new producers if some died
ask consumers [use-products]
ask producers [produce]
ask consumers [consume]
ask consumers [be-influenced]
ask producers [re-orient]
tick
end
; producer method
to pay-costs
set capital (1 - fixed-costs-prop) * capital ; pay variable costs
set capital capital - fixed-costs ; pay fixed costs
if capital < cost [ ; if producer cannot produce at least one product
ask ownership-neighbors [die] ; let products owned by producer die as well
die
]
end
; observer method
to create-new-producers
let current-n-producers count producers
if current-n-producers < n-producers [
create-producers (n-producers - current-n-producers) [
setup-producer
]
]
end
; consumer method
to use-products
let my-products ownership-neighbors
ask my-products [
set age age + 1
if age >= random-normal lifespan lifespan-variance [
die ; product is used up/broken
]
]
end
; prodcuer method
to guess-n-products
; not working any more with tradeoff system:
; let target-group consumers with [can-buy-at? myself]
; let target-demand sum [consumer-demand [product-class-index] of myself] of target-group
; let competitors producers with [ ; competitors includes the producer running this code (which is wanted)
; ; can any consumer in the target group also buy at this producer? does it produce the same product class? then it's a competitor
; product-class-index = [product-class-index] of myself and
; member? true [can-buy-at? myself] of target-group
; ]
; let expected-demand max list round (target-demand / (count competitors)) 1 ; assume demand to be at least 1 product (even if rounded demand is 0)
let competitors producers with [ product-class-index = [product-class-index] of myself ]
let expected-demand max list round (demand product-class-index / (count competitors)) 1 ; assume demand to be at least 1 product (even if rounded demand is 0)
let risk (random 3) + 1 ; prooducer has a random risk
set n-products min list (expected-demand * risk) 10 ; produce at most 10 products (maximum possible with initial capital)
end
; producer method
to produce
if n-products < 0 [
; determine n-products anew
guess-n-products
]
let expenses n-products * cost
; check if you have enough money
if expenses > capital [
set n-products floor (capital / cost)
set expenses n-products * cost
]
set capital capital - expenses
hatch-products n-products [
set age 0
create-ownership-from myself [hide-link]
]
; reset the n-sale counter
set n-sale 0
end
; consumer mtehod
; calculate the tradeoff system score value for one producer
to-report evaluate-prod [prod min-price]
report sust-weight * [sustainability] of prod + prest-weight * [prestige] of prod + price-weight * 10 * min-price / [price] of prod
end
; producer mtehod
; calculate the tradeoff system score value of yourself for one consumer cons
to-report be-evaluated-by [cons min-price]
report [sust-weight] of cons * sustainability + [prest-weight] of cons * prestige + [price-weight] of cons * 10 * min-price / price
end
; consumer method
to-report find-best-prod [prods min-price]
report max-one-of prods [
be-evaluated-by myself min-price
]
end
; consumer method
to consume
set capital capital + income ; pay monthly income to enable more consumption
; now go and buy stuff
; special case for food and textiles: if you really need it, because you own nothing, only consider products you can buy
; if you need both, divide capital in two parts, weighted with median food/clothes price
; let need-food? (consumer-demand 0) = 1
; let need-clothes? (consumer-demand 1) = 1
let need-food? (count ownership-neighbors with [product-class = "food"]) = 0
let need-clothes? (count ownership-neighbors with [product-class = "textiles"]) = 0
let budgets find-budgets need-food? need-clothes?
let food-budget item 0 budgets
let clothes-budget item 1 budgets
; decide if to go shopping for each product class
foreach range length product-classes [ i ->
; interpret demand (number between 0 and 1) to be a probability that the consumer buys products from this product class this tick
; (one product can stand for multiple, it's the full amount needed within one tick)
let prob consumer-demand i
let buy? (random-float 1) < prob
if buy? [
; consumer decided to buy
let max-price -1
if i = 0 and need-food? [ set max-price food-budget ]
if i = 1 and need-clothes? [ set max-price clothes-budget ]
; evaluate products:
let my-producers producers with [product-class-index = i]
let prods filter-products my-producers max-price
if count prods = 0 and ((i = 0 and need-food?) or (i = 1 and need-clothes?)) [
; try again, without minimum requirements to sustainability and prestige, because you NEED food/clothes
set prods turtle-set [ownership-neighbors with [price < max-price]] of my-producers
]
if count prods > 0 [
; if there is at least 1 product, try to buy, else do nothing
let prod-list pick-product prods i
let my-best-prod item 0 prod-list
let my-supplier item 1 prod-list
if my-best-prod != nobody [
; now we know which product to buy, let's buy it!
let amount [price] of my-best-prod
; only buy if you can pay for it
if amount < capital [
; transfer the money
set capital capital - amount
ask my-supplier [
set capital capital + amount
set n-sale n-sale + 1
]
; transfer the ownership
ask [my-ownerships] of my-best-prod [die]
create-ownership-to my-best-prod [hide-link]
]
]
]
]
]
end
; consumer method
; return only the products of some-producers that meet my minimum standards
to-report filter-products [some-producers max-price]
let min-sustainability sust-min
let min-prestige prest-min
if max-price > 0 [
report turtle-set [ownership-neighbors with [
price < max-price and
sustainability >= min-sustainability and prestige >= min-prestige
]] of some-producers
]
report turtle-set [ownership-neighbors with [
sustainability >= min-sustainability and prestige >= min-prestige
]] of some-producers
end
; consumer method
to-report find-budgets [need-food? need-clothes?]
let food-budget capital
let clothes-budget capital
if need-food? and need-clothes? [
let food-prices [price] of filter-products (producers with [product-class-index = 0]) -1
let clothes-prices [price] of filter-products (producers with [product-class-index = 1]) -1
let med-food-price 1.
let med-clothes-price 1.
if length food-prices > 0 [
set med-food-price median food-prices
]
if length clothes-prices > 0 [
set med-clothes-price median clothes-prices
]
set food-budget capital * med-food-price / (med-food-price + med-clothes-price)
set clothes-budget capital * med-clothes-price / (med-food-price + med-clothes-price)
]
report (list food-budget clothes-budget)
end
; consumer method
to-report pick-product [prods i]
; the return variables
let my-supplier item i suppliers
let my-best-prod nobody
let min-price min [price] of prods
let best-prod find-best-prod prods min-price
; there may not be any product suiting my minimum needs
if best-prod != nobody [
if my-supplier != nobody [
let supplier-list check-my-supplier my-supplier best-prod min-price
set my-supplier item 0 supplier-list
set my-best-prod item 1 supplier-list
]
if my-supplier = nobody [
; just take the best product
set my-best-prod best-prod
set my-supplier one-of [ownership-neighbors] of best-prod
set suppliers replace-item i suppliers my-supplier ; remember this producer for next tick
]
]
report (list my-best-prod my-supplier)
end
; consumer method
to-report check-my-supplier [my-supplier best-prod min-price]
; check if supplier still matches the needs
let best-score evaluate-prod best-prod min-price
let my-prods filter-products my-supplier -1
let my-best-prod nobody
ifelse count my-prods < 1 [
; nothing in stock, must buy somewhere else
set my-supplier nobody
]
[
set my-best-prod find-best-prod my-prods min-price
ifelse my-best-prod != nobody [
let my-best-score evaluate-prod my-best-prod min-price
if (best-score - my-best-score) > score-tol [
; score of this guy's not good enough
set my-supplier nobody
]
] [
; supplier does not meet my minimum needs
set my-supplier nobody
]
]
report (list my-supplier my-best-prod)
end
; consumer method
to be-influenced
end
; producer method
to re-orient
end
@#$#@#$#@
GRAPHICS-WINDOW
225
23
767
566
-1
-1
31.412
1
10
1
1
1
0
1
1
1
0
16
0
16
0
0
1
ticks
30.0
BUTTON
32
41
105
74
NIL
setup
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
114
41
195
74
NIL
go
T
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
PLOT
780
28
1128
294
Sustainability weights
Sustainability weight * 10
Number of turtles
0.0
10.0
0.0
10.0
true
false
"" ""
PENS
"default" 1.0 0 -16777216 true "" "histogram [sust-weight * 10] of consumers"
PLOT
1142
30
1486
296
Similarity needs
Similarity need
Number of turtles
0.0
10.0
0.0
10.0
true
false
"" ""
PENS
"default" 1.0 0 -16777216 true "" "histogram [similarity-need] of consumers"
PLOT
780
307
1127
570
Prestige weights
Prestige weight * 10
Number of turtles
0.0
10.0
0.0
10.0
true
false
"" ""
PENS
"default" 1.0 0 -16777216 true "" "histogram [prest-weight * 10] of consumers"
PLOT
9
576
209
726
Sustainability of food companies
NIL
NIL
0.0
10.0
0.0
10.0
true
false
"" ""
PENS
"default" 1.0 0 -16777216 true "" "histogram [sustainability] of producers with [product-class = \"food\"]"
PLOT
219
576
419
726
Sustainability of textile companies
NIL
NIL
0.0
10.0
0.0
10.0
true
false
"" ""
PENS
"default" 1.0 0 -16777216 true "" "histogram [sustainability] of producers with [product-class = \"textiles\"]"
PLOT
427
576
627
726
Sustainability of mobility companies
NIL
NIL
0.0
10.0
0.0
10.0
true
false
"" ""
PENS
"default" 1.0 0 -16777216 true "" "histogram [sustainability] of producers with [product-class = \"mobility-car\"]"
PLOT
845
576
1045
726
Sustainability of IT companies
NIL
NIL
0.0
10.0
0.0
10.0
true
false
"" ""
PENS
"default" 1.0 0 -16777216 true "" "histogram [sustainability] of producers with [product-class = \"IT\"]"
PLOT
1057
576
1257
726
Sustainability of other companies
NIL
NIL
0.0
10.0
0.0
10.0
true
false
"" ""
PENS
"default" 1.0 0 -16777216 true "" "histogram [sustainability] of producers with [product-class = \"others\"]"
PLOT
1143
306
1479
570
Production costs
Cost / 100
Number of products
0.0
50.0
0.0
10.0
true
false
"; set-plot-x-range 0 max [cost / 100] of producers" ""
PENS
"default" 1.0 0 -16777216 true "" "histogram [cost / 100] of producers"
PLOT
636
576
836
726
Sustainability of mobility-alt
NIL
NIL
0.0
10.0
0.0
10.0
true
false
"" ""
PENS
"default" 1.0 0 -16777216 true "" "histogram [sustainability] of producers with [product-class = \"mobility-alt\"]"
PLOT
15
93
215
243
Producer who
NIL
NIL
0.0
10.0
0.0
10.0
true
false
"" ""
PENS
"default" 1.0 0 -16777216 true "" "plot min [who] of producers"
"pen-1" 1.0 0 -7500403 true "" "plot max [who] of producers"
PLOT