/
raptr.html
1502 lines (1438 loc) · 148 KB
/
raptr.html
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
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>raptr: Representative and Adequate Prioritization Toolkit in R • raptr</title>
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script><!-- Bootstrap --><link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.4.0/sandstone/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css">
<script src="../bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="raptr: Representative and Adequate Prioritization Toolkit in R">
<meta property="og:description" content="raptr">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body data-spy="scroll" data-target="#toc">
<div class="container template-article">
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">raptr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.7.3</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="../articles/raptr.html">Get started</a>
</li>
<li>
<a href="../reference/index.html">Reference</a>
</li>
<li>
<a href="../news/index.html">Changelog</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/jeffreyhanson/raptr/" class="external-link">
<span class="fab fa-github fa-lg"></span>
</a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container -->
</div>
<!--/.navbar -->
</header><script src="raptr_files/header-attrs-2.11/header-attrs.js"></script><div class="row">
<div class="col-md-9 contents">
<div class="page-header toc-ignore">
<h1 data-toc-skip>raptr: Representative and Adequate Prioritization Toolkit in R</h1>
<small class="dont-index">Source: <a href="https://github.com/jeffreyhanson/raptr/blob/master/vignettes/raptr.Rmd" class="external-link"><code>vignettes/raptr.Rmd</code></a></small>
<div class="hidden name"><code>raptr.Rmd</code></div>
</div>
<div id="overview" class="section level1">
<h1 class="hasAnchor">
<a href="#overview" class="anchor" aria-hidden="true"></a>Overview</h1>
<p>This vignette illustrates the basic usage of the <em>raptr R</em> package.</p>
<p>To load the <em>raptr R</em> package and learn more about the package, type the following code into R.</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># load raptr R package</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://jeffrey-hanson.com/raptr">raptr</a></span><span class="op">)</span>
<span class="co"># show package overview</span>
<span class="op">?</span><span class="va">raptr</span></code></pre></div>
<p>The <em>raptr R</em> package uses a range of S4 classes to store conservation planning data, parameters, and prioritizations (Table 1).</p>
<p>Table 1: Main classes in the <em>raptr R</em> package</p>
<table class="table">
<colgroup>
<col width="19%">
<col width="80%">
</colgroup>
<thead><tr class="header">
<th align="center"><strong>Class</strong></th>
<th align="left"><strong>Description</strong></th>
</tr></thead>
<tbody>
<tr class="odd">
<td align="center"><code>ManualOpts</code></td>
<td align="left">place-holder class for manually specified solutions</td>
</tr>
<tr class="even">
<td align="center"><code>GurobiOpts</code></td>
<td align="left">stores parameters for solving optimization problems using <em>Gurobi</em>
</td>
</tr>
<tr class="odd">
<td align="center"><code>RapUnreliableOpts</code></td>
<td align="left">stores control variables parameters for the unreliable problem formulation</td>
</tr>
<tr class="even">
<td align="center"><code>RapReliableOpts</code></td>
<td align="left">stores control variables for the reliable problem formulation</td>
</tr>
<tr class="odd">
<td align="center"><code>DemandPoints</code></td>
<td align="left">stores the coordinates and weights for a given species and attribute space</td>
</tr>
<tr class="even">
<td align="center"><code>PlanningUnitPoints</code></td>
<td align="left">stores the coordinates and ids for planning units that can be used to preserve a given species</td>
</tr>
<tr class="odd">
<td align="center"><code>AttributeSpace</code></td>
<td align="left">stores the coordinates for planning units and the demand points for each species</td>
</tr>
<tr class="even">
<td align="center"><code>RapData</code></td>
<td align="left">stores the all the planning unit, species, and attribute space data</td>
</tr>
<tr class="odd">
<td align="center"><code>RapUnsolved</code></td>
<td align="left">stores all the data, control variables, and parameters needed to generate prioritizations</td>
</tr>
<tr class="even">
<td align="center"><code>RapResults</code></td>
<td align="left">stores the prioritizations and summary statistics generated after solving a problem</td>
</tr>
<tr class="odd">
<td align="center"><code>RapSolved</code></td>
<td align="left">stores the input data and output results</td>
</tr>
</tbody>
</table>
</div>
<div id="getting-started" class="section level1">
<h1 class="hasAnchor">
<a href="#getting-started" class="anchor" aria-hidden="true"></a>Getting started</h1>
<p>This tutorial is designed to provide users with an understanding of how to use the <em>raptr R</em> package to generate and compare solutions. This tutorial uses several additional packages, so first we will run the following code to load them.</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># load packages for tutorial</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va">parallel</span><span class="op">)</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="http://had.co.nz/plyr" class="external-link">plyr</a></span><span class="op">)</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://ggplot2.tidyverse.org" class="external-link">ggplot2</a></span><span class="op">)</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://www.wim.uni-mannheim.de/schlather/publications/software" class="external-link">RandomFields</a></span><span class="op">)</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://r-forge.r-project.org/projects/rgeos/" class="external-link">rgeos</a></span><span class="op">)</span>
<span class="co"># set seed for reproducibility</span>
<span class="fu"><a href="https://rdrr.io/r/base/Random.html" class="external-link">set.seed</a></span><span class="op">(</span><span class="fl">500</span><span class="op">)</span>
<span class="co"># set number of threads for computation</span>
<span class="va">threads</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/integer.html" class="external-link">as.integer</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/pkg/RandomFields/man/QMath.html" class="external-link">max</a></span><span class="op">(</span><span class="fl">1</span>, <span class="fu"><a href="https://rdrr.io/r/parallel/detectCores.html" class="external-link">detectCores</a></span><span class="op">(</span><span class="op">)</span> <span class="op">-</span> <span class="fl">2</span><span class="op">)</span><span class="op">)</span></code></pre></div>
<p>Now we will check if the the Gurobi software suite and the <em>gurobi R</em> package are installed. To do this, run the following code.</p>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="../reference/is.GurobiInstalled.html">is.GurobiInstalled</a></span><span class="op">(</span>verbose <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></code></pre></div>
<pre><code>## [1] TRUE</code></pre>
</div>
<div id="simulated-examples" class="section level1">
<h1 class="hasAnchor">
<a href="#simulated-examples" class="anchor" aria-hidden="true"></a>Simulated examples</h1>
<div id="data" class="section level2">
<h2 class="hasAnchor">
<a href="#data" class="anchor" aria-hidden="true"></a>Data</h2>
<p>To investigate the behavior of the problem, we will generate prioritizations for three simulated species. We will use the unreliable formulation of the problem to understand the basics, and later move onto the reliable formulation. The first species (termed ‘uniform’) will represent a hyper-generalist. This species will inhabit all areas with equal probability. The second species (termed ‘normal’) will represent a species with a single range core. The third species (termed ‘bimodal’) will represent a species with two distinct ecotypes, each with their own range core. To reduce computational time for this example, we will use a 10 <span class="math inline">\(\times\)</span> 10 grid of square planning units.</p>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># make planning units</span>
<span class="va">sim_pus</span> <span class="op"><-</span> <span class="fu"><a href="../reference/sim.pus.html">sim.pus</a></span><span class="op">(</span><span class="fl">100L</span><span class="op">)</span>
<span class="co"># simulate species distributions</span>
<span class="va">sim_spp</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html" class="external-link">lapply</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/pkg/RandomFields/man/QMath.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"uniform"</span>, <span class="st">"normal"</span>, <span class="st">"bimodal"</span><span class="op">)</span>, <span class="va">sim.species</span>, n <span class="op">=</span> <span class="fl">1</span>,
x <span class="op">=</span> <span class="va">sim_pus</span>, res <span class="op">=</span> <span class="fl">1</span><span class="op">)</span></code></pre></div>
<p>Let’s see what these species’ distributions look like.</p>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># plot species</span>
<span class="fu"><a href="../reference/plot.html">plot</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/pkg/raster/man/stack.html" class="external-link">stack</a></span><span class="op">(</span><span class="va">sim_spp</span><span class="op">)</span>,
main <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/pkg/RandomFields/man/QMath.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"Uniform species"</span>, <span class="st">"Normal species"</span>, <span class="st">"Bimodal species"</span><span class="op">)</span>,
addfun <span class="op">=</span> <span class="kw">function</span><span class="op">(</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/graphics/lines.html" class="external-link">lines</a></span><span class="op">(</span><span class="va">sim_pus</span><span class="op">)</span>, nc <span class="op">=</span> <span class="fl">3</span><span class="op">)</span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="raptr_files/figure-html/unnamed-chunk-7-1.png" alt="_Distribution of three simulated species. Each square represents a planning unit. The color of each square denotes the probability that individuals from each species occupy it._" width="672"><p class="caption">
<em>Distribution of three simulated species. Each square represents a planning unit. The color of each square denotes the probability that individuals from each species occupy it.</em>
</p>
</div>
<p>Next, we will generate a set of demand points. To understand the effects of probabilities and weights on the demand points, we will generate the demand points in geographic space. These demand points will be the centroids of the planning units. Additionally, we will use the same set of demand points for each species and only vary the weights of the demand points between species. <strong>Note that we are only using the same distribution of demand points for different species for teaching purposes. It is strongly recommended to use different demand points for different species in real-world conservation planning exercises.</strong> See the case-study section of this tutorial for examples on how to generate suitable demand points.</p>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># generate coordinates for pus/demand points</span>
<span class="va">pu_coords</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/pkg/rgeos/man/topo-unary-gCentroid.html" class="external-link">gCentroid</a></span><span class="op">(</span><span class="va">sim_pus</span>, byid <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span>
<span class="co"># calculate weights</span>
<span class="va">sim_dps</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html" class="external-link">lapply</a></span><span class="op">(</span><span class="va">sim_spp</span>, <span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/pkg/raster/man/extract.html" class="external-link">extract</a></span><span class="op">(</span><span class="va">x</span>, <span class="va">pu_coords</span><span class="op">)</span><span class="op">)</span>
<span class="co"># create demand point objects</span>
<span class="va">sim_dps</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/lapply.html" class="external-link">lapply</a></span><span class="op">(</span><span class="va">sim_dps</span>, <span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="../reference/DemandPoints.html">DemandPoints</a></span><span class="op">(</span><span class="va">pu_coords</span><span class="op">@</span><span class="va">coords</span>,
weights <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/pkg/RandomFields/man/QMath.html" class="external-link">c</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span><span class="op">)</span><span class="op">)</span></code></pre></div>
<p>Now, we will construct a <code>RapUnsolved</code> object to store our input data and parameters. This contains all the information to generate prioritizations.</p>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">## create RapUnreliableOpts object</span>
<span class="co"># this stores parameters for the unreliable formulation problem (ie. BLM)</span>
<span class="va">sim_ro</span> <span class="op"><-</span> <span class="fu"><a href="../reference/RapUnreliableOpts.html">RapUnreliableOpts</a></span><span class="op">(</span><span class="op">)</span>
<span class="co">## create RapData object</span>
<span class="co"># create data.frame with species info</span>
<span class="va">species</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span>name <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/pkg/RandomFields/man/QMath.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"uniform"</span>, <span class="st">"normal"</span>, <span class="st">"bimodal"</span><span class="op">)</span><span class="op">)</span>
<span class="co">## create data.frame with species and space targets</span>
<span class="co"># amount targets at 20% (denoted with target=0)</span>
<span class="co"># space targets at 20% (denoted with target=1)</span>
<span class="va">targets</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/expand.grid.html" class="external-link">expand.grid</a></span><span class="op">(</span>species <span class="op">=</span> <span class="fl">1</span><span class="op">:</span><span class="fl">3</span>, target <span class="op">=</span> <span class="fl">0</span><span class="op">:</span><span class="fl">1</span>, proportion <span class="op">=</span> <span class="fl">0.2</span><span class="op">)</span>
<span class="co"># calculate probability of each species in each pu</span>
<span class="va">pu_probabilities</span> <span class="op"><-</span> <span class="fu"><a href="../reference/calcSpeciesAverageInPus.html">calcSpeciesAverageInPus</a></span><span class="op">(</span><span class="va">sim_pus</span>, <span class="fu"><a href="https://rdrr.io/pkg/raster/man/stack.html" class="external-link">stack</a></span><span class="op">(</span><span class="va">sim_spp</span><span class="op">)</span><span class="op">)</span>
<span class="co">## create AttributeSpace object</span>
<span class="co"># this stores the coordinates of the planning units in an attribute space</span>
<span class="co"># and the coordinates and weights of demand points in the space</span>
<span class="va">pu_points</span> <span class="op"><-</span> <span class="fu"><a href="../reference/PlanningUnitPoints.html">PlanningUnitPoints</a></span><span class="op">(</span>coords <span class="op">=</span> <span class="va">pu_coords</span><span class="op">@</span><span class="va">coords</span>,
ids <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/seq.html" class="external-link">seq_len</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/pkg/raster/man/ncell.html" class="external-link">nrow</a></span><span class="op">(</span><span class="va">sim_pus</span><span class="op">@</span><span class="va">data</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>
<span class="va">attr_spaces</span> <span class="op"><-</span> <span class="fu"><a href="../reference/AttributeSpaces.html">AttributeSpaces</a></span><span class="op">(</span>
<span class="fu"><a href="https://rdrr.io/r/base/list.html" class="external-link">list</a></span><span class="op">(</span><span class="fu"><a href="../reference/AttributeSpace.html">AttributeSpace</a></span><span class="op">(</span>planning.unit.points <span class="op">=</span> <span class="va">pu_points</span>,
demand.points <span class="op">=</span> <span class="va">sim_dps</span><span class="op">[[</span><span class="fl">1</span><span class="op">]</span><span class="op">]</span>,
species <span class="op">=</span> <span class="fl">1L</span><span class="op">)</span>,
<span class="fu"><a href="../reference/AttributeSpace.html">AttributeSpace</a></span><span class="op">(</span>planning.unit.points <span class="op">=</span> <span class="va">pu_points</span>,
demand.points <span class="op">=</span> <span class="va">sim_dps</span><span class="op">[[</span><span class="fl">2</span><span class="op">]</span><span class="op">]</span>,
species <span class="op">=</span> <span class="fl">2L</span><span class="op">)</span>,
<span class="fu"><a href="../reference/AttributeSpace.html">AttributeSpace</a></span><span class="op">(</span>planning.unit.points <span class="op">=</span> <span class="va">pu_points</span>,
demand.points <span class="op">=</span> <span class="va">sim_dps</span><span class="op">[[</span><span class="fl">3</span><span class="op">]</span><span class="op">]</span>,
species <span class="op">=</span> <span class="fl">3L</span><span class="op">)</span><span class="op">)</span>,
name <span class="op">=</span> <span class="st">"geographic"</span><span class="op">)</span>
<span class="co"># generate boundary data information</span>
<span class="va">boundary</span> <span class="op"><-</span> <span class="fu"><a href="../reference/calcBoundaryData.html">calcBoundaryData</a></span><span class="op">(</span><span class="va">sim_pus</span><span class="op">)</span>
<span class="co">## create RapData object</span>
<span class="co"># this stores all the input data for the prioritization</span>
<span class="va">sim_rd</span> <span class="op"><-</span> <span class="fu"><a href="../reference/RapData.html">RapData</a></span><span class="op">(</span><span class="va">sim_pus</span><span class="op">@</span><span class="va">data</span>, <span class="va">species</span>, <span class="va">targets</span>, <span class="va">pu_probabilities</span>,
<span class="fu"><a href="https://rdrr.io/r/base/list.html" class="external-link">list</a></span><span class="op">(</span><span class="va">attr_spaces</span><span class="op">)</span>, <span class="va">boundary</span>, <span class="fu"><a href="../reference/SpatialPolygons2PolySet.html">SpatialPolygons2PolySet</a></span><span class="op">(</span><span class="va">sim_pus</span><span class="op">)</span><span class="op">)</span>
<span class="co">## create RapUnsolved object</span>
<span class="co"># this stores all the input data and parameters needed to generate</span>
<span class="co"># prioritizations</span>
<span class="va">sim_ru</span> <span class="op"><-</span> <span class="fu"><a href="../reference/RapUnsolved.html">RapUnsolved</a></span><span class="op">(</span><span class="va">sim_ro</span>, <span class="va">sim_rd</span><span class="op">)</span></code></pre></div>
</div>
<div id="single-species-prioritizations" class="section level2">
<h2 class="hasAnchor">
<a href="#single-species-prioritizations" class="anchor" aria-hidden="true"></a>Single-species prioritizations</h2>
<div id="amount-based-targets" class="section level3">
<h3 class="hasAnchor">
<a href="#amount-based-targets" class="anchor" aria-hidden="true"></a>Amount-based targets</h3>
<p>To investigate the effects of space-based targets, we will generate a prioritization for each species using only amount-based targets and compare them to prioritizations generated using amount- and space-based targets. To start off, we will generate a prioritization for the uniform species using amount-based targets. To do this, we will generate a new <code>sim_ru</code> object by extracting out the data for the uniform species from the <code>sim_ru</code> object. Then, we will update the targets in the new object. Finally, we will solve the object to generate a prioritization that fulfills the targets for minimal cost.</p>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># create new object with just the uniform species</span>
<span class="va">sim_ru_s1</span> <span class="op"><-</span> <span class="fu"><a href="../reference/spp.subset.html">spp.subset</a></span><span class="op">(</span><span class="va">sim_ru</span>, <span class="st">"uniform"</span><span class="op">)</span>
<span class="co"># update amount targets to 20% and space targets to 0%</span>
<span class="va">sim_ru_s1</span> <span class="op"><-</span> <span class="fu"><a href="../reference/update.html">update</a></span><span class="op">(</span><span class="va">sim_ru_s1</span>, amount.target <span class="op">=</span> <span class="fl">0.2</span>, space.target <span class="op">=</span> <span class="cn">NA</span>,
solve <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></code></pre></div>
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/base/options.html" class="external-link">options</a></span><span class="op">(</span>error <span class="op">=</span> <span class="kw">function</span><span class="op">(</span><span class="op">)</span> <span class="op">{</span>
<span class="fu"><a href="https://rdrr.io/r/base/traceback.html" class="external-link">traceback</a></span><span class="op">(</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/quit.html" class="external-link">q</a></span><span class="op">(</span><span class="st">"no"</span>, <span class="fl">1</span>, <span class="cn">FALSE</span><span class="op">)</span>
<span class="op">}</span><span class="op">)</span>
<span class="co"># solve problem to identify prioritization</span>
<span class="va">sim_rs_s1_amount</span> <span class="op"><-</span> <span class="fu"><a href="../reference/solve.html">solve</a></span><span class="op">(</span><span class="va">sim_ru_s1</span>, Threads <span class="op">=</span> <span class="va">threads</span><span class="op">)</span></code></pre></div>
<pre><code>## Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (linux64)
## Thread count: 4 physical cores, 8 logical processors, using up to 6 threads
## Optimize a model with 1 rows, 100 columns and 100 nonzeros
## Model fingerprint: 0xe910d3ec
## Variable types: 0 continuous, 100 integer (100 binary)
## Coefficient statistics:
## Matrix range [5e-01, 5e-01]
## Objective range [1e+00, 1e+00]
## Bounds range [1e+00, 1e+00]
## RHS range [1e+01, 1e+01]
## Found heuristic solution: objective 20.0000000
## Presolve removed 1 rows and 100 columns
## Presolve time: 0.00s
## Presolve: All rows and columns removed
##
## Explored 0 nodes (0 simplex iterations) in 0.00 seconds
## Thread count was 1 (of 8 available processors)
##
## Solution count 1: 20
##
## Optimal solution found (tolerance 1.00e-01)
## Best objective 2.000000000000e+01, best bound 2.000000000000e+01, gap 0.0000%</code></pre>
<pre><code>## Warning in validityMethod(object): some species have space.held values less than
## 0, and thus are poorly represented</code></pre>
<div class="sourceCode" id="cb13"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">## show summary</span>
<span class="co"># note the format for this is similar to that used by Marxan</span>
<span class="co"># see ?raptr::summary for details on this table</span>
<span class="fu"><a href="../reference/summary.html">summary</a></span><span class="op">(</span><span class="va">sim_rs_s1_amount</span><span class="op">)</span></code></pre></div>
<pre><code>## Run_Number Status Score Cost Planning_Units Connectivity_Total
## 1 1 OPTIMAL 20 20 20 220
## Connectivity_In Connectivity_Edge Connectivity_Out Connectivity_In_Fraction
## 1 42 168 10 0.1909091</code></pre>
<div class="sourceCode" id="cb15"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show amount held</span>
<span class="fu"><a href="../reference/amount.held.html">amount.held</a></span><span class="op">(</span><span class="va">sim_rs_s1_amount</span><span class="op">)</span></code></pre></div>
<pre><code>## uniform
## 1 0.2</code></pre>
<div class="sourceCode" id="cb17"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show space held</span>
<span class="fu"><a href="../reference/space.held.html">space.held</a></span><span class="op">(</span><span class="va">sim_rs_s1_amount</span><span class="op">)</span></code></pre></div>
<pre><code>## uniform (Space 1)
## 1 -0.2363636</code></pre>
<p>Now that we have generated a prioritization, let’s see what it looks like. We can use the <code>spp.plot</code> method to see how the prioritization overlaps with the uniform species’ distribution. Note that since all planning units have equal probabilities for this species, all planning units have the same fill color.</p>
<div class="sourceCode" id="cb19"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># plot the prioritization and the uniform species' distribution</span>
<span class="fu"><a href="../reference/spp.plot.html">spp.plot</a></span><span class="op">(</span><span class="va">sim_rs_s1_amount</span>, <span class="fl">1</span>, main <span class="op">=</span> <span class="st">"Uniform species"</span><span class="op">)</span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="raptr_files/figure-html/unnamed-chunk-13-1.png" alt="_A prioritization for the uniformly distributed species generated using amount-based targets (20\%). Sqaures represent planning units. Planning units with a green border are selected for prioritization, and their colour denotes the probability they are inhabited by the species._" width="432"><p class="caption">
<em>A prioritization for the uniformly distributed species generated using amount-based targets (20%). Sqaures represent planning units. Planning units with a green border are selected for prioritization, and their colour denotes the probability they are inhabited by the species.</em>
</p>
</div>
<p>The prioritization for the uniform species appears to be just a random selection of planning units. This behavior is due to the fact that any prioritization with 20 planning units is optimal. By relying on just amount targets, this solution may preserve a section of the species’ range core, or just focus on the range margin, or some random part of its range–no emphasis is directed towards preserving different parts of the species’ range. This behavior highlights a fundamental limitation of just using amount-based targets. In the absence of additional criteria, conventional reserve selection problems do not contain any additional information to identify the most effective prioritization.</p>
<p>Now, we will generate a prioritization for the normally distributed species using amount-based targets. We will use a similar process to what we used for the uniformly distributed species, but for brevity, we will use code to generate solutions immediately after updating the object.</p>
<div class="sourceCode" id="cb20"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># create new object with just the normal species</span>
<span class="va">sim_ru_s2</span> <span class="op"><-</span> <span class="fu"><a href="../reference/spp.subset.html">spp.subset</a></span><span class="op">(</span><span class="va">sim_ru</span>, <span class="st">"normal"</span><span class="op">)</span></code></pre></div>
<div class="sourceCode" id="cb21"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># update amount targets to 20% and space targets to 0% and solve it</span>
<span class="va">sim_rs_s2_amount</span> <span class="op"><-</span> <span class="fu"><a href="../reference/update.html">update</a></span><span class="op">(</span><span class="va">sim_ru_s2</span>, amount.target <span class="op">=</span> <span class="fl">0.2</span>, space.target <span class="op">=</span> <span class="cn">NA</span>,
solve <span class="op">=</span> <span class="cn">TRUE</span>, Threads <span class="op">=</span> <span class="va">threads</span><span class="op">)</span></code></pre></div>
<pre><code>## Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (linux64)
## Thread count: 4 physical cores, 8 logical processors, using up to 6 threads
## Optimize a model with 1 rows, 100 columns and 100 nonzeros
## Model fingerprint: 0x3d4ec257
## Variable types: 0 continuous, 100 integer (100 binary)
## Coefficient statistics:
## Matrix range [7e-02, 7e-01]
## Objective range [1e+00, 1e+00]
## Bounds range [1e+00, 1e+00]
## RHS range [7e+00, 7e+00]
## Found heuristic solution: objective 27.0000000
## Presolve removed 0 rows and 86 columns
## Presolve time: 0.00s
## Presolved: 1 rows, 14 columns, 14 nonzeros
## Variable types: 0 continuous, 14 integer (0 binary)
## Presolved: 1 rows, 14 columns, 14 nonzeros
##
##
## Root relaxation: objective 9.864476e+00, 6 iterations, 0.00 seconds
##
## Nodes | Current Node | Objective Bounds | Work
## Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
##
## 0 0 9.86448 0 1 27.00000 9.86448 63.5% - 0s
## H 0 0 14.0000000 9.86448 29.5% - 0s
## H 0 0 10.0000000 9.86448 1.36% - 0s
## 0 0 9.86448 0 1 10.00000 9.86448 1.36% - 0s
##
## Explored 1 nodes (6 simplex iterations) in 0.00 seconds
## Thread count was 6 (of 8 available processors)
##
## Solution count 3: 10 14 27
##
## Optimal solution found (tolerance 1.00e-01)
## Best objective 1.000000000000e+01, best bound 1.000000000000e+01, gap 0.0000%</code></pre>
<div class="sourceCode" id="cb23"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show summary</span>
<span class="fu"><a href="../reference/summary.html">summary</a></span><span class="op">(</span><span class="va">sim_rs_s2_amount</span><span class="op">)</span></code></pre></div>
<pre><code>## Run_Number Status Score Cost Planning_Units Connectivity_Total
## 1 1 OPTIMAL 10 10 10 220
## Connectivity_In Connectivity_Edge Connectivity_Out Connectivity_In_Fraction
## 1 12 192 16 0.05454545</code></pre>
<div class="sourceCode" id="cb25"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show amount held</span>
<span class="fu"><a href="../reference/amount.held.html">amount.held</a></span><span class="op">(</span><span class="va">sim_rs_s2_amount</span><span class="op">)</span></code></pre></div>
<pre><code>## normal
## 1 0.2026153</code></pre>
<div class="sourceCode" id="cb27"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show space held</span>
<span class="fu"><a href="../reference/space.held.html">space.held</a></span><span class="op">(</span><span class="va">sim_rs_s2_amount</span><span class="op">)</span></code></pre></div>
<pre><code>## normal (Space 1)
## 1 0.5909494</code></pre>
<p>Now let’s visualize the prioritization we made for the normal species.</p>
<div class="sourceCode" id="cb29"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># plot the prioritization and the normal species' distribution</span>
<span class="fu"><a href="../reference/spp.plot.html">spp.plot</a></span><span class="op">(</span><span class="va">sim_rs_s2_amount</span>, <span class="fl">1</span>, main <span class="op">=</span> <span class="st">"Normal species"</span><span class="op">)</span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="raptr_files/figure-html/unnamed-chunk-17-1.png" alt="_A prioritization for the normally distributed species generated using amount-based targets (20\%). See Figure 3 caption for conventions._" width="432"><p class="caption">
<em>A prioritization for the normally distributed species generated using amount-based targets (20%). See Figure 3 caption for conventions.</em>
</p>
</div>
<p>The amount-based prioritization for the normal species focuses only on the species’ range core. This prioritization fails to secure any peripheral parts of the species’ distribution. As a consequence, it may miss out on populations with novel adaptations to environmental conditions along the species’ range margin.</p>
<p>Now, let’s generate an amount-based target for the bimodally distributed species view it.</p>
<div class="sourceCode" id="cb30"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># create new object with just the bimodal species</span>
<span class="va">sim_ru_s3</span> <span class="op"><-</span> <span class="fu"><a href="../reference/spp.subset.html">spp.subset</a></span><span class="op">(</span><span class="va">sim_ru</span>, <span class="st">"bimodal"</span><span class="op">)</span></code></pre></div>
<div class="sourceCode" id="cb31"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># update amount targets to 20% and space targets to 0% and solve it</span>
<span class="va">sim_rs_s3_amount</span> <span class="op"><-</span> <span class="fu"><a href="../reference/update.html">update</a></span><span class="op">(</span><span class="va">sim_ru_s3</span>, amount.target <span class="op">=</span> <span class="fl">0.2</span>,
space.target <span class="op">=</span> <span class="cn">NA</span>, Threads <span class="op">=</span> <span class="va">threads</span><span class="op">)</span></code></pre></div>
<pre><code>## Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (linux64)
## Thread count: 4 physical cores, 8 logical processors, using up to 6 threads
## Optimize a model with 1 rows, 100 columns and 100 nonzeros
## Model fingerprint: 0x1ce55139
## Variable types: 0 continuous, 100 integer (100 binary)
## Coefficient statistics:
## Matrix range [7e-03, 9e-01]
## Objective range [1e+00, 1e+00]
## Bounds range [1e+00, 1e+00]
## RHS range [7e+00, 7e+00]
## Found heuristic solution: objective 21.0000000
## Presolve removed 0 rows and 75 columns
## Presolve time: 0.00s
## Presolved: 1 rows, 25 columns, 25 nonzeros
## Variable types: 0 continuous, 25 integer (0 binary)
## Presolved: 1 rows, 25 columns, 25 nonzeros
##
##
## Root relaxation: objective 7.919039e+00, 17 iterations, 0.00 seconds
##
## Nodes | Current Node | Objective Bounds | Work
## Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
##
## 0 0 7.91904 0 1 21.00000 7.91904 62.3% - 0s
## H 0 0 16.0000000 7.91904 50.5% - 0s
## H 0 0 8.0000000 7.91904 1.01% - 0s
## 0 0 7.91904 0 1 8.00000 7.91904 1.01% - 0s
##
## Explored 1 nodes (17 simplex iterations) in 0.00 seconds
## Thread count was 6 (of 8 available processors)
##
## Solution count 3: 8 16 21
##
## Optimal solution found (tolerance 1.00e-01)
## Best objective 8.000000000000e+00, best bound 8.000000000000e+00, gap 0.0000%</code></pre>
<div class="sourceCode" id="cb33"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># plot the prioritization and the bimodal species' distribution</span>
<span class="fu"><a href="../reference/spp.plot.html">spp.plot</a></span><span class="op">(</span><span class="va">sim_rs_s3_amount</span>, <span class="fl">1</span>, main <span class="op">=</span> <span class="st">"Bimodal species"</span><span class="op">)</span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="raptr_files/figure-html/unnamed-chunk-20-1.png" alt="_A prioritization for the bimodally distributed species generated using amount-based targets (20\%). See Figure 3 caption for conventions._" width="432"><p class="caption">
<em>A prioritization for the bimodally distributed species generated using amount-based targets (20%). See Figure 3 caption for conventions.</em>
</p>
</div>
<div class="sourceCode" id="cb34"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show summary</span>
<span class="fu"><a href="../reference/summary.html">summary</a></span><span class="op">(</span><span class="va">sim_rs_s3_amount</span><span class="op">)</span></code></pre></div>
<pre><code>## Run_Number Status Score Cost Planning_Units Connectivity_Total
## 1 1 OPTIMAL 8 8 8 220
## Connectivity_In Connectivity_Edge Connectivity_Out Connectivity_In_Fraction
## 1 9 197 14 0.04090909</code></pre>
<div class="sourceCode" id="cb36"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show amount held</span>
<span class="fu"><a href="../reference/amount.held.html">amount.held</a></span><span class="op">(</span><span class="va">sim_rs_s3_amount</span><span class="op">)</span></code></pre></div>
<pre><code>## bimodal
## 1 0.2018391</code></pre>
<div class="sourceCode" id="cb38"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show space held</span>
<span class="fu"><a href="../reference/space.held.html">space.held</a></span><span class="op">(</span><span class="va">sim_rs_s3_amount</span><span class="op">)</span></code></pre></div>
<pre><code>## bimodal (Space 1)
## 1 0.1200278</code></pre>
<p>The amount-based prioritization for the bimodally distributed species only selects planning units in the bottom left corner of the study area. This prioritization only preserves individuals belonging to one of the two ecotypes. As a consequence, this prioritization may fail to preserve a representative sample of the genetic variation found inside this species.</p>
</div>
<div id="amount-based-and-space-based-targets" class="section level3">
<h3 class="hasAnchor">
<a href="#amount-based-and-space-based-targets" class="anchor" aria-hidden="true"></a>Amount-based and space-based targets</h3>
<p>Now that we have generated a prioritization for each species using only amount-based targets, we will generate a prioritizations using both amount-based and space-targets. To do this we will update the space targets in our amount-based prioritizations to 85%, and store the new prioritizations in new objects.</p>
<p>First, let’s do this for the uniform species.</p>
<div class="sourceCode" id="cb40"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># make new prioritization</span>
<span class="va">sim_rs_s1_space</span> <span class="op"><-</span> <span class="fu"><a href="../reference/update.html">update</a></span><span class="op">(</span><span class="va">sim_rs_s1_amount</span>, amount.target <span class="op">=</span> <span class="fl">0.2</span>,
space.target <span class="op">=</span> <span class="fl">0.85</span>, Threads <span class="op">=</span> <span class="va">threads</span><span class="op">)</span></code></pre></div>
<pre><code>## Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (linux64)
## Thread count: 4 physical cores, 8 logical processors, using up to 6 threads
## Optimize a model with 10102 rows, 10100 columns and 40000 nonzeros
## Model fingerprint: 0x3f02f09a
## Variable types: 0 continuous, 10100 integer (10100 binary)
## Coefficient statistics:
## Matrix range [5e-01, 8e+01]
## Objective range [1e+00, 1e+00]
## Bounds range [1e+00, 1e+00]
## RHS range [1e+00, 1e+02]
## Found heuristic solution: objective 95.0000000
## Presolve removed 36 rows and 0 columns
## Presolve time: 1.04s
## Presolved: 10066 rows, 10100 columns, 40104 nonzeros
## Variable types: 0 continuous, 10100 integer (10100 binary)
## Presolved: 10066 rows, 10100 columns, 40104 nonzeros
##
##
## Root relaxation: objective 2.000000e+01, 621 iterations, 0.04 seconds
##
## Nodes | Current Node | Objective Bounds | Work
## Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
##
## * 0 0 0 20.0000000 20.00000 0.00% - 1s
##
## Explored 0 nodes (1158 simplex iterations) in 1.14 seconds
## Thread count was 6 (of 8 available processors)
##
## Solution count 2: 20 95
##
## Optimal solution found (tolerance 1.00e-01)
## Best objective 2.000000000000e+01, best bound 2.000000000000e+01, gap 0.0000%</code></pre>
<div class="sourceCode" id="cb42"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show summary</span>
<span class="fu"><a href="../reference/summary.html">summary</a></span><span class="op">(</span><span class="va">sim_rs_s1_space</span><span class="op">)</span></code></pre></div>
<pre><code>## Run_Number Status Score Cost Planning_Units Connectivity_Total
## 1 1 OPTIMAL 20 20 20 220
## Connectivity_In Connectivity_Edge Connectivity_Out Connectivity_In_Fraction
## 1 13 147 60 0.05909091</code></pre>
<div class="sourceCode" id="cb44"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show amount held</span>
<span class="fu"><a href="../reference/amount.held.html">amount.held</a></span><span class="op">(</span><span class="va">sim_rs_s1_space</span><span class="op">)</span></code></pre></div>
<pre><code>## uniform
## 1 0.2</code></pre>
<div class="sourceCode" id="cb46"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show space held</span>
<span class="fu"><a href="../reference/space.held.html">space.held</a></span><span class="op">(</span><span class="va">sim_rs_s1_space</span><span class="op">)</span></code></pre></div>
<pre><code>## uniform (Space 1)
## 1 0.909697</code></pre>
<p>Let’s take a look at the prioritization for the uniform species with amount-based and space-based targets. Then, let’s compare the solutions for the amount-based prioritization with the new prioritization using both amount and space targets.</p>
<div class="sourceCode" id="cb48"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># plot the prioritization and the uniform species' distribution</span>
<span class="fu"><a href="../reference/spp.plot.html">spp.plot</a></span><span class="op">(</span><span class="va">sim_rs_s1_space</span>, <span class="st">"uniform"</span>, main <span class="op">=</span> <span class="st">"Uniform species"</span><span class="op">)</span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="raptr_files/figure-html/unnamed-chunk-24-1.png" alt="_A prioritization for the uniformly distributed species generated using amount-based targets (20\%) and space-based targets (85\%). See Figure 3 caption for conventions._" width="432"><p class="caption">
<em>A prioritization for the uniformly distributed species generated using amount-based targets (20%) and space-based targets (85%). See Figure 3 caption for conventions.</em>
</p>
</div>
<div class="sourceCode" id="cb49"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># plot the difference between old and new prioritizations</span>
<span class="fu"><a href="../reference/plot.html">plot</a></span><span class="op">(</span><span class="va">sim_rs_s1_amount</span>, <span class="va">sim_rs_s1_space</span>, <span class="fl">1</span>, <span class="fl">1</span>,
main <span class="op">=</span> <span class="st">"Difference between solutions"</span><span class="op">)</span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="raptr_files/figure-html/unnamed-chunk-25-1.png" alt="_Difference between two prioritizations for the uniformly distributed species. Prioritisation $X$ was generated using just amount-based targets (20\%), and prioritization $Y$ was generated using an additional space-based target (85\%)._" width="576"><p class="caption">
<em>Difference between two prioritizations for the uniformly distributed species. Prioritisation <span class="math inline">\(X\)</span> was generated using just amount-based targets (20%), and prioritization <span class="math inline">\(Y\)</span> was generated using an additional space-based target (85%).</em>
</p>
</div>
<p>Here we can see that by including a space-target, the prioritization is spread out evenly across the species’ distribution. Unlike the amount-based prioritization, this prioritization samples all the different parts of the species’ distribution.</p>
<p>Now, let’s generate a prioritization for the normally distributed species that considers amount-based and space-based targets. Then, let’s visualize the new prioritization and compare it to the old amount-based prioritization.</p>
<div class="sourceCode" id="cb50"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># make new prioritization</span>
<span class="va">sim_rs_s2_space</span> <span class="op"><-</span> <span class="fu"><a href="../reference/update.html">update</a></span><span class="op">(</span><span class="va">sim_rs_s2_amount</span>, amount.target <span class="op">=</span> <span class="fl">0.2</span>,
space.target <span class="op">=</span> <span class="fl">0.85</span>, Threads <span class="op">=</span> <span class="va">threads</span><span class="op">)</span></code></pre></div>
<pre><code>## Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (linux64)
## Thread count: 4 physical cores, 8 logical processors, using up to 6 threads
## Optimize a model with 10102 rows, 10100 columns and 40000 nonzeros
## Model fingerprint: 0xa48af59a
## Variable types: 0 continuous, 10100 integer (10100 binary)
## Coefficient statistics:
## Matrix range [7e-02, 4e+01]
## Objective range [1e+00, 1e+00]
## Bounds range [1e+00, 1e+00]
## RHS range [1e+00, 6e+01]
## Found heuristic solution: objective 91.0000000
## Presolve removed 220 rows and 0 columns
## Presolve time: 0.74s
## Presolved: 9882 rows, 10100 columns, 41664 nonzeros
## Variable types: 0 continuous, 10100 integer (10100 binary)
## Presolved: 9882 rows, 10100 columns, 41664 nonzeros
##
##
## Root relaxation: objective 1.232570e+01, 4022 iterations, 0.12 seconds
##
## Nodes | Current Node | Objective Bounds | Work
## Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
##
## 0 0 12.32570 0 294 91.00000 12.32570 86.5% - 0s
## H 0 0 13.0000000 12.32570 5.19% - 0s
## 0 0 12.32570 0 294 13.00000 12.32570 5.19% - 0s
##
## Explored 1 nodes (4344 simplex iterations) in 0.94 seconds
## Thread count was 6 (of 8 available processors)
##
## Solution count 2: 13 91
##
## Optimal solution found (tolerance 1.00e-01)
## Best objective 1.300000000000e+01, best bound 1.300000000000e+01, gap 0.0000%</code></pre>
<div class="sourceCode" id="cb52"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show summary</span>
<span class="fu"><a href="../reference/summary.html">summary</a></span><span class="op">(</span><span class="va">sim_rs_s2_space</span><span class="op">)</span></code></pre></div>
<pre><code>## Run_Number Status Score Cost Planning_Units Connectivity_Total
## 1 1 OPTIMAL 13 13 13 220
## Connectivity_In Connectivity_Edge Connectivity_Out Connectivity_In_Fraction
## 1 5 173 42 0.02272727</code></pre>
<div class="sourceCode" id="cb54"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show amount held</span>
<span class="fu"><a href="../reference/amount.held.html">amount.held</a></span><span class="op">(</span><span class="va">sim_rs_s2_space</span><span class="op">)</span></code></pre></div>
<pre><code>## normal
## 1 0.2099983</code></pre>
<div class="sourceCode" id="cb56"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show space held</span>
<span class="fu"><a href="../reference/space.held.html">space.held</a></span><span class="op">(</span><span class="va">sim_rs_s2_space</span><span class="op">)</span></code></pre></div>
<pre><code>## normal (Space 1)
## 1 0.8533832</code></pre>
<div class="sourceCode" id="cb58"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># plot the prioritization and the normal species' distribution</span>
<span class="fu"><a href="../reference/spp.plot.html">spp.plot</a></span><span class="op">(</span><span class="va">sim_rs_s2_space</span>, <span class="st">"normal"</span>, main <span class="op">=</span> <span class="st">"Normal species"</span><span class="op">)</span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="raptr_files/figure-html/unnamed-chunk-28-1.png" alt="_A prioritization for the normally distributed species generated using amount-based targets (20\%) and space-based targets (85\%). See Figure 3 caption for conventions._" width="432"><p class="caption">
<em>A prioritization for the normally distributed species generated using amount-based targets (20%) and space-based targets (85%). See Figure 3 caption for conventions.</em>
</p>
</div>
<div class="sourceCode" id="cb59"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># plot the difference between old and new prioritizations</span>
<span class="fu"><a href="../reference/plot.html">plot</a></span><span class="op">(</span><span class="va">sim_rs_s2_amount</span>, <span class="va">sim_rs_s2_space</span>, <span class="fl">1</span>, <span class="fl">1</span>,
main <span class="op">=</span> <span class="st">"Difference between solutions"</span><span class="op">)</span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="raptr_files/figure-html/unnamed-chunk-29-1.png" alt="_Difference between two prioritizations for the normally distributed species. See Figure 7 caption for conventions._" width="576"><p class="caption">
<em>Difference between two prioritizations for the normally distributed species. See Figure 7 caption for conventions.</em>
</p>
</div>
<p>We can see by using both amount-based and space-based targets we can obtain a prioritization that secures both the species’ range core and parts of its range margin. As a consequence, it may capture any novel adaptations found along the species’ range margin–unlike the amount-based prioritization.</p>
<p>Finally, let’s generate a prioritization for the bimodal species using amount-based and space-based targets.</p>
<div class="sourceCode" id="cb60"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># make new prioritization</span>
<span class="va">sim_rs_s3_space</span> <span class="op"><-</span> <span class="fu"><a href="../reference/update.html">update</a></span><span class="op">(</span><span class="va">sim_rs_s3_amount</span>, amount.target <span class="op">=</span> <span class="fl">0.2</span>,
space.target <span class="op">=</span> <span class="fl">0.85</span>, Threads <span class="op">=</span> <span class="va">threads</span><span class="op">)</span></code></pre></div>
<pre><code>## Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (linux64)
## Thread count: 4 physical cores, 8 logical processors, using up to 6 threads
## Optimize a model with 10102 rows, 10100 columns and 40000 nonzeros
## Model fingerprint: 0x9175928f
## Variable types: 0 continuous, 10100 integer (10100 binary)
## Coefficient statistics:
## Matrix range [7e-03, 9e+01]
## Objective range [1e+00, 1e+00]
## Bounds range [1e+00, 1e+00]
## RHS range [1e+00, 7e+01]
## Found heuristic solution: objective 87.0000000
## Presolve removed 589 rows and 17 columns
## Presolve time: 1.92s
## Presolved: 9513 rows, 10083 columns, 43814 nonzeros
## Variable types: 0 continuous, 10083 integer (10083 binary)
## Presolved: 9513 rows, 10083 columns, 43814 nonzeros
##
##
## Root relaxation: objective 8.980792e+00, 5845 iterations, 0.17 seconds
##
## Nodes | Current Node | Objective Bounds | Work
## Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
##
## 0 0 8.98079 0 75 87.00000 8.98079 89.7% - 2s
## H 0 0 10.0000000 8.98079 10.2% - 2s
##
## Cutting planes:
## Gomory: 2
## MIR: 1
## Zero half: 1
##
## Explored 1 nodes (6003 simplex iterations) in 2.18 seconds
## Thread count was 6 (of 8 available processors)
##
## Solution count 2: 10 87
##
## Optimal solution found (tolerance 1.00e-01)
## Best objective 1.000000000000e+01, best bound 1.000000000000e+01, gap 0.0000%</code></pre>
<div class="sourceCode" id="cb62"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show summary</span>
<span class="fu"><a href="../reference/summary.html">summary</a></span><span class="op">(</span><span class="va">sim_rs_s3_space</span><span class="op">)</span></code></pre></div>
<pre><code>## Run_Number Status Score Cost Planning_Units Connectivity_Total
## 1 1 OPTIMAL 10 10 10 220
## Connectivity_In Connectivity_Edge Connectivity_Out Connectivity_In_Fraction
## 1 7 187 26 0.03181818</code></pre>
<div class="sourceCode" id="cb64"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show amount held</span>
<span class="fu"><a href="../reference/amount.held.html">amount.held</a></span><span class="op">(</span><span class="va">sim_rs_s3_space</span><span class="op">)</span></code></pre></div>
<pre><code>## bimodal
## 1 0.2226414</code></pre>
<div class="sourceCode" id="cb66"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show space held</span>
<span class="fu"><a href="../reference/space.held.html">space.held</a></span><span class="op">(</span><span class="va">sim_rs_s3_space</span><span class="op">)</span></code></pre></div>
<pre><code>## bimodal (Space 1)
## 1 0.8562891</code></pre>
<div class="sourceCode" id="cb68"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># plot the prioritization and the bimodal species' distribution</span>
<span class="fu"><a href="../reference/spp.plot.html">spp.plot</a></span><span class="op">(</span><span class="va">sim_rs_s3_space</span>, <span class="st">'bimodal'</span>, main<span class="op">=</span><span class="st">'Bimodal species'</span><span class="op">)</span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="raptr_files/figure-html/unnamed-chunk-32-1.png" alt="_A prioritization for the normally distributed species generated using amount-based targets (20\%) and space-based targets (85\%). See Figure 3 caption for conventions._" width="432"><p class="caption">
<em>A prioritization for the normally distributed species generated using amount-based targets (20%) and space-based targets (85%). See Figure 3 caption for conventions.</em>
</p>
</div>
<div class="sourceCode" id="cb69"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># plot the difference between old and new prioritizations</span>
<span class="fu"><a href="../reference/plot.html">plot</a></span><span class="op">(</span><span class="va">sim_rs_s3_amount</span>, <span class="va">sim_rs_s3_space</span>, <span class="fl">1</span>, <span class="fl">1</span>,
main <span class="op">=</span> <span class="st">"Difference between solutions"</span><span class="op">)</span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="raptr_files/figure-html/unnamed-chunk-33-1.png" alt="_Difference between two prioritizations for the bimodally distributed species. See Figure 7 caption for conventions._" width="576"><p class="caption">
<em>Difference between two prioritizations for the bimodally distributed species. See Figure 7 caption for conventions.</em>
</p>
</div>
<p>Earlier we found that the amount-based prioritization only preserved individuals from a single ecotype, and would have failed to adequately preserve the intra-specific variation for this species. However, here we can see that by including space-based targets, we can develop prioritizations that secure individuals belonging to both ecotypes. This new prioritization is much more effective at sampling the intra-specific variation for this species.</p>
<p>Overall, these results demonstrate that under the simplest of conditions, the use of space-based targets can improve prioritizations. However, these prioritizations were each generated for a single species. Prioritizations generated using multiple species may do a better job at preserving the intra-specific variation for individuals species by preserving them in different parts of their range. We will investigate this in the next section.</p>
</div>
</div>
<div id="multi-species-prioritizations" class="section level2">
<h2 class="hasAnchor">
<a href="#multi-species-prioritizations" class="anchor" aria-hidden="true"></a>Multi-species prioritizations</h2>
<div id="effects-of-including-space-based-targets" class="section level3">
<h3 class="hasAnchor">
<a href="#effects-of-including-space-based-targets" class="anchor" aria-hidden="true"></a>Effects of including space-based targets</h3>
<p>So far we have generated prioritizations using only a single species at a time. However, real world prioritizations are often generated using multiple species to ensure that they preserve a comprehensive set of biodiversity. Here, we will generate multi-species prioritizations that preserve all three of the simulated species. First, we will generate a prioritization using amount-based targets that only aims to preserve 20% of the area they occupy. Then, we will generate a prioritization that also incorporate space-based targets to also preserve 85% of their geographic distribution. We will then compare the two prioritizations.</p>
<div class="sourceCode" id="cb70"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># make prioritizations</span>
<span class="va">sim_mrs_amount</span> <span class="op"><-</span> <span class="fu"><a href="../reference/update.html">update</a></span><span class="op">(</span><span class="va">sim_ru</span>, amount.target <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/pkg/RandomFields/man/QMath.html" class="external-link">c</a></span><span class="op">(</span><span class="fl">0.2</span>, <span class="fl">0.2</span>, <span class="fl">0.2</span><span class="op">)</span>,
space.target <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/pkg/RandomFields/man/QMath.html" class="external-link">c</a></span><span class="op">(</span><span class="fl">0</span>, <span class="fl">0</span>, <span class="fl">0</span><span class="op">)</span>, Threads <span class="op">=</span> <span class="va">threads</span><span class="op">)</span></code></pre></div>
<pre><code>## Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (linux64)
## Thread count: 4 physical cores, 8 logical processors, using up to 6 threads
## Optimize a model with 30306 rows, 30100 columns and 120000 nonzeros
## Model fingerprint: 0xf6868af3
## Variable types: 0 continuous, 30100 integer (30100 binary)
## Coefficient statistics:
## Matrix range [7e-03, 9e+01]
## Objective range [1e+00, 1e+00]
## Bounds range [1e+00, 1e+00]
## RHS range [1e+00, 8e+02]
## Found heuristic solution: objective 98.0000000
## Presolve time: 0.55s
## Presolved: 30306 rows, 30100 columns, 120000 nonzeros
## Variable types: 0 continuous, 30100 integer (30100 binary)
## Presolved: 30306 rows, 30100 columns, 120000 nonzeros
##
##
## Root relaxation: objective 2.000000e+01, 2320 iterations, 0.48 seconds
##
## Nodes | Current Node | Objective Bounds | Work
## Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
##
## H 0 0 20.0000000 0.00000 100% - 1s
## 0 0 - 0 20.00000 20.00000 0.00% - 1s
##
## Explored 0 nodes (4348 simplex iterations) in 1.31 seconds
## Thread count was 6 (of 8 available processors)
##
## Solution count 2: 20 98
##
## Optimal solution found (tolerance 1.00e-01)
## Best objective 2.000000000000e+01, best bound 2.000000000000e+01, gap 0.0000%</code></pre>
<div class="sourceCode" id="cb72"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">sim_mrs_space</span> <span class="op"><-</span> <span class="fu"><a href="../reference/update.html">update</a></span><span class="op">(</span><span class="va">sim_ru</span>, amount.target <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/pkg/RandomFields/man/QMath.html" class="external-link">c</a></span><span class="op">(</span><span class="fl">0.2</span>, <span class="fl">0.2</span>, <span class="fl">0.2</span><span class="op">)</span>,
space.target <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/pkg/RandomFields/man/QMath.html" class="external-link">c</a></span><span class="op">(</span><span class="fl">0.85</span>, <span class="fl">0.85</span>, <span class="fl">0.85</span><span class="op">)</span>,
Threads <span class="op">=</span> <span class="va">threads</span><span class="op">)</span></code></pre></div>
<pre><code>## Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (linux64)
## Thread count: 4 physical cores, 8 logical processors, using up to 6 threads
## Optimize a model with 30306 rows, 30100 columns and 120000 nonzeros
## Model fingerprint: 0xfe534681
## Variable types: 0 continuous, 30100 integer (30100 binary)
## Coefficient statistics:
## Matrix range [7e-03, 9e+01]
## Objective range [1e+00, 1e+00]
## Bounds range [1e+00, 1e+00]
## RHS range [1e+00, 1e+02]
## Found heuristic solution: objective 99.0000000
## Presolve removed 833 rows and 17 columns
## Presolve time: 4.11s
## Presolved: 29473 rows, 30083 columns, 123899 nonzeros
## Variable types: 0 continuous, 30083 integer (30083 binary)
## Presolved: 29473 rows, 30083 columns, 123899 nonzeros
##
##
## Root relaxation: objective 2.000000e+01, 4787 iterations, 0.69 seconds
## Total elapsed time = 5.00s
##
## Nodes | Current Node | Objective Bounds | Work
## Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
##
## H 0 0 20.0000000 0.00000 100% - 5s
## 0 0 - 0 20.00000 20.00000 0.00% - 5s
##
## Explored 0 nodes (8856 simplex iterations) in 5.05 seconds
## Thread count was 6 (of 8 available processors)
##
## Solution count 2: 20 99
##
## Optimal solution found (tolerance 1.00e-01)
## Best objective 2.000000000000e+01, best bound 2.000000000000e+01, gap 0.0000%</code></pre>
<div class="sourceCode" id="cb74"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show summaries</span>
<span class="fu"><a href="../reference/summary.html">summary</a></span><span class="op">(</span><span class="va">sim_mrs_amount</span><span class="op">)</span></code></pre></div>
<pre><code>## Run_Number Status Score Cost Planning_Units Connectivity_Total
## 1 1 OPTIMAL 20 20 20 220
## Connectivity_In Connectivity_Edge Connectivity_Out Connectivity_In_Fraction
## 1 8 142 70 0.03636364</code></pre>
<div class="sourceCode" id="cb76"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="../reference/summary.html">summary</a></span><span class="op">(</span><span class="va">sim_mrs_space</span><span class="op">)</span></code></pre></div>
<pre><code>## Run_Number Status Score Cost Planning_Units Connectivity_Total
## 1 1 OPTIMAL 20 20 20 220
## Connectivity_In Connectivity_Edge Connectivity_Out Connectivity_In_Fraction
## 1 5 140 75 0.02272727</code></pre>
<div class="sourceCode" id="cb78"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show amount held for each prioritization</span>
<span class="fu"><a href="../reference/amount.held.html">amount.held</a></span><span class="op">(</span><span class="va">sim_mrs_amount</span><span class="op">)</span></code></pre></div>
<pre><code>## uniform normal bimodal
## 1 0.2 0.2307696 0.2664269</code></pre>
<div class="sourceCode" id="cb80"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="../reference/amount.held.html">amount.held</a></span><span class="op">(</span><span class="va">sim_mrs_space</span><span class="op">)</span></code></pre></div>
<pre><code>## uniform normal bimodal
## 1 0.2 0.2228158 0.2293413</code></pre>
<div class="sourceCode" id="cb82"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show space held for each prioritization</span>
<span class="fu"><a href="../reference/space.held.html">space.held</a></span><span class="op">(</span><span class="va">sim_mrs_amount</span><span class="op">)</span></code></pre></div>
<pre><code>## uniform (Space 1) normal (Space 1) bimodal (Space 1)
## 1 0.890303 0.8662688 0.9201247</code></pre>
<div class="sourceCode" id="cb84"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="../reference/space.held.html">space.held</a></span><span class="op">(</span><span class="va">sim_mrs_space</span><span class="op">)</span></code></pre></div>
<pre><code>## uniform (Space 1) normal (Space 1) bimodal (Space 1)
## 1 0.929697 0.9084047 0.9308147</code></pre>
<div class="sourceCode" id="cb86"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># plot multi-species prioritization with amount-based targets</span>
<span class="fu"><a href="../reference/plot.html">plot</a></span><span class="op">(</span><span class="va">sim_mrs_amount</span>, <span class="fl">1</span>, main <span class="op">=</span> <span class="st">"Amount-based targets"</span><span class="op">)</span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="raptr_files/figure-html/unnamed-chunk-36-1.png" alt="_A multi-species prioritization for the uniformly, normally, and bimodally distributed species generated using just amount-based targets (20\%). Squares represent planning units. Dark green planning units are selected for preservation._" width="432"><p class="caption">
<em>A multi-species prioritization for the uniformly, normally, and bimodally distributed species generated using just amount-based targets (20%). Squares represent planning units. Dark green planning units are selected for preservation.</em>
</p>
</div>
<div class="sourceCode" id="cb87"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># plot multi-species prioritization with amount- and space-based targets</span>
<span class="fu"><a href="../reference/plot.html">plot</a></span><span class="op">(</span><span class="va">sim_mrs_space</span>, <span class="fl">1</span>, main <span class="op">=</span> <span class="st">"Amount and space-based targets"</span><span class="op">)</span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="raptr_files/figure-html/unnamed-chunk-37-1.png" alt="_A multi-species prioritization for the uniformly, normally, and bimodally distributed species generated using amount-based targets (20\%) and space-based targets (85\%). See Figure 12 caption for conventions._" width="432"><p class="caption">
<em>A multi-species prioritization for the uniformly, normally, and bimodally distributed species generated using amount-based targets (20%) and space-based targets (85%). See Figure 12 caption for conventions.</em>
</p>
</div>
<div class="sourceCode" id="cb88"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># difference between the two prioritizations</span>
<span class="fu"><a href="../reference/plot.html">plot</a></span><span class="op">(</span><span class="va">sim_mrs_amount</span>, <span class="va">sim_mrs_space</span>, <span class="fl">1</span>, <span class="fl">1</span>, main <span class="op">=</span> <span class="st">"Difference between solutions"</span><span class="op">)</span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="raptr_files/figure-html/unnamed-chunk-38-1.png" alt="_Difference between two multi-species prioritizations. See Figure 7 caption for conventions.)" width="576"><p class="caption">
_Difference between two multi-species prioritizations. See Figure 7 caption for conventions.)
</p>
</div>
<p>Here we can see that the inclusion of space-based targets changes which planning units are selected for prioritization, but also the number of planning units that are selected. The amount-based prioritization is comprised of 20 units, and the space-based prioritization is comprised of 20 units. This result suggests that an adequate and representative prioritization can be achieved for only a minor increase in cost.</p>
</div>
<div id="uncertainty-in-species-distributions" class="section level3">
<h3 class="hasAnchor">
<a href="#uncertainty-in-species-distributions" class="anchor" aria-hidden="true"></a>Uncertainty in species’ distributions</h3>
<p>The unreliable formulation does not consider the probability that the planning units are occupied by features when calculating how well a given solution secures a representative sample of an attribute space. Thus solutions identified using the unreliable formulation may select regions of an attribute space for a species using planning units that only have a small chance of being inhabited. As a consequence, if the prioritization is implemented, it may fail to secure regions of an attribute space if individuals do not inhabit these planning units, and ultimately fail to fulfill the space-based targets.</p>
<p>A simple solution to this issue would be to ensure that planning units cannot be assigned to demand points if they have a low probability of occupancy. This can be achieved by setting a probability threshold for planning units, such that planning units with a probability of occupancy below the threshold are effectively set to zero.</p>
<div class="sourceCode" id="cb89"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># make new prioritization with probability threshold of 0.1 for each species</span>
<span class="va">sim_mrs_space2</span> <span class="op"><-</span> <span class="fu"><a href="../reference/solve.html">solve</a></span><span class="op">(</span><span class="fu"><a href="../reference/prob.subset.html">prob.subset</a></span><span class="op">(</span><span class="va">sim_mrs_space</span>, species <span class="op">=</span> <span class="fl">1</span><span class="op">:</span><span class="fl">3</span>,
threshold <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/pkg/RandomFields/man/QMath.html" class="external-link">c</a></span><span class="op">(</span><span class="fl">0.1</span>, <span class="fl">0.1</span>, <span class="fl">0.1</span><span class="op">)</span><span class="op">)</span>,
Threads <span class="op">=</span> <span class="va">threads</span><span class="op">)</span></code></pre></div>
<pre><code>## Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (linux64)
## Thread count: 4 physical cores, 8 logical processors, using up to 6 threads
## Optimize a model with 30306 rows, 30100 columns and 119974 nonzeros
## Model fingerprint: 0xde859f63
## Variable types: 0 continuous, 30100 integer (30100 binary)
## Coefficient statistics:
## Matrix range [7e-03, 9e+01]
## Objective range [1e+00, 1e+00]
## Bounds range [1e+00, 1e+00]
## RHS range [1e+00, 1e+02]
## Found heuristic solution: objective 99.0000000
## Presolve removed 833 rows and 17 columns
## Presolve time: 4.36s
## Presolved: 29473 rows, 30083 columns, 123873 nonzeros
## Variable types: 0 continuous, 30083 integer (30083 binary)
## Presolved: 29473 rows, 30083 columns, 123873 nonzeros
##
##
## Root simplex log...
##
## Iteration Objective Primal Inf. Dual Inf. Time
## 4686 2.0000000e+01 0.000000e+00 0.000000e+00 5s
##
## Root relaxation: objective 2.000000e+01, 4686 iterations, 0.63 seconds
##
## Nodes | Current Node | Objective Bounds | Work
## Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
##
## H 0 0 20.0000000 0.00000 100% - 5s
## 0 0 - 0 20.00000 20.00000 0.00% - 5s
##
## Explored 0 nodes (9696 simplex iterations) in 5.77 seconds
## Thread count was 6 (of 8 available processors)
##
## Solution count 2: 20 99
##
## Optimal solution found (tolerance 1.00e-01)
## Best objective 2.000000000000e+01, best bound 2.000000000000e+01, gap 0.0000%</code></pre>
<div class="sourceCode" id="cb91"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show summary</span>
<span class="fu"><a href="../reference/summary.html">summary</a></span><span class="op">(</span><span class="va">sim_mrs_space2</span><span class="op">)</span></code></pre></div>
<pre><code>## Run_Number Status Score Cost Planning_Units Connectivity_Total
## 1 1 OPTIMAL 20 20 20 220
## Connectivity_In Connectivity_Edge Connectivity_Out Connectivity_In_Fraction
## 1 9 143 68 0.04090909</code></pre>
<div class="sourceCode" id="cb93"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># plot prioritization</span>
<span class="fu"><a href="../reference/plot.html">plot</a></span><span class="op">(</span><span class="va">sim_mrs_space2</span>, <span class="fl">1</span><span class="op">)</span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="raptr_files/figure-html/unnamed-chunk-42-1.png" alt="_A multi-species prioritization for the uniformly, normally, and bimodally distributed species generated using amount-based targets (20\%) and space-based targets (85\%). This prioritization was generated to be robust against low occupancy probabilities, by preventing planning units with low probabilities from being used to represent demand points. See Figure 12 caption for conventions._" width="432"><p class="caption">
<em>A multi-species prioritization for the uniformly, normally, and bimodally distributed species generated using amount-based targets (20%) and space-based targets (85%). This prioritization was generated to be robust against low occupancy probabilities, by preventing planning units with low probabilities from being used to represent demand points. See Figure 12 caption for conventions.</em>
</p>
</div>
<div class="sourceCode" id="cb94"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># difference between prioritizations that use and do not use thresholds</span>
<span class="fu"><a href="../reference/plot.html">plot</a></span><span class="op">(</span><span class="va">sim_mrs_space2</span>, <span class="va">sim_mrs_space</span>, <span class="fl">1</span>, <span class="fl">1</span>, main <span class="op">=</span> <span class="st">"Difference between solutions"</span><span class="op">)</span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="raptr_files/figure-html/unnamed-chunk-43-1.png" alt="_Difference between two multi-species prioritizations. See Figure 7 caption for conventions._" width="576"><p class="caption">
<em>Difference between two multi-species prioritizations. See Figure 7 caption for conventions.</em>
</p>
</div>
<p>But this method requires setting somewhat arbitrary thresholds. A more robust solution to this issue is to actually use the probability that species occupy planning units to generate the prioritizations. This is what the reliable formulation does. First we will try and generate a solution using existing targets and the reliable formulation. To reduce computational time, we will set the maximum backup <span class="math inline">\(R\)</span>-level to 1.</p>
<div class="sourceCode" id="cb95"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># make new prioritization using reliable formulation</span>
<span class="va">sim_mrs_space3</span> <span class="op"><-</span> <span class="kw"><a href="https://rdrr.io/r/base/try.html" class="external-link">try</a></span><span class="op">(</span><span class="fu"><a href="../reference/update.html">update</a></span><span class="op">(</span><span class="va">sim_mrs_space</span>, formulation <span class="op">=</span> <span class="st">"reliable"</span>,
max.r.level <span class="op">=</span> <span class="fl">1L</span>, Threads <span class="op">=</span> <span class="va">threads</span><span class="op">)</span><span class="op">)</span></code></pre></div>
<pre><code>## Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (linux64)
## Thread count: 4 physical cores, 8 logical processors, using up to 6 threads
## Optimize a model with 364206 rows, 181900 columns and 3847200 nonzeros
## Model fingerprint: 0xee04bf48
## Variable types: 0 continuous, 60700 integer (60700 binary)
## Semi-Variable types: 121200 continuous, 0 integer
## Coefficient statistics:
## Matrix range [8e-04, 1e+02]
## Objective range [1e+00, 1e+00]
## Bounds range [1e+00, 1e+00]
## RHS range [7e-03, 1e+02]
## Presolve removed 338506 rows and 156703 columns
## Presolve time: 1.41s
##
## Explored 0 nodes (0 simplex iterations) in 1.62 seconds
## Thread count was 1 (of 8 available processors)
##
## Solution count 0
##
## Model is infeasible
## Best objective -, best bound -, gap -
## Error in .local(a, b, ...) :
## No solution found because the problem cannot be solved because space-based targets are too high. Try setting lower space-based targets. See ?maximum.targets</code></pre>
<p>However, this fails. The reason why we cannot generate a prioritization that fulfills these targets is because even the solution that contains all the planning units is still insufficient when we consider probabilities. The negative maximum targets printed in the error message indicate that planning units have low probabilities of occupancy. To fulfill the targets, we must obtain more planning units with higher probabilities of occupancy. We also could attempt resolving the problem using a higher <span class="math inline">\(R\)</span>-level. Instead, we will set lower targets and generate solution.</p>
<div class="sourceCode" id="cb97"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># make new prioritization using reliable formulation and reduced targets</span>
<span class="va">sim_mrs_space3</span> <span class="op"><-</span> <span class="fu"><a href="../reference/update.html">update</a></span><span class="op">(</span><span class="va">sim_mrs_space</span>, formulation <span class="op">=</span> <span class="st">"reliable"</span>,
max.r.level <span class="op">=</span> <span class="fl">1L</span>, space.target <span class="op">=</span> <span class="op">-</span><span class="fl">1000</span>,
Threads <span class="op">=</span> <span class="va">threads</span><span class="op">)</span></code></pre></div>
<pre><code>## Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (linux64)
## Thread count: 4 physical cores, 8 logical processors, using up to 6 threads
## Optimize a model with 364206 rows, 181900 columns and 3847200 nonzeros
## Model fingerprint: 0x1fba7cb2
## Variable types: 0 continuous, 60700 integer (60700 binary)
## Semi-Variable types: 121200 continuous, 0 integer
## Coefficient statistics:
## Matrix range [8e-04, 1e+02]
## Objective range [1e+00, 1e+00]
## Bounds range [1e+00, 1e+00]
## RHS range [7e-03, 8e+05]
## Presolve removed 333903 rows and 151800 columns
## Presolve time: 2.58s
## Presolved: 30303 rows, 30100 columns, 90300 nonzeros
## Variable types: 0 continuous, 30100 integer (30100 binary)
## Found heuristic solution: objective 27.0000000
## Presolved: 30303 rows, 30100 columns, 90300 nonzeros
##
##
## Root relaxation: objective 2.000000e+01, 129 iterations, 0.19 seconds
##
## Nodes | Current Node | Objective Bounds | Work
## Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
##
## 0 0 20.00000 0 3 27.00000 20.00000 25.9% - 3s
## H 0 0 20.0000000 20.00000 0.00% - 3s
## 0 0 20.00000 0 3 20.00000 20.00000 0.00% - 3s
##
## Explored 1 nodes (129 simplex iterations) in 3.04 seconds
## Thread count was 6 (of 8 available processors)
##
## Solution count 2: 20 27
##
## Optimal solution found (tolerance 1.00e-01)
## Best objective 2.000000000000e+01, best bound 2.000000000000e+01, gap 0.0000%</code></pre>
<pre><code>## Warning in validityMethod(object): some species have space.held values less than
## 0, and thus are poorly represented</code></pre>
<div class="sourceCode" id="cb100"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># show summary</span>
<span class="fu"><a href="../reference/summary.html">summary</a></span><span class="op">(</span><span class="va">sim_mrs_space3</span><span class="op">)</span></code></pre></div>
<pre><code>## Run_Number Status Score Cost Planning_Units Connectivity_Total
## 1 1 OPTIMAL 20 20 20 220
## Connectivity_In Connectivity_Edge Connectivity_Out Connectivity_In_Fraction
## 1 24 160 36 0.1090909</code></pre>
<div class="sourceCode" id="cb102"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># plot prioritization</span>
<span class="fu"><a href="../reference/plot.html">plot</a></span><span class="op">(</span><span class="va">sim_mrs_space3</span>, <span class="fl">1</span><span class="op">)</span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="raptr_files/figure-html/unnamed-chunk-47-1.png" alt="_A multi-species prioritization for the uniformly, normally, and bimodally distributed species generated using amount-based targets (20\%) and space-based targets (85\%). This prioritization was generated to be robust against low occupancy probabilities, by explicitly using the probability of occupancy data when deriving a solution. See Figure 12 caption for conventions._" width="432"><p class="caption">
<em>A multi-species prioritization for the uniformly, normally, and bimodally distributed species generated using amount-based targets (20%) and space-based targets (85%). This prioritization was generated to be robust against low occupancy probabilities, by explicitly using the probability of occupancy data when deriving a solution. See Figure 12 caption for conventions.</em>