-
Notifications
You must be signed in to change notification settings - Fork 0
/
PI.py
57 lines (43 loc) · 1.26 KB
/
PI.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
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_toolkits.mplot3d import axes3d, Axes3D #<-- Note the capitalization!
from Driver import Driver
from Quad_Driver import QuadDriver
from NN_Driver import NN_driver
#CONSTANTS
SEED = 520
np.random.seed(SEED)
#number of parking spaces (without garage)
N = 10
myN = np.linspace(1,N,N,dtype=int)
# probability of space being free
x = np.linspace(0, 2*np.pi, N+1)
pf = 0.8
#print('Probability of every spot being free is:\n', pf)
#cost of every spot
c = (np.sin(x*2)+1)/2
c[N] = 2
print('Cost of every spot is:\n', c)
# space actually free or not. Here all spots are free
f = np.zeros(N,int)
f[pf>=0.3]=1
f[np.argmin(c)] = 1
print('Whether every spot is actually free or not:\n', f)
exact_driver = Driver(pf,f,c,N)
#learned_policy = exact_driver.policy_iter()
qdriver = QuadDriver(pf,f,c,N)
learned_policy = qdriver.policy_iter()
nndriver = NN_driver(pf,f,c,N)
#learned_policy = nndriver.policy_iter()
n = np.array([*myN,N+1])
nn = n[:-1]
cc = c[:-1]
# Plot the cost function
fig = plt.figure(1)
plt.plot(n,c)
plt.plot(nn[learned_policy=='park'],cc[learned_policy=='park'],'ro')
plt.title('Actual Cost function, chosen parking spot is red')
plt.xlabel('Parking Spots')
plt.ylabel('Cost')
plt.show()