-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorkshop_prioriactions_IEB_2022.Rmd
1202 lines (829 loc) · 29.4 KB
/
Workshop_prioriactions_IEB_2022.Rmd
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
---
title: "Prioriactions in Action"
author: "**José Salgado-Rojas / Matías Moreno-Faguett**"
date: "December 16, 2022"
output:
ioslides_presentation:
incremental: false
ccs: styles.css
keep_md: yes
logo: Figures/Logo.png
widescreen: yes
df_print: paged
smaller: yes
beamer_presentation: default
subtitle: Tutorial for ``R`` Users <br>![CRAN/METACRAN](https://www.r-pkg.org/badges/version/prioriactions)
bibliography: bibtex.bib
editor_options:
markdown:
wrap: 72
---
```{=html}
<!---
- ioslides manual:
https://bookdown.org/yihui/rmarkdown/ioslides-presentation.html
- Compile from command-line
Rscript -e "rmarkdown::render('R_for_HPC.Rmd'); knitr::knit('R_for_HPC.Rmd', tangle=TRUE)"
-->
```
```{=html}
<!---
Note: following css chunks are required for scrolling support beyond slide boundaries
-->
```
```{=html}
<style>
slides > slide {
overflow-x: auto !important;
overflow-y: auto !important;
}
slides > slide.title-slide p {
color: black;
}
slides > slide.title-slide hgroup h1{
color: #4C7843;
}
</style>
```
```{css, echo=FALSE}
pre {
max-height: 300px;
overflow-y: auto;
}
pre[class] {
max-height: 300px;
}
```
```{css, echo=FALSE}
.scroll-300 {
max-height: 300px;
overflow-y: auto;
background-color: inherit;
}
```
##
### <https://github.com/prioriactions/teaching>
# Outline
- ::: white
**Features**
:::
- Overview
- Toy example
- Actual case study: The Mitchell River, Australia
- Shiny Application
## Why ![](Figures/r_logo.png){#id .class width="8%" height="8%"}?
Reproducibility, Academic use, ...
<center>![Source: https://medium.com](Figures/whyr.webp){.class
width="60%" height="60%"}</center>
## Features
::: {style="float: left; width: 50%;"}
<br>
- [Powered by **Rcpp and RcppArmadillo**]{style=""}
<img src="Figures/rcpp.png" style="vertical-align:middle" width="10%" height="10%"/>
- Find **optimal** solutions
- Solve a specific new problem using mathematical programming
- Ideally, fast 🙂 <br> <br>
:::
::: {style="float: left; width: 50%;"}
<center>![](Figures/Logo.png){.class width="80%" height="80%"}</center>
:::
## Overview
[**Three**]{style="color: #B93600;"} questions: **Planning objective**,
**Optimization objective**, and **Intensity of threats**.
<center>![](Figures/Diagram1.jpg){.class width="70%"
height="70%"}</center>
## Workflow
<center>![](Figures/Diagram2.png){.class width="80%"
height="80%"}</center>
## [**Q1.**]{style="color: #B93600;"} Planning objective?
#### Recovery vs Conservation
<center>![](Figures/PlanningObjectives1.png){.class width="60%"
height="60%"}</center>
## Workflow
<center>![](Figures/Diagram2.png){.class width="80%"
height="80%"}</center>
## [**Q2.**]{style="color: #B93600;"} Threat intensities?
#### Binary vs Continuous
<br>
<center>![Bolch, E.A. et al. (2020). Remote Detection of Invasive Alien
Species](Figures/invasive.webp){.class width="80%"
height="80%"}</center>
## [**Q2.**]{style="color: #B93600;"} Threat intensities?
#### Binary vs Continuous
<br>
<center>![Source:
https://ib.bioninja.com.au](Figures/threats.jpg){.class width="70%"
height="70%"}</center>
## Workflow
<center>![](Figures/Diagram2.png){.class width="80%"
height="80%"}</center>
# I) Input data validation
## Inputs (`inputData()`)
Data that defines the spatial prioritization problem (**planning units
data**, **feature data**, **threats data**, and their **spatial
distributions**).
<div>
<center>[**5**]{style=""}
<img src="Figures/table.png" style="vertical-align:middle" width="10%" height="10%"/>
[**+**]{style=""} [**2**]{style=""}
<img src="Figures/table_optional.png" style="vertical-align:middle" width="10%" height="10%"/>
[(optional)]{style=""}</center>
</div>
```{r input0_0, eval=FALSE, include=TRUE}
inputData(
pu,
features,
dist_features,
threats,
dist_threats,
sensitivity = NULL,
boundary = NULL
)
```
## Inputs
**What if I have my data in another format?**<br>
[**A:**]{style="color: red;"} There are functions that allow you to
import and convert data to `data.frame` format
Examples:
```{r inputs0_1, eval=FALSE, include=TRUE}
##from .txt to data.frame
df <- read.table('myfile.txt',sep='\t')
```
```{r inputs0_2, eval=FALSE, include=TRUE}
##from .csv to data.frame
df <- read.csv("myfile.csv")
```
<center>![Source:
https://libguides.umn.edu](Figures/data-frame.png){.class width="80%"
height="80%"}</center>
<br>
## #1 Planning units data (`pu`)
#### `data.frame`
<br> Specifies the **planning units (PU)** of the corresponding instance
and their corresponding **monitoring cost** and **status**. Each row
corresponds to a different planning unit. This file is inherited from
the *pu.dat* in Marxan. <br> <br>
::: {style="float: left; width: 50%;"}
- [**id**]{style="color: #4385CD;"}<br> `integer` unique identifier
for each planning unit.
- [**monitoring_cost**]{style="color: #4385CD;"}<br> `numeric` cost of
including each planning unit in the reserve system.
- [**status** (optional)]{style="color: #4385CD;"}<br> `integer` value
that indicate if each planning unit should be available to be
selected (`0`), locked-in (`2`) as part of the solution, or
locked-out (`3`) and excluded from the solution.
:::
::: {style="float: right; width: 40%;"}
```{r inputs1, eval=TRUE, include=TRUE}
## id monitoring_cost status
## 1 2 0
## 2 2 0
## 3 2 0
## 4 2 0
## 5 2 0
## 6 2 0
```
:::
## #1 Planning units data (`pu`)
### [**id**]{style="color: #4385CD;"}<br>
<br>
<center>![Game, E. T. y H. S. Grantham. (2008). Manual del Usuario de
Marxan: Para la versión Marxan 1.8.10](Figures/pu.png){.class
width="70%" height="70%"}</center>
## #1 Planning units data (`pu`)
### [**monitoring_cost**]{style="color: #4385CD;"}<br>
<center>![Source: https://marxansolutions.org](Figures/costs.png){.class
width="50%" height="50%"}</center>
## #1 Planning units data (`pu`)
### [**status** (optional)]{style="color: #4385CD;"}<br>
- free (`0`)
- locked-in (`2`)
- locked-out (`3`)
<center>![Source:
https://marxansolutions.org](Figures/status.png){.class width="40%"
height="40%"}</center>
## #2 Features data (`features`)
#### `data.frame`
<br> Specifies the **conservation features** to consider in the
optimization problem. Each row corresponds to a different feature. This
file is inherited from the *spec.dat* in Marxan. <br> <br>
::: {style="float: left; width: 50%;"}
- [**id**]{style="color: #4385CD;"}<br> `integer` unique identifier
for each conservation feature.
- [**target_recovery**]{style="color: #4385CD;"}<br> `numeric` amount
of recovery target to achieve for each conservation feature.
- [**target_conservation** (optional)]{style="color: #4385CD;"}<br>
`numeric` amount of conservation target to achieve for each
conservation feature.
- [**name** (optional)]{style="color: #4385CD;"}<br> `character` name
for each conservation feature.
:::
::: {style="float: right; width: 40%;"}
```{r inputs2, eval=TRUE, include=TRUE}
##id target_recovery name
## 1 11 feature1
## 2 16 feature2
## 3 8 feature3
## 4 9 feature4
```
:::
## #2 Features data (`features`)
### [**id**]{style="color: #4385CD;"} (Species) <br>
<center>![Source:
https://gefespeciesamenazadas.mma.gob.cl](Figures/species.jpg){.class
width="45%" height="45%"}</center>
## #2 Features data (`features`)
### [**id**]{style="color: #4385CD;"} (Ecosystem Services)<br>
<center>![Source:
https://ecology.fnal.gov](Figures/servicios.jpg){.class width="45%"
height="45%"}</center>
## #2 Features data (`features`)
### [**id**]{style="color: #4385CD;"} (Habitats) <br>
<br>
<center>![Source:
https://www.asemafor.cl/areas-protegidas-en-chile](Figures/habitats.jpg){.class
width="70%" height="70%"}</center>
## #2 Features data (`features`)
### [**recovery_target**]{style="color: #4385CD;"}<br>
<br>
<center>![](Figures/t.png){.class width="50%"
height="50%"}</center>
## #2 Features data (`features`)
### [**conservation_target (optional)**]{style="color: #4385CD;"}<br>
::: {style="float: left; width: 50%;"}
<br>
<center>![](Figures/target1.png){.class width="100%"
height="100%"}</center>
:::
::: {style="float: left; width: 50%;"}
<center>![](Figures/target2.png){.class width="100%"
height="100%"}</center>
:::
<center>Source: <https://marxansolutions.org></center>
## #3 Distribution Features data (`dist_features`)
#### `data.frame`
<br> Specifies the **spatial distribution of conservation features**
across planning units. Each row corresponds to a combination of
`planning unit` and `feature`. <br> <br>
::: {style="float: left; width: 50%;"}
- [**pu**]{style="color: #4385CD;"}<br> `integer` *id* of a planning
unit where the conservation feature listed on the same row occurs.
- [**feature**]{style="color: #4385CD;"}<br> `integer` *id* of each
conservation feature.
- [**amount**]{style="color: #4385CD;"}<br> `numeric` amount of the
feature in the planning unit. Set to `1` to work with
presence/absence.
:::
::: {style="float: right; width: 30%;"}
```{r inputs3, eval=TRUE, include=TRUE}
#pu feature amount
#1 3 1
#2 3 1
#3 3 1
#4 3 1
#5 3 1
#6 3 1
```
:::
## #3 Distribution Features data (`dist_features`)
### [**amount (binaries)**]{style="color: #4385CD;"}<br>
<center>![Source: https://calumma.typepad.com](Figures/sd1.png){.class
width="50%" height="50%"}</center>
## #3 Distribution Features data (`dist_features`)
### [**amount (continuous)**]{style="color: #4385CD;"}<br>
<center>![Source: https://ib.bioninja.com.au](Figures/sd2.jpeg){.class
width="70%" height="70%"}</center>
## #4 Threats data (`threats`)
#### `data.frame`
<br> Specifies the **threats** to consider in the optimization exercise.
Each row corresponds to a different `threats`. <br> <br>
::: {style="float: left; width: 50%;"}
- [**id**]{style="color: #4385CD;"}<br> `integer` unique identifier
for each threat.
- [**blm_actions** (optional)]{style="color: #4385CD;"}<br> `numeric`
penalty of connectivity between threats. Default is `0`.
- [**name** (optional)]{style="color: #4385CD;"}<br> `character`
\`name for each conservation feature.
:::
::: {style="float: right; width: 35%;"}
```{r inputs4, eval=TRUE, include=TRUE}
#>id name blm_actions
#> 1 threat1 0
#> 2 threat2 0
```
:::
## #4 Threats data (`threats`)
### [**blm_actions**]{style="color: #4385CD;"}
<center>![Source:
https://docs.marxanweb.org](Figures/connectivity2.png){.class
width="50%" height="50%"}</center>
## #5 Distribution Threats data (`dist_threats`)
#### `data.frame`
<br> specifies the **spatial distribution of threats** across planning
units. Each row corresponds to a combination of `planning unit` and
`threat`. <br> <br>
::: {style="float: left; width: 60%;"}
- [**pu**]{style="color: #4385CD;"}<br> `integer` *id* of a planning
unit where the threat listed on the same row occurs.
- [**threat**]{style="color: #4385CD;"}<br> `integer` *id* of each
conservation feature.
- [**amount**]{style="color: #4385CD;"}<br> `numeric` amount of the
threat in the planning unit. Set to `1` to work with
presence/absence. Continuous amount values require that feature
`sensitivities` to threats be established.
:::
::: {style="float: right; width: 30%;"}
```{r inputs5, eval=TRUE, include=TRUE}
#>pu threat amount action_cost status
#> 8 2 1 2 0
#> 9 2 1 2 0
#>10 2 1 2 0
#>11 1 1 3 0
#>11 2 1 4 0
#>12 1 1 3 0
```
:::
## #5 Distribution Threats data (`dist_threats`)
#### `data.frame`
<br> specifies the **spatial distribution of threats** across planning
units. Each row corresponds to a combination of `planning unit` and
`threat`. <br> <br>
- [**action_cost**]{style="color: #4385CD;"}<br> `numeric` cost of an
action to abate the threat in each planning unit.
- [**status** (optional)]{style="color: #4385CD;"}<br> `integer` value
that indicate if each planning unit should be available to be
selected (`0`), locked-in (`2`) as part of the solution, or
locked-out (`3`) and excluded from the solution. :::
## #5 Distribution Threats data (`dist_threats`)
### [**amount (continuous)**]{style="color: #4385CD;"}<br>
<center>![Source:
https://ib.bioninja.com.au](Figures/threats.jpg){.class width="70%"
height="70%"}</center>
## #6 Sensitivity data (`sensitivity`)
### Optional
#### `data.frame`
<br> specifies the **sensitivity** of each `feature` to each `threat`.
Each row corresponds to a combination of `feature` and `threat`. <br>
<br>
::: {style="float: left; width: 70%;"}
- [**feature**]{style="color: #4385CD;"}<br> `integer` *id* of each
conservation feature.
- [**threat**]{style="color: #4385CD;"}<br> `integer` *id* of each
threat.
- [**a** (optional)]{style="color: #4385CD;"}<br> `numeric` the
minimum intensity of the threat at which the features probability of
persistence starts to decline.
- [**b** (optional)]{style="color: #4385CD;"}<br> `numeric` the value
of intensity of the threat over which the feature has a probability
of persistence of `0`.
:::
::: {style="float: right; width: 30%;"}
```{r inputs7, eval=TRUE, include=TRUE}
#>feature threat
#> 1 1
#> 2 1
#> 3 1
#> 4 1
#> 1 2
#> 2 2
```
:::
## #6 Sensitivity data (`sensitivity`)
### Optional
#### `data.frame`
<br> specifies the **sensitivity** of each `feature` to each `threat`.
Each row corresponds to a combination of `feature` and `threat`. <br>
<br>
- [**c** (optional)]{style="color: #4385CD;"}<br> `numeric` minimum
probability of persistence of a features when a threat reaches its
maximum intensity value.
- [**d** (optional)]{style="color: #4385CD;"}<br> `numeric` maximum
probability of persistence of a features in absence threats. :::
## #6 Sensitivity data (`sensitivity`)
### [**a, b, c and d**]{style="color: #4385CD;"}<br>
<center>![](Figures/sensitivity1.png){.class width="70%"
height="70%"}</center>
## #6 Sensitivity data (`sensitivity`)
### [**a, b, c and d**]{style="color: #4385CD;"}<br>
<center>![](Figures/sensitivities2.jpg){.class width="60%"
height="60%"}</center>
## #7 Boundary data (`boundary`)
### Optional
#### `data.frame`
<br> Specifies the **spatial relationship** between pair of
`planning units`. Each row corresponds to a combination of
`planning unit`. <br> <br>
::: {style="float: left; width: 60%;"}
- [**id1**]{style="color: #4385CD;"}<br> `integer` *id* of each
planning unit.
- [**id2**]{style="color: #4385CD;"}<br> `integer` *id* of each
planning unit.
- [**boundary**]{style="color: #4385CD;"}<br> `numeric` penalty
applied in the objective function when only one of the planning
units is present in the solution.
:::
::: {style="float: right; width: 30%;"}
```{r inputs8, eval=TRUE, include=TRUE}
#>id1 id2 boundary
#> 1 1 0
#> 2 1 1
#> 3 1 2
#> 4 1 3
#> 5 1 4
#> 6 1 5
```
:::
## Workflow
<center>![](Figures/Diagram2.png){.class width="80%"
height="80%"}</center>
## [**Q3.**]{style="color: #B93600;"} Optimization objective?
#### Minimize Costs (**`minimizeCosts`**) vs Maximize Benefits (**`maximizeBenefits`**)
<br>
<center>![](Figures/mincost.png){.class width="80%"
height="80%"}</center>
$x_{ik}$ is the decisions variable that specifies whether an action to
abate threat $k$ in planning unit $i$ has been selected $(1)$ or not
$(0)$.
$c_{ik}$ is the cost of the action to abate the threat $k$ in the
planning unit $i$.
$b_{is}(x)$ is the benefit of the feature $s$ in the planning unit $i$
(ranging between $0$ and $1$).
$t_s$ is the recovery target for feature $s$.
$f(x)$ is the function of connectivity penalty.
## [**Q3.**]{style="color: #B93600;"} Optimization objective?
#### Minimize Costs (**`minimizeCosts`**) vs Maximize Benefits (**`maximizeBenefits`**)
<br>
<center>![](Figures/maxben.png){.class width="80%"
height="80%"}</center>
$x_{ik}$ is the decisions variable that specifies whether an action to
abate threat $k$ in planning unit $i$ has been selected $(1)$ or not
$(0)$.
$c_{ik}$ is the cost of the action to abate the threat $k$ in the
planning unit $i$.
$b_{is}(x)$ is the benefit of the feature $s$ in the planning unit $i$
(ranging between $0$ and $1$).
$B$ is the budget available.
$f(x)$ is the function of connectivity penalty.
## Workflow
<center>![](Figures/Diagram2.png){.class width="80%"
height="80%"}</center>
# II) Create mathematical model
## Create the model (`problem()`)
Create an **optimization model** for the multi-action conservation
planning problem, following the mathematical formulations used in
Salgado-Rojas et al. (2020).
<br>
```{r model1, eval=FALSE, include=TRUE}
problem(
x,
model_type = "minimizeCosts",
budget = 0,
blm = 0
)
```
## Workflow
<center>![](Figures/Diagram2.png){.class width="80%"
height="80%"}</center>
# III) Solve model
## Solve model (`solve()`)
Solves the **optimization model** associated with the multi-action
conservation planning problem. This function is used to solve the
mathematical model created by the `problem()` function.
<br>
```{r solve1, eval=FALSE, include=TRUE}
solve(
a,
solver = "",
gap_limit = 0,
time_limit = .Machine$integer.max,
solution_limit = FALSE,
cores = 2,
verbose = TRUE,
name_output_file = "output",
output_file = TRUE
)
```
## Solve model (`solve()`)
### [**solver**]{style="color: #4385CD;"} (`gurobi, cplex, symphony`)<br>
<br>
<div>
<center>
**Rsymphony** <br>
<center>
<img src="Figures/cplex-gurobi.webp" style="vertical-align:middle" width="50%" height="50%"/>
</div>
## Solve model (`solve()`)
### [**gap limit**]{style="color: #4385CD;"} (percentage) <br>
<center>![Source: https://www.math.uwaterloo.ca](Figures/gap.jpg){.class
width="60%" height="60%"}</center>
## Solve model (`solve()`)
### [**time limit**]{style="color: #4385CD;"} (seconds) <br>
### [**solution_limit**]{style="color: #4385CD;"} (First solution?) <br>
### [**verbose**]{style="color: #4385CD;"} (Information on screen?) <br>
## Overview
<center>![](Figures/Diagram2.png){.class width="80%"
height="80%"}</center>
# Getting information of solutions
## `getActions()`
Returns the spatial deployment of the **actions for each planning unit**
of the corresponding solution.
<br>
```{r info1, eval=FALSE, include=TRUE}
getActions(x, format = "wide")
```
Output example,
```{r info2, eval=FALSE, include=TRUE}
## solution_name pu 1 2 conservation connectivity
## 1 sol 1 0 0 0 0
## 2 sol 2 0 0 0 0
## 3 sol 3 0 0 0 0
## 4 sol 4 0 0 0 0
## 5 sol 5 0 0 0 0
## 6 sol 6 0 0 0 0
```
## `getSolutionBenefit()`
Returns the **total benefit** induced by the corresponding solution. The
total benefit is computed as the sum of the benefits obtained, for all
features, across all the units in the planning area.
<br>
```{r info3, eval=FALSE, include=TRUE}
getSolutionBenefit(x, type = "total")
```
Output example,
```{r info4, eval=FALSE, include=TRUE}
## solution_name feature benefit.conservation benefit.recovery benefit.total
## 1 sol 1 0 11 11
## 2 sol 2 0 16 16
## 3 sol 3 0 10 10
## 4 sol 4 0 9 9
```
## `getCost()`
Provides the sum of **costs** to actions and monitoring applied in a
solution.
<br>
```{r info5, eval=FALSE, include=TRUE}
getCost(x)
```
Output example,
```{r info6, eval=FALSE, include=TRUE}
## solution_name monitoring threat_1 threat_2
## 1 sol 61 20 65
```
# Outline
- Features
- ::: white
**Toy example**
:::
- Overview
- Actual case study: The Mitchell River, Australia
- Shiny Application
## Package installation and documentation
<!-- badges: start -->
![CRAN/METACRAN](https://www.r-pkg.org/badges/version/prioriactions)
[![Lifecycle:
stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![R-CMD-check](https://github.com/prioriactions/prioriactions/workflows/R-CMD-check/badge.svg)](https://github.com/prioriactions/prioriactions/actions)
[![](https://cranlogs.r-pkg.org/badges/grand-total/prioriactions)](https://cran.rstudio.com/web/packages/prioriactions/index.html)
<!-- badges: end -->
Package `prioriactions` can be found at
[CRAN](https://cloud.r-project.org/web/packages/prioriactions/index.html),
so it can be installed using:
```{r toyExample1, eval=FALSE, include=TRUE}
install.packages("prioriactions")
```
Latest stable versions can be downloaded and installed from GitHub as
follows (package `remotes` should be installed first):
```{r toyExample2, eval=FALSE, include=TRUE}
if (!require(remotes)) install.packages("remotes")
remotes::install_github("prioriactions/prioriactions")
```
So, we load the `prioriactions` package.
```{r toyExample3, eval=TRUE, include=TRUE}
# load package
library(prioriactions)
```
## Toy Example
##### (Available in the [Get Started](https://prioriactions.github.io/prioriactions/articles/prioriactions.html) vignette on the `prioriactions` website)
<br />
- This example contains **100 planning units**, **4 features** and **2
threats**.
- The distribution of features and threats can be plotted on a grid of
10 x 10 units.
- `prioriactions` contains this simulated example inside the setup
files. You can extract it by the `data()` function.
## #1 Planning units data
The monitoring cost values ranging from 1 to 10 and all status of 0 (not
locked).
```{r toyExample4, eval=TRUE, message=FALSE, include=TRUE}
# load planning unit data from prioriactions
data(sim_pu_data) #To load simulated data
#head(sim_pu_data)
```
```{r toyExample5, echo=FALSE, message=FALSE}
library(DT)
datatable(sim_pu_data, rownames = FALSE, options = list(pageLength = 5))
```
## #1 Planning units data
A `RasterLayer` object can be used to present this spatial information.
The pixel values correspond to the **monitoring costs** of each planning
unit.
```{r toyExample6, eval=TRUE, message=FALSE, include=TRUE, out.width="60%"}
library(raster) #To plot rasters
r <- raster(ncol=10, nrow=10, xmn=0, xmx=10, ymn=0, ymx=10)
values(r) <- sim_pu_data$monitoring_cost
plot(r)
```
## #2 Features data
Contains information about the **features** such as its *id* and
*targets* (mandatory when `minimizing costs`).
```{r toyExample7, eval=TRUE, message=FALSE, include=TRUE}
# load features data from prioriactions
data(sim_features_data)
#head(sim_features_data)
```
```{r toyExample8, echo=FALSE, message=FALSE}
datatable(sim_features_data, rownames = FALSE, options = list(pageLength = 5))
```
## #3 Features distribution data
Contains information on the **spatial distribution of these features**
across planning units.
```{r toyExample9, eval=TRUE, message=FALSE, include=TRUE}
# load features data from prioriactions
data(sim_dist_features_data)
#head(sim_features_data)
```
```{r toyExample10, echo=FALSE, message=FALSE}
datatable(sim_dist_features_data, rownames = FALSE, options = list(pageLength = 5))
```
## #3 Features distribution data
To plot the spatial distribution of the first feature,
```{r toyExample10_1, eval=TRUE, message=FALSE, include=TRUE}
# load amount of features data
features <- reshape2::dcast(sim_dist_features_data,
pu~feature,
value.var = "amount",
fill = 0)
values(r) <- features$`1`
plot(r)
```
## #3 Features distribution data
<center>![](Figures/toyexample_1.png){.class width="80%"
height="80%"}</center>
## #4 Threats data
Provides information about the threats such as their `id` and `name`.
```{r toyExample11, eval=TRUE, message=FALSE, include=TRUE}
# load threats data from prioriactions
data(sim_threats_data)
```
```{r toyExample12, echo=FALSE, message=FALSE}
datatable(sim_threats_data, rownames = FALSE, options = list(pageLength = 5))
```
## #5 Threats distribution data
Provides information on the **spatial distribution** of these threats
```{r toyExample13, eval=TRUE, message=FALSE, include=TRUE}
# load threats data from prioriactions
data(sim_dist_threats_data)
```
```{r toyExample14, echo=FALSE, message=FALSE}
datatable(sim_dist_threats_data, rownames = FALSE, options = list(pageLength = 5))
```
## #5 Threats distribution data
<center>![](Figures/toyexample_2.png){.class width="80%"
height="80%"}</center>
## #6 Sensitivity data
Indicates which features is sensitive to what threat.
```{r toyExample15, eval=TRUE, message=FALSE, include=TRUE}
# load threats data from prioriactions
data(sim_sensitivity_data)