-
Notifications
You must be signed in to change notification settings - Fork 0
/
PES.R
882 lines (713 loc) · 30.7 KB
/
PES.R
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
### This script is for the second part of my final PhD chapter. The analysis is investigating the potential effects of PES on the system dynamics of a social-ecological system. I will be using the same landscape and model set up as in part A - i.e., a landscape with farmers, where the human population is increasing, and thus the human pressure on the lsandscape is increasing (via the user budget). I will also start by testing the addition of PES payments on the investment scenarios from part A.
### Load libraries ####
library('tidyverse')
library('GMSE')
library('patchwork')
library('viridis')
library('scales')
library('devtools')
############## LANDSCAPE DETAILS ##################
# Study period- 50 years
# Landscape dimensions - 100 x 100 cells. which results in 10,000 cells (or ha). With 30 villages, this results in 333.33 ha or 3.33km2 per village. The number of trees is 100,000
# There is no public land. It does not serve any purpose in this study.
# "Resources" are trees. The resources therefore do not move.
# The density of trees in tropical forest landscapes vary hugely. In previous simulations I have assumed 50 stems/ha which is low, but not implausible (e.g. deciduous dipterocarp woodland). A reference for this value can be found here:https://www.jstor.org/stable/44521915. This resulted in >1M trees, which meant that the differences in trees lost between scenarios, and the total number of trees lost, were too low. In the final scenarios, the number of trees was set to 100,000. Note that the trees are distributed randomly across the landscape, and so there will not be exactly 50/cell. This reflects reality.
# Trees in a cell reduce the farmer's yield. The amount a tree reduces yield is governed by an exponential function: yield = (1 - % yield reduction per tree) ^ remaining trees. I want a farmer's yield to be reduced by a significant amount if all trees in a cell are standing. But the trees do not completely eliminate yield. This is a balance between the farmer being able to farm and gain some yield even when there are trees on their cell, but also providing an incentive to cull where possible. I have set each tree on a cell to reduce yield by 8%. See the N1:N1f scenario comparisons which were used to decide on the parameter values for res_consume and tendcrop_yield
# The amount a user can increase their yield by tending crops is governed by tend_crop_yld. I have set this at 0.01 (1%) which means they can increase their yield on a cell by 1% in a single time step if they choose to tend crops. This is lower than the yield gain they would make if they felled some trees. This is set up so that there is an incentive to fell trees and expand their farmland, as it will increase their yield. See the N1:N1f scenario comparisons which were used to decide on the parameter values for res_consume and tendcrop_yield
# For simplicity, I am assuming there is no natural death and no natural birth (forest regeneration). remove_pr is set to 0, and lambda is set to 0, and res_death_type is set to 0 (new value created by Brad that means no natural death at all)
# The carrying capacity of new resources is set to 1 as it has to be a positive number but I want it as low as possible i.e. there is no real recruitment
# res_death_type is set to 0 (no natural death).
# The observation process is set to density-based sampling, with 1 observation per time step. The manager can move in any direction. Currently the manager can see 150 cells, and move 50 cells. We decided to remove any observation error.
# There is no minimum age for resources to be acted upon i.e. all trees in the landscape can be observed/culled
# Agents are permitted to move at the end of each time step. Because land_ownership==TRUE I believe this then only relates to the manager.
# User and manager budgets will vary based on the scenario. But the total amount of budget available to the manager for the whole study period will be the same. The total is 25,000. See the "scenario_details_budgets" spreadsheet
# Group_think == FALSE, and so users act independently
# Both culling and feeding are allowed. Culling is cutting down trees to increase yield. Feeding is going to be the hack to introduce PES. I will use the parameter perceive_feed to alter the way the users view feeding of the resource. Normally, feeding will increase the population of the resource, and therefore usually, in these circumstances, the users would not want that because resources reduce their yield. But we can set perceive_feed to a negative value, which will make the user think that feeding actually reduces the resources (i.e., it is beneficial to them). Therefore, the manager can use some of their budget to set the cost of feeding low, and depending on the value of perceive_feed, the users may choose to "feed" (i.e., collect a PES), rather than culling. So it is a way of offering the users an alternative option to culling.
# farming is allowed (tend_crops==TRUE, i.e. farmers can increase their yield by tending their crops rather than felling trees)
### Test 1:3 ####
# I will start with the code that Brad sent on GitHub (https://github.com/ConFooBio/gmse/issues/64). This is just to see how it runs
### no feeding
Test_1 <- gmse_apply(land_dim_1 = 150, land_dim_2 = 150, stakeholders = 20,
land_ownership = TRUE, res_move_type = 0, res_death_type = 0,
lambda = 0, res_consume = 0.08, RESOURCE_ini = 10000,
manage_target = 10000, feeding = FALSE)
Test_1$manager_results
Test_1$user_results
### perceive_feed set low
Test_2 <- gmse_apply(land_dim_1 = 150, land_dim_2 = 150, stakeholders = 20,
land_ownership = TRUE, res_move_type = 0, res_death_type = 0,
lambda = 0, res_consume = 0.08, RESOURCE_ini = 10000,
manage_target = 10000, feeding = TRUE, perceive_feed = -0.1)
Test_2$manager_results
Test_2$user_results
# Users choose to feed once - not really very popular
### perceive_feed set high
Test_3 <- gmse_apply(land_dim_1 = 150, land_dim_2 = 150, stakeholders = 20,
land_ownership = TRUE, res_move_type = 0, res_death_type = 0,
lambda = 0, res_consume = 0.08, RESOURCE_ini = 10000,
manage_target = 10000, feeding = TRUE, perceive_feed = -1.0)
Test_3$manager_results
Test_3$user_results
# Users now choose to take the PES payments instead of culling
### Test 4, -0.5 ####
# now I will run it over multiple time steps, with a static perceive_feed, set at -0.5
Test_4_sim_old <- gmse_apply(
res_mod = resource,
obs_mod = observation,
man_mod = manager,
use_mod = user,
get_res = "FUll",
time_max = 30,
land_dim_1 = 100,
land_dim_2 = 100,
res_movement = 0,
agent_view = 150,
agent_move = 50,
res_move_type = 0,
res_death_type = 0,
lambda = 0,
observe_type = 2,
times_observe = 1,
obs_move_type = 1,
res_min_age = 0,
res_move_obs = FALSE,
plotting = FALSE,
res_consume = 0.08,
# all genetic algorithm parameters left to default
move_agents = TRUE,
max_ages = 1000,
minimum_cost = 10,
user_budget = 1000,
manager_budget = 1000,
usr_budget_rng = 100,
manage_target = 100000,
RESOURCE_ini = 100000,
culling = TRUE,
feeding = TRUE,
perceive_feed = -0.5,
tend_crops = TRUE,
tend_crop_yld = 0.01,
stakeholders = 30,
land_ownership = TRUE,
public_land = 0,
manage_freq = 1,
group_think = FALSE
)
# matrix for results
Test_4 <- matrix(data=NA, nrow=30, ncol=7)
# loop the simulation.
for(time_step in 1:30){
sim_new <- gmse_apply(get_res = "Full", old_list = Test_4_sim_old)
Test_4[time_step, 1] <- time_step
Test_4[time_step, 2] <- sim_new$basic_output$resource_results[1]
Test_4[time_step, 3] <- sim_new$basic_output$observation_results[1]
Test_4[time_step, 4] <- sim_new$basic_output$manager_results[3]
Test_4[time_step, 5] <- sum(sim_new$basic_output$user_results[,3])
Test_4[time_step, 6] <- sim_new$basic_output$manager_results[5]
Test_4[time_step, 7] <- sum(sim_new$basic_output$user_results[,5])
Test_4_sim_old <- sim_new
print(time_step)
}
colnames(Test_4) <- c("Time", "Trees", "Trees_est", "Cull_cost", "Cull_count", "Feed_cost", "Feed_count")
Test_4_summary <- data.frame(Test_4)
write.csv(Test_4_summary, file="outputs/pes/test_runs/Test_4_summary.csv")
### Test 5, -0.4 ####
# now I will run it over multiple time steps, with a static perceive_feed, set at -0.4
Test_5_sim_old <- gmse_apply(
res_mod = resource,
obs_mod = observation,
man_mod = manager,
use_mod = user,
get_res = "FUll",
time_max = 30,
land_dim_1 = 100,
land_dim_2 = 100,
res_movement = 0,
agent_view = 150,
agent_move = 50,
res_move_type = 0,
res_death_type = 0,
lambda = 0,
observe_type = 2,
times_observe = 1,
obs_move_type = 1,
res_min_age = 0,
res_move_obs = FALSE,
plotting = FALSE,
res_consume = 0.08,
# all genetic algorithm parameters left to default
move_agents = TRUE,
max_ages = 1000,
minimum_cost = 10,
user_budget = 1000,
manager_budget = 1000,
usr_budget_rng = 100,
manage_target = 100000,
RESOURCE_ini = 100000,
culling = TRUE,
feeding = TRUE,
perceive_feed = -0.4,
tend_crops = TRUE,
tend_crop_yld = 0.01,
stakeholders = 30,
land_ownership = TRUE,
public_land = 0,
manage_freq = 1,
group_think = FALSE
)
# matrix for results
Test_5 <- matrix(data=NA, nrow=30, ncol=7)
# loop the simulation.
for(time_step in 1:30){
sim_new <- gmse_apply(get_res = "Full", old_list = Test_5_sim_old)
Test_5[time_step, 1] <- time_step
Test_5[time_step, 2] <- sim_new$basic_output$resource_results[1]
Test_5[time_step, 3] <- sim_new$basic_output$observation_results[1]
Test_5[time_step, 4] <- sim_new$basic_output$manager_results[3]
Test_5[time_step, 5] <- sum(sim_new$basic_output$user_results[,3])
Test_5[time_step, 6] <- sim_new$basic_output$manager_results[5]
Test_5[time_step, 7] <- sum(sim_new$basic_output$user_results[,5])
Test_5_sim_old <- sim_new
print(time_step)
}
colnames(Test_5) <- c("Time", "Trees", "Trees_est", "Cull_cost", "Cull_count", "Feed_cost", "Feed_count")
Test_5_summary <- data.frame(Test_5)
write.csv(Test_5_summary, file="outputs/pes/test_runs/Test_5_summary.csv")
### Test 6, -0.3 ####
# now I will run it over multiple time steps, with a static perceive_feed, set at -0.3
Test_6_sim_old <- gmse_apply(
res_mod = resource,
obs_mod = observation,
man_mod = manager,
use_mod = user,
get_res = "FUll",
time_max = 30,
land_dim_1 = 100,
land_dim_2 = 100,
res_movement = 0,
agent_view = 150,
agent_move = 50,
res_move_type = 0,
res_death_type = 0,
lambda = 0,
observe_type = 2,
times_observe = 1,
obs_move_type = 1,
res_min_age = 0,
res_move_obs = FALSE,
plotting = FALSE,
res_consume = 0.08,
# all genetic algorithm parameters left to default
move_agents = TRUE,
max_ages = 1000,
minimum_cost = 10,
user_budget = 1000,
manager_budget = 1000,
usr_budget_rng = 100,
manage_target = 100000,
RESOURCE_ini = 100000,
culling = TRUE,
feeding = TRUE,
perceive_feed = -0.3,
tend_crops = TRUE,
tend_crop_yld = 0.01,
stakeholders = 30,
land_ownership = TRUE,
public_land = 0,
manage_freq = 1,
group_think = FALSE
)
# matrix for results
Test_6 <- matrix(data=NA, nrow=30, ncol=7)
# loop the simulation.
for(time_step in 1:30){
sim_new <- gmse_apply(get_res = "Full", old_list = Test_6_sim_old)
Test_6[time_step, 1] <- time_step
Test_6[time_step, 2] <- sim_new$basic_output$resource_results[1]
Test_6[time_step, 3] <- sim_new$basic_output$observation_results[1]
Test_6[time_step, 4] <- sim_new$basic_output$manager_results[3]
Test_6[time_step, 5] <- sum(sim_new$basic_output$user_results[,3])
Test_6[time_step, 6] <- sim_new$basic_output$manager_results[5]
Test_6[time_step, 7] <- sum(sim_new$basic_output$user_results[,5])
Test_6_sim_old <- sim_new
print(time_step)
}
colnames(Test_6) <- c("Time", "Trees", "Trees_est", "Cull_cost", "Cull_count", "Feed_cost", "Feed_count")
Test_6_summary <- data.frame(Test_6)
write.csv(Test_6_summary, file="outputs/pes/test_runs/Test_6_summary.csv")
### Test 7, -0.2 ####
# now I will run it over multiple time steps, with a static perceive_feed, set at -0.2
Test_7_sim_old <- gmse_apply(
res_mod = resource,
obs_mod = observation,
man_mod = manager,
use_mod = user,
get_res = "FUll",
time_max = 30,
land_dim_1 = 100,
land_dim_2 = 100,
res_movement = 0,
agent_view = 150,
agent_move = 50,
res_move_type = 0,
res_death_type = 0,
lambda = 0,
observe_type = 2,
times_observe = 1,
obs_move_type = 1,
res_min_age = 0,
res_move_obs = FALSE,
plotting = FALSE,
res_consume = 0.08,
# all genetic algorithm parameters left to default
move_agents = TRUE,
max_ages = 1000,
minimum_cost = 10,
user_budget = 1000,
manager_budget = 1000,
usr_budget_rng = 100,
manage_target = 100000,
RESOURCE_ini = 100000,
culling = TRUE,
feeding = TRUE,
perceive_feed = -0.2,
tend_crops = TRUE,
tend_crop_yld = 0.01,
stakeholders = 30,
land_ownership = TRUE,
public_land = 0,
manage_freq = 1,
group_think = FALSE
)
# matrix for results
Test_7 <- matrix(data=NA, nrow=30, ncol=7)
# loop the simulation.
for(time_step in 1:30){
sim_new <- gmse_apply(get_res = "Full", old_list = Test_7_sim_old)
Test_7[time_step, 1] <- time_step
Test_7[time_step, 2] <- sim_new$basic_output$resource_results[1]
Test_7[time_step, 3] <- sim_new$basic_output$observation_results[1]
Test_7[time_step, 4] <- sim_new$basic_output$manager_results[3]
Test_7[time_step, 5] <- sum(sim_new$basic_output$user_results[,3])
Test_7[time_step, 6] <- sim_new$basic_output$manager_results[5]
Test_7[time_step, 7] <- sum(sim_new$basic_output$user_results[,5])
Test_7_sim_old <- sim_new
print(time_step)
}
colnames(Test_7) <- c("Time", "Trees", "Trees_est", "Cull_cost", "Cull_count", "Feed_cost", "Feed_count")
Test_7_summary <- data.frame(Test_7)
write.csv(Test_7_summary, file="outputs/pes/test_runs/Test_7_summary.csv")
### Results tests 4:10 ####
# load in results
test4 <- read.csv(file="outputs/pes/test_runs/Test_4_summary.csv")
test5 <- read.csv(file="outputs/pes/test_runs/Test_5_summary.csv")
test6 <- read.csv(file="outputs/pes/test_runs/Test_6_summary.csv")
test7 <- read.csv(file="outputs/pes/test_runs/Test_7_summary.csv")
test8 <- read.csv(file="outputs/pes/test_runs/Test_8_summary.csv")
test9 <- read.csv(file="outputs/pes/test_runs/Test_9_summary.csv")
test10 <- read.csv(file="outputs/pes/test_runs/Test_10_summary.csv")
# add perceive_feeding
test4$perc_feed <- "-0.5"
test8$perc_feed <- "-0.45"
test5$perc_feed <- "-0.4"
test9$perc_feed <- "-0.35"
test6$perc_feed <- "-0.3"
test10$perc_feed <- "-0.25"
test7$perc_feed <- "-0.2"
# merge
test_all <- rbind(test4,test8,test5,test9,test6,test10,test7)
test_all <- test_all[, -1]
# calculate what percentage of all actions were feeding and culling
test_all$feed_percent <- (test_all[,7] / (test_all[,7] + test_all[,5]))*100
test_all$cull_percent <- ifelse(test_all$feed_percent==100,0,100-test_all$feed_percent)
## plots
# proportion of action that were feeding
prop_feed <- ggplot(test_all, aes(x=Time, y=feed_percent, group=perc_feed, color=perc_feed))+
geom_line(size=1)+
theme_classic()+
theme(axis.title = element_text(size=15),
axis.text = element_text(size=15),
legend.text = element_text(size=15),
legend.title = element_text(size=15))+
facet_wrap(~perc_feed)+
ylab("PES actions (% of total)")+
ggtitle("a")
# cost of feeding
cost_feed <- ggplot(test_all, aes(x=Time, y=Feed_cost, group=perc_feed, color=perc_feed))+
geom_line(size=1)+
theme_classic()+
theme(axis.title = element_text(size=15),
axis.text = element_text(size=15),
legend.text = element_text(size=15),
legend.title = element_text(size=15))+
facet_wrap(~perc_feed)+
ylab("Cost of PES action")+
ggtitle("b")
# proportion of actions that were culling
prop_cull <- ggplot(test_all, aes(x=Time, y=cull_percent, group=perc_feed, color=perc_feed))+
geom_line(size=1)+
theme_classic()+
theme(axis.title = element_text(size=15),
axis.text = element_text(size=15),
legend.text = element_text(size=15),
legend.title = element_text(size=15))+
facet_wrap(~perc_feed)+
ylab("Felling actions (% of total)")+
ggtitle("c")
# cost of culling
cost_cull <- ggplot(test_all, aes(x=Time, y=Cull_cost, group=perc_feed, color=perc_feed))+
geom_line(size=1)+
theme_classic()+
theme(axis.title = element_text(size=15),
axis.text = element_text(size=15),
legend.text = element_text(size=15),
legend.title = element_text(size=15))+
facet_wrap(~perc_feed)+
ylab("Cost of felling action")+
ggtitle("d")
static_perc_feed <- prop_feed + cost_feed + prop_cull + cost_cull
ggsave(filename = "outputs/pes/test_runs/plots/static_perc_feed.png", static_perc_feed,
width = 35, height = 30, units="cm", dpi=300)
## from the results above, it is clear that the perceive_feed value cannot be above -0.3, otherwise the users will choose to take the PES every single time step. I guess -0.35 could be the maximum value the parameter should go up to, i.e., the ceiling. And I guess 0 should be the floor? I want to now run some simulations with the PES value changing throughout the simulation. This should give more detail about how decisions change with changing values.
### Test 11 ####
# Here I want to vary the perceive_feed over the time steps, and see what happens.
# create vector of perceive_feed values
perc_f <- seq(0,-0.35, length.out = 30)
PF <- perc_f[1]
Test_11_sim_old <- gmse_apply(
res_mod = resource,
obs_mod = observation,
man_mod = manager,
use_mod = user,
get_res = "FUll",
time_max = 30,
land_dim_1 = 100,
land_dim_2 = 100,
res_movement = 0,
agent_view = 150,
agent_move = 50,
res_move_type = 0,
res_death_type = 0,
lambda = 0,
observe_type = 2,
times_observe = 1,
obs_move_type = 1,
res_min_age = 0,
res_move_obs = FALSE,
plotting = FALSE,
res_consume = 0.08,
# all genetic algorithm parameters left to default
move_agents = TRUE,
max_ages = 1000,
minimum_cost = 10,
user_budget = 1000,
manager_budget = 1000,
usr_budget_rng = 100,
manage_target = 100000,
RESOURCE_ini = 100000,
culling = TRUE,
feeding = TRUE,
perceive_feed = PF,
tend_crops = TRUE,
tend_crop_yld = 0.01,
stakeholders = 30,
land_ownership = TRUE,
public_land = 0,
manage_freq = 1,
group_think = FALSE
)
# matrix for results
Test_11 <- matrix(data=NA, nrow=30, ncol=7)
# loop the simulation.
for(time_step in 1:30){
sim_new <- gmse_apply(get_res = "Full", old_list = Test_11_sim_old, perceive_feed = PF)
Test_11[time_step, 1] <- time_step
Test_11[time_step, 2] <- sim_new$basic_output$resource_results[1]
Test_11[time_step, 3] <- sim_new$basic_output$observation_results[1]
Test_11[time_step, 4] <- sim_new$basic_output$manager_results[3]
Test_11[time_step, 5] <- sum(sim_new$basic_output$user_results[,3])
Test_11[time_step, 6] <- sim_new$basic_output$manager_results[5]
Test_11[time_step, 7] <- sum(sim_new$basic_output$user_results[,5])
Test_11_sim_old <- sim_new
PF <- perc_f[time_step]
print(time_step)
}
colnames(Test_11) <- c("Time", "Trees", "Trees_est", "Cull_cost", "Cull_count", "Feed_cost", "Feed_count")
Test_11_summary <- data.frame(Test_11)
Test_11_summary$perceive_feed <- perc_f
write.csv(Test_11_summary, file="outputs/pes/test_runs/Test_11_summary.csv")
count_value <- ggplot(Test_11_summary, aes(x=perceive_feed, y=Feed_count))+
geom_line(size=1)+
theme_classic()+
theme(axis.title = element_text(size=15),
axis.text = element_text(size=15),
plot.title = element_text(size=20))+
ylab("Count of PES actions")+
xlab("perceive_feed value")+
scale_x_reverse()+
ggtitle("a")
feed_cost <- ggplot(Test_11_summary, aes(x=perceive_feed, y=Feed_cost))+
geom_line(size=1)+
theme_classic()+
theme(axis.title = element_text(size=15),
axis.text = element_text(size=15),
plot.title = element_text(size=20))+
ylab("Cost of PES actions")+
xlab("perceive_feed value")+
scale_x_reverse()+
ylim(0,110)+
ggtitle("b")
fell_count <- ggplot(Test_11_summary, aes(x=perceive_feed, y=Cull_count))+
geom_line(size=1)+
theme_classic()+
theme(axis.title = element_text(size=15),
axis.text = element_text(size=15),
plot.title = element_text(size=20))+
ylab("Count of felling actions")+
xlab("perceive_feed value")+
scale_x_reverse()+
ggtitle("c")
fell_cost <- ggplot(Test_11_summary, aes(x=perceive_feed, y=Cull_cost))+
geom_line(size=1)+
theme_classic()+
theme(axis.title = element_text(size=15),
axis.text = element_text(size=15),
plot.title = element_text(size=20))+
ylab("Cost of felling actions")+
xlab("perceive_feed value")+
scale_x_reverse()+
ylim(0,110)+
ggtitle("d")
test11_plots <- count_value + feed_cost + fell_count + fell_cost
### Test 12 ####
# Here I want to vary the perceive_feed more than above. There didn't seem to be many users taking the PES option, even at the higher end of the perceive_feed
# create vector of perceive_feed values
perc_f <- seq(0,-0.5, length.out = 50)
PF <- perc_f[1]
Test_12_sim_old <- gmse_apply(
res_mod = resource,
obs_mod = observation,
man_mod = manager,
use_mod = user,
get_res = "FUll",
time_max = 50,
land_dim_1 = 100,
land_dim_2 = 100,
res_movement = 0,
agent_view = 150,
agent_move = 50,
res_move_type = 0,
res_death_type = 0,
lambda = 0,
observe_type = 2,
times_observe = 1,
obs_move_type = 1,
res_min_age = 0,
res_move_obs = FALSE,
plotting = FALSE,
res_consume = 0.08,
# all genetic algorithm parameters left to default
move_agents = TRUE,
max_ages = 1000,
minimum_cost = 10,
user_budget = 1000,
manager_budget = 1000,
usr_budget_rng = 100,
manage_target = 100000,
RESOURCE_ini = 100000,
culling = TRUE,
feeding = TRUE,
perceive_feed = PF,
tend_crops = TRUE,
tend_crop_yld = 0.01,
stakeholders = 30,
land_ownership = TRUE,
public_land = 0,
manage_freq = 1,
group_think = FALSE
)
# matrix for results
Test_12 <- matrix(data=NA, nrow=50, ncol=7)
# loop the simulation.
for(time_step in 1:50){
sim_new <- gmse_apply(get_res = "Full", old_list = Test_12_sim_old, perceive_feed = PF)
Test_12[time_step, 1] <- time_step
Test_12[time_step, 2] <- sim_new$basic_output$resource_results[1]
Test_12[time_step, 3] <- sim_new$basic_output$observation_results[1]
Test_12[time_step, 4] <- sim_new$basic_output$manager_results[3]
Test_12[time_step, 5] <- sum(sim_new$basic_output$user_results[,3])
Test_12[time_step, 6] <- sim_new$basic_output$manager_results[5]
Test_12[time_step, 7] <- sum(sim_new$basic_output$user_results[,5])
Test_12_sim_old <- sim_new
PF <- perc_f[time_step]
print(time_step)
}
colnames(Test_12) <- c("Time", "Trees", "Trees_est", "Cull_cost", "Cull_count", "Feed_cost", "Feed_count")
Test_12_summary <- data.frame(Test_12)
Test_12_summary$perceive_feed <- perc_f
#write.csv(Test_12_summary, file="outputs/pes/test_runs/Test_12_summary.csv")
# load results
Test_12_summary <- read.csv("outputs/pes/test_runs/Test_12_summary.csv")
count_value <- ggplot(Test_12_summary, aes(x=perceive_feed, y=Feed_count))+
geom_line(size=1)+
theme_classic()+
theme(axis.title = element_text(size=15),
axis.text = element_text(size=15),
plot.title = element_text(size=20))+
ylab("Count of PES actions")+
xlab("perceive_feed value")+
scale_x_reverse()+
ggtitle("a")
feed_cost <- ggplot(Test_12_summary, aes(x=perceive_feed, y=Feed_cost))+
geom_line(size=1)+
theme_classic()+
theme(axis.title = element_text(size=15),
axis.text = element_text(size=15),
plot.title = element_text(size=20))+
ylab("Cost of PES actions")+
xlab("perceive_feed value")+
scale_x_reverse()+
ylim(0,110)+
ggtitle("b")
fell_count <- ggplot(Test_12_summary, aes(x=perceive_feed, y=Cull_count))+
geom_line(size=1)+
theme_classic()+
theme(axis.title = element_text(size=15),
axis.text = element_text(size=15),
plot.title = element_text(size=20))+
ylab("Count of felling actions")+
xlab("perceive_feed value")+
scale_x_reverse()+
ggtitle("c")
fell_cost <- ggplot(Test_12_summary, aes(x=perceive_feed, y=Cull_cost))+
geom_line(size=1)+
theme_classic()+
theme(axis.title = element_text(size=15),
axis.text = element_text(size=15),
plot.title = element_text(size=20))+
ylab("Cost of felling actions")+
xlab("perceive_feed value")+
scale_x_reverse()+
ylim(0,110)+
ggtitle("d")
test12_plots <- count_value + feed_cost + fell_count + fell_cost
ggplot(Test_12_summary, aes(x=Time, y=Feed_count))+
geom_line()
### Test 13 ####
# following Brad's suggestion, I am going to vary perceive_feed much more than above, to an extreme of -20
perc_f <- seq(0,-20, length.out = 50)
PF <- perc_f[1]
Test_13_sim_old <- gmse_apply(
res_mod = resource,
obs_mod = observation,
man_mod = manager,
use_mod = user,
get_res = "FUll",
time_max = 50,
land_dim_1 = 100,
land_dim_2 = 100,
res_movement = 0,
agent_view = 150,
agent_move = 50,
res_move_type = 0,
res_death_type = 0,
lambda = 0,
observe_type = 2,
times_observe = 1,
obs_move_type = 1,
res_min_age = 0,
res_move_obs = FALSE,
plotting = FALSE,
res_consume = 0.08,
# all genetic algorithm parameters left to default
move_agents = TRUE,
max_ages = 1000,
minimum_cost = 10,
user_budget = 1000,
manager_budget = 1000,
usr_budget_rng = 100,
manage_target = 100000,
RESOURCE_ini = 100000,
culling = TRUE,
feeding = TRUE,
perceive_feed = PF,
tend_crops = TRUE,
tend_crop_yld = 0.01,
stakeholders = 30,
land_ownership = TRUE,
public_land = 0,
manage_freq = 1,
group_think = FALSE
)
# matrix for results
Test_13 <- matrix(data=NA, nrow=50, ncol=8)
# loop the simulation.
for(time_step in 1:50){
sim_new <- gmse_apply(get_res = "Full", old_list = Test_13_sim_old, perceive_feed = PF)
Test_13[time_step, 1] <- time_step
Test_13[time_step, 2] <- sim_new$basic_output$resource_results[1]
Test_13[time_step, 3] <- sim_new$basic_output$observation_results[1]
Test_13[time_step, 4] <- sim_new$basic_output$manager_results[3]
Test_13[time_step, 5] <- sum(sim_new$basic_output$user_results[,3])
Test_13[time_step, 6] <- sim_new$basic_output$manager_results[5]
Test_13[time_step, 7] <- sum(sim_new$basic_output$user_results[,5])
Test_13[time_step, 8] <- sim_new$AGENTS[2,21]
Test_13_sim_old <- sim_new
PF <- perc_f[time_step]
print(PF)
}
colnames(Test_13) <- c("Time", "Trees", "Trees_est", "Cull_cost", "Cull_count", "Feed_cost", "Feed_count",
"Perceive_feed")
Test_13_summary <- data.frame(Test_13)
Test_13_summary$perceive_feed <- perc_f
#write.csv(Test_13_summary, file="outputs/pes/test_runs/Test_13_summary.csv")
sim_new$AGENTS
# load results
Test_13_summary <- read.csv("outputs/pes/test_runs/Test_12_summary.csv")
count_value <- ggplot(Test_13_summary, aes(x=perceive_feed, y=Feed_count))+
geom_line(size=1)+
theme_classic()+
theme(axis.title = element_text(size=15),
axis.text = element_text(size=15),
plot.title = element_text(size=20))+
ylab("Count of PES actions")+
xlab("perceive_feed value")+
scale_x_reverse()+
ggtitle("a")
feed_cost <- ggplot(Test_13_summary, aes(x=perceive_feed, y=Feed_cost))+
geom_line(size=1)+
theme_classic()+
theme(axis.title = element_text(size=15),
axis.text = element_text(size=15),
plot.title = element_text(size=20))+
ylab("Cost of PES actions")+
xlab("perceive_feed value")+
scale_x_reverse()+
ylim(0,110)+
ggtitle("b")
fell_count <- ggplot(Test_13_summary, aes(x=perceive_feed, y=Cull_count))+
geom_line(size=1)+
theme_classic()+
theme(axis.title = element_text(size=15),
axis.text = element_text(size=15),
plot.title = element_text(size=20))+
ylab("Count of felling actions")+
xlab("perceive_feed value")+
scale_x_reverse()+
ggtitle("c")
fell_cost <- ggplot(Test_13_summary, aes(x=perceive_feed, y=Cull_cost))+
geom_line(size=1)+
theme_classic()+
theme(axis.title = element_text(size=15),
axis.text = element_text(size=15),
plot.title = element_text(size=20))+
ylab("Cost of felling actions")+
xlab("perceive_feed value")+
scale_x_reverse()+
ylim(0,110)+
ggtitle("d")
test13_plots <- count_value + feed_cost + fell_count + fell_cost
ggplot(Test_13_summary, aes(x=Time, y=Feed_count))+
geom_line()
### Test 14 ####
# Test 13 did not work - the users are still not choosing to take PES over felling. Below I will test the static