forked from iadine/PPR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreserve_example.r
35 lines (25 loc) · 865 Bytes
/
reserve_example.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#########################################################################
# RESERVE EXAMPLE
#########################################################################
rm(list=ls())
library(MDPtoolbox)
source('mdp_example_reserve.r')
source('explore_solution_reserve.r')
source('dec2binvec.r')
source('getSite.r')
source('binvec2dec.r')
source('getState.r')
# Generate the species richness matrix (e.g. 7 species, 20 sites)
init_site <- 7
init_species <- 20
M <- round(matrix(nrow=init_site, ncol=init_species, data=runif(init_site*init_species,0,1)))
# Generate the transition and reward matrix
PR <- mdp_example_reserve(M, 0.2)
P <- PR$P
R <- PR$R
# Solve the reserve design problem
results <- mdp_value_iteration(P, R, 0.96, 0.001);
V <- results$V
policy <- results$policy
# Explore solution
explore_solution_reserve(numeric(init_site), policy, M, P, R)