-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
73 lines (55 loc) · 1.7 KB
/
test.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
import gym
from gym import error, spaces, utils
from gym.utils import seeding
import numpy as np
import stable_baselines3
from stable_baselines3 import PPO
from stable_baselines3.common.evaluation import evaluate_policy
from RH_PPO import *
import RideHailing
from RideHailing.envs import *
from RideHailing.envs.RideHailing_env import *
env = gym.make('RideHailing-v0', config=CONFIG)
# env = gym.make('CartPole-v1')
#print(env.state)
#print(env.action_space)
#print(env.observation_space) # openAI calles states observations :/
#print(env.action_space.sample())
#env.reset()
#tot_reward = 0
def evaluate(model, env, numiters):
tot_reward_l = []
for i in range(numiters):
print('iteration'+str(i))
env.reset()
tot_reward = 0
episode_over = False
while (episode_over != True):
_, reward, episode_over, _ = env.step(model(env.state))
tot_reward += reward
tot_reward_l.append(tot_reward)
l = np.asarray(tot_reward_l)
return (np.mean(l), np.std(l))
def random_model(state):
# TODO: do not hardcode
action = [state['origin'], np.random.randint(5)]
return action
env = gym.make('RideHailing-v0', config=CONFIG)
# # why is the environment not resetting correctly????
# # import pdb; pdb.set_trace()
# result = evaluate(random_model, env, 1000)
# print(result)
# print(CONFIG)
run_PPO(env)
# import pdb; pdb.set_trace()
# model.learn(total_timesteps=10000)
# model = evalua("MlpPolicy", env, verbose=1)
#result = evaluate(random_model, env, 1000)
#print(result)
#np.random.seed(0)
#cl = RideHailingEnv(CONFIG)
#for i in range(5):
# for j in range(5):
# print('State: {}'.format(cl.step([i, j])))
#
#print('FINISHED')