-
Notifications
You must be signed in to change notification settings - Fork 1
/
tools.py
87 lines (65 loc) · 2.27 KB
/
tools.py
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
import math
import random
import sympy as sym
import numpy as np
from scipy.optimize import brentq
r, s, x, theta_r, tau = sym.symbols("r, s, x, theta_r, tau", positive=True)
alpha, H, beta, Gamma, F, epsilon = sym.symbols(
"alpha, H, beta, Gamma, F, epsilon", positive=True
)
def theta(r, s, theta_r=theta_r):
"""
Return the quantity of horn gained:
Parameters
----------
s: float between 0 and 1 - the proportion of poachers acting selectively
r: float between 0 and 1 - the proportion of horns devalued
theta_r: float between 0 and 1 - the value of dehorned horn
"""
return s * (1 - r) + (1 - s) * ((theta_r - 1) * r + 1)
def selective_time(r, tau):
"""
Expected time spent in park by a selective poacher
Parameters
----------
r: float between 0 and 1 - the proportion of horns devalued
tau: float between - the time taken to kill a horn
"""
return (r + tau * (1 - r)) / (1 - r)
def indiscriminate_time(r, tau, N_r):
"""
Expected time spent in park by an indiscriminate poacher
Parameters
----------
r: float between 0 and 1 - the proportion of horns devalued
tau: float - the time taken to kill a horn
N_r: int - number of devalued rhinos that correspond
to a single valued rhino
"""
return tau * (1 - r ** N_r) / (1 - r)
def gain(s=s, x=x, H=H, r=r, theta_r=theta_r, alpha=alpha):
"""
Return the total gain of the poachers based on their behaviour.
"""
return theta(r, s, theta_r) * H * theta(r, x, theta_r) ** (-alpha)
def cost(s=s, tau=tau, x=x, r=r, F=F, beta=beta, theta_r=theta_r):
N_r = sym.ceiling(1 / theta_r)
return (
F
* (1 - r) ** beta
* (
s * selective_time(r=r, tau=tau)
+ (1 - s) * indiscriminate_time(r=r, tau=tau, N_r=N_r)
)
)
def utility(
s=s, x=x, F=F, H=H, r=r, alpha=alpha, beta=beta, tau=tau, theta_r=theta_r,
Gamma=Gamma
):
"""
The total utility for a strategy
sigma=(s, 1-s) in a population chi=(x, 1-x)
"""
return gain(s=s, x=x, H=H, r=r, theta_r=theta_r, alpha=alpha) - cost(
s=s, tau=tau, x=x, r=r, F=F, beta=beta, theta_r=theta_r
) - (1 - s) * Gamma