-
Notifications
You must be signed in to change notification settings - Fork 0
/
Waste recycling Plastic_final.nlogo
1941 lines (1775 loc) · 50.5 KB
/
Waste recycling Plastic_final.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
;; Defining global variables
globals [
recycle-percent-target ; recycle percent target defined by the municipality
tick-counter ; to stop the model
target-update-counter ; Used to update the recycle percent target
initiative-tick ; Used to keep track of municipal initiative based ticks
]
;;Defining different agents for the model
breed [households household]
breed [municipalities municipality]
breed [firms firm]
undirected-link-breed [contracts contract]
;; Household attributes
households-own [
base-waste-function ; base waste function as per the formula given in the problem description
household-type ; assigning household types
waste-factor ; multiplication factor per household type
base-waste ; Ideal Base waste value given the households collect all the possible plastic
is-awareness-training? ; proxy for awareness training
infrastructure-effect ; Multiplication factor to account for motivation based on centralized and decentralized infrastructure.
perception-to-recycle ; stores the current perception value towards recycling
awareness-effectiveness ; stores the awareness training effectiveness value
recyclable-waste ; the recylable waste produced based on the perception value
is-knowledge-training? ; proxy for knowledge training
pre-separate-percent ; stores the currest post separation percent value
knowledge-effectiveness ; stores the knowledge training effectiveness value
pre-separated-waste ; the pre-separated waste per households
municipality-belong ; proxy to assign municipality to each household
]
;; municipality attributes
municipalities-own [
collection-infra ; the type of collection infrastructure of a municipality
total-base-waste ; total base waste collected
possible-recyclable-waste ; the maximum amount of waste that can be recycled under perfect conditions
actual-recyclable-waste ; actual waste collected
total-pre-separated-waste ; actual pre-separated waste
contracted-waste ; waste under contracts
non-contracted-waste ; waste not under contracts
awareness-program ; counter for number of awareness programs
awareness-cost ; total cost of awareness program
knowledge-program ; counter for number of knowledge programs
fine? ; proxy to see applicablity of firxne
municipal-fine ; value of fine
municipal-fines-total ; total value of fines
total-fines ; counter for number of fines
knowledge-cost ; total cost of knowledge program
education-program-cost ; cost for combined knowledge and awareness programs
education-cost ; cost per education activity
total-recycled-waste-municipality ; total waste recycled
recycling-rate-achieved ; recycling rate actually achieved
municipal-expenditure ; municipal expenditure
municipality-singles-belong ; household of singles per municipality
municipality-old-belong ; household of old per municipality
municipality-couples-belong ; household of couples per municipality
municipality-family-belong ; household of families per municipality
municipality-population ; total municipal population
running-contracts ; running contracts
total-efficiency-received ; total efficiency of the running contract firms, used as a proxy to calculate municipal recycling rates
]
;; firms attributes
firms-own [
offer-recycled-post ; offer value of recycled post-separated
capacity ; cuurent capacity of firms
efficiency ; current efficiency of firms
operate-cost ; current cost of operations of firms
tech-improve-time ; counter to check the efficiency improvement
capacity-improve-time ; counter to check capacity improvements
capacity-utilized ; total utilized capacity of firms
waste-collect-cost ; collection cost for waste
can-bid? ; proxy to check bidding ability of firms
tech-improve? ; proxy to check need for efficiency improvement
factory-cash-balance ; total cash balance of firms
capacity-improve? ; proxy to check need for capacity improvement
capacity-effect-operate-cost ; effect of capacity improvement on operating cost
capacity-effect-tech ; effect of capacity improvement on efficiency improvement
total-waste-post-separated ; total waste post separated by firms
total-waste-received-firm ; total waste recieved by firms
total-waste-recycled-firm ; total waste recycled by firms
tech-effect-operate-cost ; effect of efficiency improvement on operating cost
sell-price-pre ; selling price of pre-separated plastic
sell-price-post ; selling price of post-separated plastics
fine-earnings ; earnings from fines
total-sell-earning ; earnings from selling plastic
total-collect-cost ; total collection costs
total-operating-cost ; total operating costs
offer-non-contracted-received ; offer quantity of plastic recieved
offer-cost ; offer cost submitted
offer-recycled ; offer for recycled quantity submitted
offer-recycle-percent ; offer recycle percentage quoted
investment-capacity ; cost for a cacity investment
investment-tech ; cost for efficiency investement
total-pre-separated-received ; total preseparated plastic recieved
]
;; contracts attributes
contracts-own [
fine-cost ; fines cost agreed in contracts
recycle-percentage-agreed ; recycle percentage agreed in negotiations
contracted-waste-agreed ; waste quanitity agreed
contract-period ; contract period
contract-time-running ; proxy to check contract running time
contract-price ; price of the contract based on offer price
present-post-separation-rate ; post separation rate agreed
contract-efficiency ; efficiency value of the firm
]
;;;;;;;;;;;;;;;;;;;;;;;
;;; Setup Functions ;;;
;;;;;;;;;;;;;;;;;;;;;;;
to setup
clear-all
setup-globals
setup-municipalities
setup-households
setup-firms
setup-municipal-population-counter
reset-ticks
end
;; to setup all the globals in the model
to setup-globals
Set recycle-percent-target initial-recycle-percent-target
set tick-counter 0
Set target-update-counter 0
Set initiative-tick 0
end
;; to assign the initial municipal parameters
to setup-municipalities
create-municipalities total-municipalities
ask municipalities [
setxy (min-pxcor + 1) (random-float -25 + 12) ; ensuring that the municipalities are always on the left corner of the world view
set shape "house ranch"
set size 3
Set color violet - 2 + random 5 ; set the color of the municipality on different shades of violet
;;setting the initial value to attributes
Set total-base-waste 0
Set possible-recyclable-waste 0
Set actual-recyclable-waste 0
Set total-pre-separated-waste 0
Set contracted-waste 0
Set non-contracted-waste 0
Set awareness-program 0
Set fine? False
set municipal-fine 0
set municipal-fines-total 0
Set total-fines 0
Set awareness-cost 0
Set knowledge-program 0
Set knowledge-cost 0
Set education-program-cost 15
Set education-cost 0
Set total-recycled-waste-municipality 0; sum of all recycled-waste-municipality
Set recycling-rate-achieved 0
Set municipal-expenditure 0
;; assigning collection infrastructure based on global probability
if-else random-float 1 < percent-centralized-infra
[
Set collection-infra "centralised"
]
[
Set collection-infra "decentralised"
]
]
end
;; to assign the initial household parameters
to setup-households
create-households random-normal (26 * total-municipalities) 2 ; assign population distribution
ask households [
setxy random-float -25 + 13 random-float -25 + 12 ; ensure that households are in the middle area of the world view
Set municipality-belong one-of municipalities ; assign households to municipalities
set size 1
set shape "house"
Set base-waste-function (40 - (0.04 * tick-counter - (e ^ (-0.01 * tick-counter)) * sin(0.3 * tick-counter * 57.2957795) ) / 12) ; 1 radian = 57.2957795 degrees
Set base-waste 0
Set is-awareness-training? False
;; assigning the distribution of knowledge and perception to households
Set perception-to-recycle random-normal init-perception-to-recycle 0.06
Set awareness-effectiveness random-normal init-awareness-effectiveness 0.02
Set recyclable-waste 0
Set is-knowledge-training? False
Set pre-separate-percent random-normal init-pre-separate-percent 0.05
Set knowledge-effectiveness random-normal init-knowledge-effectiveness 0.02
Set pre-separated-waste 0
;; assigning the waste factor and color based on type of household
let type-setter random-float 1 ; proxy for setting type of household, will be a assigned a random number from 0 -100
if type-setter <= percentage-old
[set household-type "old"
set color blue
Set waste-factor 0.75
]
if type-setter > percentage-old and type-setter <= (percentage-single + percentage-old)
[ set household-type "single"
set color red
Set waste-factor 1
]
if type-setter > (percentage-single + percentage-old) and type-setter <= (percentage-single + percentage-old + percentage-couples)
[ set household-type "couples"
set color green
Set waste-factor 2
]
if type-setter > (percentage-single + percentage-old + percentage-couples)
[ set household-type "family"
set color yellow
Set waste-factor 3
]
]
end
;; to assign the initial firm parameters
to setup-firms
create-firms 4 [
set color brown - 2 + random 5 ; all firms are different shades of brown
set shape "factory"
set size 2
setxy (random-float -25 + 12) (max-pycor - 1) ; ensure that firms are always on the top on the world view
]
;; setting other attributes
ask firms [
Set capacity random-normal init-capacity 8500 ; capacity distribution
Set efficiency random-normal init-efficiency 0.02 ; efficiency distribution
Set operate-cost random-normal 0.35 0.05 ; operation cost distribution
Set tech-effect-operate-cost 0.02
Set sell-price-pre 0.43
Set sell-price-post 0.87
Set fine-earnings 0
Set waste-collect-cost 0.1
Set total-sell-earning 0
Set total-operating-cost 0
Set total-collect-cost 0
Set offer-non-contracted-received 0
Set offer-cost 0
Set offer-recycled 0
Set offer-recycle-percent 0
Set investment-capacity 500000
Set can-bid? True
Set investment-tech 200000
Set total-pre-separated-received 0
Set total-waste-received-firm 0
Set total-waste-post-separated 0
Set total-waste-recycled-firm 0
Set tech-improve? false
Set capacity-improve? false
Set capacity-effect-tech 0.04
Set capacity-effect-operate-cost 0.05
Set factory-cash-balance 10000000
Set capacity-improve-time 0
Set tech-improve-time 0
set capacity-utilized 0
]
end
;; to setup up counters for eac type of household per municipality
to setup-municipal-population-counter
ask municipalities[
set municipality-singles-belong count households with [ municipality-belong = myself and household-type = "single" ] * 1000 ; 1000 households representation per agent
set municipality-old-belong count households with [ municipality-belong = myself and household-type = "old" ] * 1000
set municipality-couples-belong count households with [ municipality-belong = myself and household-type = "couples" ] * 1000
set municipality-family-belong count households with [ municipality-belong = myself and household-type = "family" ] * 1000
set municipality-population municipality-singles-belong + municipality-old-belong + municipality-couples-belong + municipality-family-belong
]
end
;;;;;;;;;;;;;;;;;;;
;;; Go Function ;;;
;;;;;;;;;;;;;;;;;;;
to go
;; update globals
If-else target-update-counter < 11
[
set target-update-counter (target-update-counter + 1)
]
[
Set target-update-counter 0
Set recycle-percent-target (recycle-percent-target + (percent-increase-target * recycle-percent-target))
]
set initiative-tick (initiative-tick + 1)
;See if the contracts are running
check-running-contracts
check-facility-improve
;;ask households to start generating waste and raising awareness if any municipal intiatives are running
improve-education
generate-waste
;;Ask municipalities to start collecting the wastes and send requests for tender offers
ask municipalities [
accumulate-waste
release-tender
]
;; ask municipality to
settle-contract-prices ; and
fine-check ; to pay fines, if any
;; ask firms to process the waste that is collected and therefore compute the expenditure
ask firms [
collect-waste
compute-firm-expenditure
]
;;lastly asking the municipalities to do awareness programs if the national targets are not being met and raise awareness, if requred.
ask municipalities [
awareness-programs
compute-municipal-expenditure
]
;; ensuring model stops at 20 years
Set tick-counter (tick-counter + 1)
if-else tick-counter < 240
[ Tick ]
[ stop ]
;; plotting the results that are needed
plot-results
end
;; to schek the running contracts and release the tenders if the contracts are finished
to check-running-contracts
ask contracts [
if-else contract-time-running < contract-period
[
set contract-time-running contract-time-running + 1
]
[
die
]
]
ask municipalities [
set contracted-waste sum [contracted-waste-agreed] of my-contracts ; make corrections for the new contracted sum
release-tender
if my-contracts = 0
[
set contracted-waste 0 ; if there are no contarcts, there is no contracted sum
release-tender
]
]
ask firms [
update-firm-processing ;; to ensure, no municipality is without contracts
]
end
;; to check for running awareness or knowledge programs and update the households. This is important before households collect waste fpr the given month
to improve-education
ask households [
If is-awareness-training? = True
[
Set awareness-effectiveness random-normal init-awareness-effectiveness 0.02 ; to ensure different effectiveness for each training
Set perception-to-recycle (perception-to-recycle + awareness-effectiveness * perception-to-recycle)
Set is-awareness-training? False
]
If is-knowledge-training? = True
[
Set knowledge-effectiveness random-normal init-knowledge-effectiveness 0.02 ; to ensure different effectiveness for each training
Set pre-separate-percent (pre-separate-percent + knowledge-effectiveness * pre-separate-percent)
Set is-knowledge-training? False
]
]
end
;; actual waste generation and post separation by households
to generate-waste
ask households [
let infra [ collection-infra ] of municipality-belong ; proxy to set type of infrastructure
if-else infra = "centralised" ; different motivation fators for centralised and decentralised infra
[
set infrastructure-effect 1
]
[
set infrastructure-effect 1.1
]
Set base-waste-function (40 - (0.04 * tick-counter - (e ^ (-0.01 * tick-counter)) * sin(0.3 * tick-counter) )) / 12
Set base-waste (base-waste-function * waste-factor * 1000) ; 1000 households per agent representation
Set recyclable-waste (base-waste * perception-to-recycle)
Set pre-separated-waste (recyclable-waste * pre-separate-percent * infrastructure-effect) ; motivation to pre-separate is dependant on infrastructure of the municipality
]
end
;; function of the municipality to accumulate the waste
to accumulate-waste
Set total-base-waste sum [ base-waste ] of households with [ municipality-belong = myself ]
Set possible-recyclable-waste total-base-waste * possible-recycle-percent
Set actual-recyclable-waste sum [ recyclable-waste ] of households with [ municipality-belong = myself ]
Set total-pre-separated-waste sum [ pre-separated-waste ] of households with [ municipality-belong = myself ]
end
;; release new tenders if the waste collected for the tick is more than contracted waste
to release-tender
if actual-recyclable-waste > contracted-waste
[
Set non-contracted-waste (actual-recyclable-waste - contracted-waste)
;; to use the non-contracted-waste as input in link-context
let non-contracted-volume non-contracted-waste ; proxy to be used in the functions ahead
request-bid non-contracted-volume ; function to request for firm offers
Set contracted-waste sum [ contracted-waste-agreed ] of my-contracts ; update contracted value once contract is made
]
end
;; this function is where the magic happens
to request-bid [ non-contracted-volume ]
ask firms [
submit-offer non-contracted-volume ; firms submit offers, after chencking whether they can bid based on capacity and efficiency
]
;; make a contract with waste management firm with cheapest offer if they can bid
ifelse count firms with [ can-bid? ] > 0
[
create-contract-with min-one-of firms [offer-cost]
[
set-contract-settings non-contracted-volume ; update the contract properties to make it binding. Some properties do not change per contract and some do
]
ask firms [
update-firm-processing ; firms update their capacity since new waste values are assigned. This means they might need to invest in capacity as well
]
]
[
;; if there is no waste management firm that can make a contract, make a contract with the waste management firm that has the highest efficiency
create-contract-with max-one-of firms [ efficiency ]
[
set-contract-settings non-contracted-volume ; same as above
]
ask firms [
update-firm-processing ; same as above
]
]
end
;; contract values are set here and are used as reference for calculations
to set-contract-settings [ non-contracted-volume ]
set contract-period init-contract-period
set contracted-waste-agreed non-contracted-volume
set recycle-percentage-agreed [ offer-recycle-percent ] of other-end
set fine-cost 500000
set contract-price ( [ offer-cost ] of other-end )
;; if the collection infrastructure is decentralised, then the firms have spend more time and money on the collection of waste, so the price of a contract is increased
if [ collection-infra ] of myself = "decentralised" [
set contract-price contract-price * 1.01
]
;; at the start of a contract the month variable is set to 0
set contract-time-running 1
set present-post-separation-rate [offer-recycled-post] of other-end
end
;; Firms calculate and submit offers when municipalities release tenders
to submit-offer [ non-contracted-volume ]
Set offer-non-contracted-received non-contracted-volume
let pre-separate-percent-req mean [pre-separate-percent] of households ; proxy to account for pre-separated waste that will be received
Set offer-cost ((offer-non-contracted-received * waste-collect-cost) + (offer-non-contracted-received - (offer-non-contracted-received * pre-separate-percent-req))* operate-cost) ;; Calculating offer cost.
Set offer-recycled-post ((offer-non-contracted-received - (offer-non-contracted-received * pre-separate-percent-req)) * efficiency)
Set offer-recycled (offer-recycled-post + ((offer-non-contracted-received * pre-separate-percent-req )))
Set offer-recycle-percent (offer-recycled / offer-non-contracted-received)
firm-offer ; this is to check if the firm has enough spare capacity to actually make the bid
end
;; checking if firms can bid based on capacity and efficiency
to firm-offer
;; nested functions to check if firms can achieve target recycling percent followed by if they can actually process followed by whether they have cash-balance to invest
If-else offer-recycle-percent >= recycle-percent-target
[
if-else capacity-utilized < 0.9 * capacity
[
if factory-cash-balance > 0
[
Set can-bid? True
]
]
[
Set can-bid? False ; if cannot bid due to capacity, then check for cash balance and invest in capacity
if factory-cash-balance > 0
[
if capacity-improve? = False
[
Set capacity-improve? True
Set factory-cash-balance (factory-cash-balance - investment-capacity)
Set operate-cost (operate-cost + (capacity-effect-operate-cost * operate-cost))
Set capacity-improve-time 1
]
]
]
]
[
Set can-bid? False ; if not due to recycling target, then check cash-balance and ivenst in efficiency
if factory-cash-balance > 0
[
if tech-improve? = False
[
Set tech-improve? True
Set factory-cash-balance (factory-cash-balance - investment-tech)
Set operate-cost (operate-cost + (tech-effect-operate-cost * operate-cost))
Set tech-improve-time 1
]
]
]
end
;; check for already running capacity or technology improvements and update the firms capacity or efficiency
to check-facility-improve
ask firms
[
if capacity-improve? = True
[
if-else capacity-improve-time <= 12
[
Set capacity-improve-time (capacity-improve-time + 1)
]
[
Set capacity-improve-time 0
Set capacity (capacity + (capacity-improve-percent * capacity))
Set efficiency (efficiency + (capacity-effect-tech * efficiency)) ; capacity improvement effects efficiency as well
Set capacity-improve? False
]
]
if tech-improve? = True
[
if-else tech-improve-time < 12
[
Set tech-improve-time (tech-improve-time + 1)
]
[
Set tech-improve-time 0
Set efficiency (efficiency + (tech-improve-percent * efficiency)) ; efficiency improvement has no effect on capacity
Set tech-improve? False
]
]
]
end
;; update the utilized capacity once the contracts have been made
to update-firm-processing
set capacity-utilized sum [ contracted-waste-agreed ] of my-contracts
firm-offer ; go through investment cycle if required.
end
; municipality has to settle the expenditure from contracts
to settle-contract-prices
ask municipalities [
Set municipal-expenditure (municipal-expenditure + sum [ contract-price ] of my-contracts)
]
ask firms [
set factory-cash-balance (factory-cash-balance + sum [ contract-price ] of my-contracts) ; firms add to their cash balance the payments from municipality
]
end
;; Firms collect waste based on the contracts
to collect-waste
let total-waste-received-central sum [ actual-recyclable-waste ] of contract-neighbors with [ collection-infra = "centralised" ] ; proxy for all centralized waste collection since cost is different
let total-waste-received-decentral sum [ actual-recyclable-waste ] of contract-neighbors with [ collection-infra = "decentralised" ] ; proxy for all decentralized waste collection since cost is different
Set total-waste-received-firm (total-waste-received-central + total-waste-received-decentral)
Set total-pre-separated-received (total-waste-received-firm * (mean [pre-separate-percent] of households)) ; to see the applicability of fine
Set total-waste-post-separated ((total-waste-received-firm - total-pre-separated-received) * efficiency)
Set total-waste-recycled-firm (total-waste-post-separated + total-pre-separated-received)
ask my-contracts [
Set contract-efficiency [efficiency] of myself ; contracts update the recent efficiency value since this is required by the municipalities to update their recycling targets.
]
Set total-operating-cost ((total-waste-received-firm - total-pre-separated-received) * operate-cost)
Set total-collect-cost ((total-waste-received-central * waste-collect-cost) + (total-waste-received-decentral * waste-collect-cost * 1.01))
Set total-sell-earning ((sell-price-pre * total-pre-separated-received) + (sell-price-post * total-waste-post-separated)) ; calculate total earnings and expenditures of processing
end
to fine-check
ask municipalities [
; ;; municipalities can only pay fines if they have contracts
if count my-contracts > 0 [
let contract-value-difference 0
let fine-of-contract 0
;
; ;; determine if there is a difference between the amount of waste and the amount of waste in the contract
ask my-contracts [
set contract-value-difference (([ total-pre-separated-waste ] of myself ) - (( [actual-recyclable-waste] of myself ) * pre-separated-promised))
set fine-of-contract fine-cost
]
; ;; if there is not enough waste, pay the fine
if contract-value-difference < 0 [
;
set fine? true
set municipal-fine fine-of-contract
set municipal-fines-total municipal-fines-total + municipal-fine
set municipal-expenditure municipal-expenditure + municipal-fine
set total-fines total-fines + 1
ask contract-neighbors [
set factory-cash-balance factory-cash-balance + [ municipal-fine ] of myself ; allocate fine to the respective firms
set fine-earnings fine-earnings + [ municipal-fine ] of myself
]
]
]
]
end
;; Update the final cash balance
to compute-firm-expenditure
Set factory-cash-balance (factory-cash-balance + total-sell-earning - total-operating-cost + total-collect-cost)
end
;; run awareness programs if the national targets are not beine met
to awareness-programs
Set total-efficiency-received sum [contract-efficiency] of my-contracts
Set running-contracts count my-contracts
Let actual-efficiency-received (total-efficiency-received / (running-contracts)) ;; calculate the mean efficiency of all the contarcts to get aggregate overview
Set total-recycled-waste-municipality (((actual-recyclable-waste - total-pre-separated-waste) * (actual-efficiency-received)) + total-pre-separated-waste)
Set recycling-rate-achieved (total-recycled-waste-municipality / possible-recyclable-waste)
;; check the procativeness of the municipalities
if municipal-initiative-frequency <= initiative-tick
[
If recycling-rate-achieved < recycle-percent-target ; check if actual recycling rates are less than target to start awareness programs
[
set initiative-tick 0
if random-float 1 < Act-towards-recycling-target
[
ask households with [ municipality-belong = myself ]
[
Set is-awareness-training? True
Set is-knowledge-training? True
]
;; update the municipal exenditure after awareness programs
Set awareness-cost (education-program-cost * (count households with [ municipality-belong = myself ]) * 1000)
Set awareness-program awareness-program + 1
Set knowledge-cost (education-program-cost * (count households with [ municipality-belong = myself ]) * 1000)
Set knowledge-program knowledge-program + 1
Set education-cost knowledge-cost + awareness-cost
]
]
]
;; knowledge increase if not enough fines have been collected
If fine? = True
[
ask households with [ municipality-belong = myself ]
[
Set is-knowledge-training? True
]
Set knowledge-cost (education-program-cost * (count households with [ municipality-belong = myself ]) * 1000)
Set knowledge-program knowledge-program + 1
Set education-cost (education-cost + knowledge-cost)
Set fine? False
]
end
;;Compute final expenditures.
to compute-municipal-expenditure
Set municipal-expenditure (municipal-expenditure + education-cost)
end
;;;;;;;;;;;;;;;;;;;;;;
;;; Plot functions ;;;
;;;;;;;;;;;;;;;;;;;;;;
to plot-results
set-current-plot "Capacity Utilized for Firms"
ask firms [
create-temporary-plot-pen ( word who )
set-plot-pen-color color
plot capacity-utilized
]
set-current-plot "Capacity of Firms"
ask firms [
create-temporary-plot-pen ( word who )
set-plot-pen-color color
plot capacity
]
set-current-plot "Awareness Increase"
ask municipalities [
create-temporary-plot-pen ( word who )
set-plot-pen-color color
plot mean [perception-to-recycle] of households with [ municipality-belong = myself ]
]
set-current-plot "Operating Efficiency of Firms"
ask firms [
create-temporary-plot-pen ( word who )
set-plot-pen-color color
plot efficiency
]
set-current-plot "Operation Cost for Firms"
ask firms [
create-temporary-plot-pen ( word who )
set-plot-pen-color color
plot operate-cost
]
set-current-plot "Cash Balance Firms"
ask firms [
create-temporary-plot-pen ( word who )
set-plot-pen-color color
plot factory-cash-balance
]
set-current-plot "Municipal Expenditure"
ask municipalities [
create-temporary-plot-pen ( word who )
set-plot-pen-color color
plot municipal-expenditure
]
set-current-plot "Recycling Rate Achieved per Municipality"
ask municipalities [
create-temporary-plot-pen ( word who )
set-plot-pen-color color
plot recycling-rate-achieved
]
set-current-plot "Fines Payed"
ask municipalities [
create-temporary-plot-pen ( word who )
set-plot-pen-color color
plot municipal-fines-total
]
set-current-plot "Running Contracts per Municipality"
ask municipalities [
create-temporary-plot-pen ( word who )
set-plot-pen-color color
plot running-contracts
]
set-current-plot "Actual Waste produced per Municipality"
ask municipalities [
create-temporary-plot-pen ( word who )
set-plot-pen-color color
plot actual-recyclable-waste
]
end
@#$#@#$#@
GRAPHICS-WINDOW
374
291
892
810
-1
-1
15.455
1
10
1
1
1
0
0
0
1
-16
16
-16
16
0
0
1
ticks
30.0
SLIDER
8
52
184
85
init-capacity
init-capacity
20000
100000
75000.0
5000
1
NIL
HORIZONTAL
SLIDER
8
88
184
121
init-efficiency
init-efficiency
0
1
0.2
0.01
1
NIL
HORIZONTAL
SLIDER
9
124
184
157
capacity-improve-percent
capacity-improve-percent
0
0.5
0.1
0.05
1
NIL
HORIZONTAL
SLIDER
9
160
185
193
tech-improve-percent
tech-improve-percent
0
0.5
0.06
0.01
1
NIL
HORIZONTAL
SLIDER
575
50
759
83
initial-recycle-percent-target
initial-recycle-percent-target
0
1
0.5
0.05
1
NIL
HORIZONTAL
SLIDER
575
121
760
154
possible-recycle-percent
possible-recycle-percent
0
0.8
0.8
0.1
1
NIL
HORIZONTAL
SLIDER
380
50
564
83
total-municipalities
total-municipalities
1
60
6.0
1
1
NIL
HORIZONTAL
SLIDER
382
160
565
193
percent-centralized-infra
percent-centralized-infra
0
1
0.5
0.1
1
NIL
HORIZONTAL
SLIDER
195
51
373
84
init-perception-to-recycle
init-perception-to-recycle
0
0.8
0.3
0.01
1
NIL
HORIZONTAL
SLIDER
195
125
376
158
init-awareness-effectiveness
init-awareness-effectiveness
0
0.2
0.02
0.01
1
NIL
HORIZONTAL
SLIDER
196
88
375
121
init-pre-separate-percent
init-pre-separate-percent
0
1
0.4
0.01
1
NIL
HORIZONTAL
SLIDER
195
160
376
193
init-knowledge-effectiveness
init-knowledge-effectiveness
0
0.2
0.01
0.01
1
NIL
HORIZONTAL
SLIDER
381
123
564
156
init-contract-period
init-contract-period
0
50
36.0
1
1
NIL
HORIZONTAL
SLIDER
380
87
564
120
pre-separated-promised
pre-separated-promised
0
1
0.25
0.05
1
NIL
HORIZONTAL
BUTTON
575
161
630
194
NIL
setup
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
634
161
689
194
NIL
go
T
1