forked from nathangrinsztajn/DAG-scheduling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuman_playing_commandline.py
82 lines (66 loc) · 2.39 KB
/
human_playing_commandline.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
import torch
from env import CholeskyTaskGraph
import networkx as nx
from torch_geometric.utils.convert import to_networkx
import pydot
import matplotlib.pyplot as plt
from networkx.drawing.nx_pydot import graphviz_layout
import numpy as np
env = CholeskyTaskGraph(8, 4, 1)
def print_available_actions(available_actions_list):
"""
Prints all available actions nicely formatted..
:return:
"""
display_actions = '\n'.join(available_actions_list)
print()
print('Action out of Range!')
print('Available Actions:\n{}'.format(display_actions))
print()
for i_episode in range(1):
print('Starting new game!')
observation = env.reset()
available_actions = env.ready_tasks
t = 0
while True:
t += 1
env.render()
print('Available tasks: ', env.ready_tasks + [-1])
action = input('Select action: ')
try:
action = int(action)
if not action in env.ready_tasks + [-1]:
raise ValueError
except ValueError:
print_available_actions(env.ready_tasks + [-1])
continue
observation, reward, done, info = env.step(action, render_before=True)
# if save_images:
# # img = Image.fromarray(env.render(mode="return"), 'RGB')
# # img.save(os.path.join('images', 'observation_{}_{}.png'.format(i_episode, t)))
# img = env.render(mode="return")
# fig = plt.imshow(img, vmin=0, vmax=255, interpolation='none')
# fig.axes.get_xaxis().set_visible(False)
# fig.axes.get_yaxis().set_visible(False)
# plt.savefig(os.path.join('images', 'observation_{}_{}.png'.format(i_episode, t)))
if done:
print("Episode finished after {} timesteps".format(t+1))
env.render()
break
# if generate_gifs:
# print('')
# import imageio
#
# with imageio.get_writer(os.path.join('images', 'round_{}.gif'.format(i_episode)), mode='I', fps=1) as writer:
#
# for t in range(n_steps):
# try:
#
# filename = os.path.join('images', 'observation_{}_{}.png'.format(i_episode, t))
# image = imageio.imread(filename)
# writer.append_data(image)
#
# except:
# pass
env.close()
time.sleep(10)