This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
models.py
87 lines (80 loc) · 2.75 KB
/
models.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 torch
from torch import nn
import numpy as np
class CancelProbModel(nn.Module):
def __init__(self, hourfeat = 8):
super(CancelProbModel, self).__init__()
self.houremb = nn.Embedding(24, hourfeat)
self.fc = nn.Sequential(
nn.Linear(hourfeat + 6, 32),
nn.ReLU(),
nn.Linear(32, 10)
)
# startPos, endPos, hour, reward, ETA, prob
def forward(self, startPos, endPos, hour, reward, ETA):
startPos = startPos.float()
endPos = endPos.float()
hour = self.houremb(hour)
reward = reward.unsqueeze(1)
ETA = ETA.unsqueeze(1)
#print(startGID.shape, endGID.shape, hour.shape, week.shape)
x = torch.cat((startPos, endPos, hour, reward, ETA), dim = 1)
#print(x.shape)
x = self.fc(x)
#print(x.shape)
return x
class GridModel(nn.Module):
def __init__(self, hourfeat = 8):
super(GridModel, self).__init__()
self.houremb = nn.Embedding(24, hourfeat)
self.order = nn.Sequential(
nn.Linear(hourfeat + 2, 32),
nn.ReLU(),
nn.Linear(32, 1)
)
self.reward = nn.Sequential(
nn.Linear(hourfeat + 2, 32),
nn.ReLU(),
nn.Linear(32, 1)
)
def forward(self, GPS, hour):
GPS = GPS.float()
hour = self.houremb(hour)
#print(GID.shape, hour.shape, week.shape)
x = torch.cat((GPS, hour), dim = 1)
#print(x.shape)
return self.order(x).reshape(-1), self.reward(x).reshape(-1)
class DVNNet(nn.Module):
"""fetch value function
Args:
GIDnum: number of grids
GIDfeat: grid ID embedding feature number
hourfeat: hour embedding feature number
weekfeat: week embedding feature number
"""
def __init__(self, hourfeat = 8):
super(DVNNet, self).__init__()
self.houremb = nn.Embedding(24, hourfeat)
self.fc = nn.Sequential(
nn.Linear(hourfeat + 4, 32),
nn.ReLU(),
nn.Linear(32, 1)
)
"""
Args:
lat: driver position lat
lon: driver position lon
hour: now hour
average_reward: average reward in this grid
demand: expected demand in this grid
"""
def forward(self, lat, lon, hour, average_reward, demand):
#print(lat, lon, hour, average_reward, demand)
lat = lat.unsqueeze(1).float()
lon = lon.unsqueeze(1).float()
hour = self.houremb(hour)
average_reward = average_reward.float().unsqueeze(1)
demand = demand.float().unsqueeze(1)
x = torch.cat((lat, lon, hour, average_reward, demand), dim = 1)
#print(x.shape)
return self.fc(x).reshape(-1)