-
Notifications
You must be signed in to change notification settings - Fork 0
/
cost_functions.py
59 lines (46 loc) · 1.93 KB
/
cost_functions.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
# FROM Andy:
# Current:
## Labour: £175.64 / hour
## Vehicle Running: £32.40 / hour
## Vehicle Daily: £8.99 / day
# Future (28% of current):
## Labour: £31.44 / hour
## Vehicle Running: £20.33 / hour
## Vehicle Daily: £8.99 / day
# Tipping Point (18.5% of current):
## Labour: £32.49 / hour
## Vehicle Running: £5.99 / hour
## Vehicle Daily: £1.66 / day
from bresenham import make_line
from config import get_variant, get_vpf, get_speed, get_resolution, VALUE_CAPITAL, PROB_LOSS_PER_FLT_HR
def fixed_vehicle_costs():
VARIANT = get_variant()
if VARIANT == 'current' or VARIANT == 'future':
return 8.99
elif VARIANT == 'tipping_point':
return 1.66
def marginal_vehicle_costs(seconds):
hrs = seconds / 3600
cvar_cost = VALUE_CAPITAL * PROB_LOSS_PER_FLT_HR * hrs
VARIANT = get_variant()
if VARIANT == 'current':
return ((32.44 + 175.64) * hrs) + cvar_cost
elif VARIANT == 'future':
return ((20.33 + (31.44/20)) * hrs) + cvar_cost
elif VARIANT == 'tipping_point':
return ((5.99 + (32.49/20)) * hrs) + cvar_cost
def marginal_vpf_costs(grid, current, neighbour):
VPF = get_vpf()
# Check if current and neighbour are adjacent including diagonals
if abs(current.x - neighbour.x) <= 1 and abs(current.y - neighbour.y) <= 1:
return grid[neighbour.y][neighbour.x] * VPF
else:
path = make_line(current.x, current.y, neighbour.x, neighbour.y)
return sum([grid[y][x] * VPF for y, x in path[1:]])
def total_marginal_costs(grid, current, neighbour):
MAP_RESOLUTION = get_resolution()
CRUISE_SPEED = get_speed()
# Get euclidean distance between current and neighbour
dist = ((current.x - neighbour.x) ** 2 + (current.y - neighbour.y) ** 2) ** 0.5
time_between = (dist * MAP_RESOLUTION) / CRUISE_SPEED
return marginal_vehicle_costs(time_between), marginal_vpf_costs(grid, current, neighbour)