forked from prosysscience/JSSEnv
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5 unit test rendering + clean-up random test
- Loading branch information
Showing
3 changed files
with
32 additions
and
6 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import unittest | ||
|
||
import gym | ||
import imageio | ||
import numpy as np | ||
|
||
|
||
class TestRendering(unittest.TestCase): | ||
|
||
def test_random_mt10c1_rendering(self): | ||
env = gym.make('JSSEnv:flexible-jss-v1', env_config={'instance_path': '../../JSSEnv/envs/instances/flexible/mt10c1.fjs'}) | ||
env.reset() | ||
self.assertEqual(env.current_time_step, 0) | ||
done = False | ||
step_nb = 0 | ||
images = [] | ||
while not done: | ||
legal_actions = env.get_legal_actions() | ||
actions = np.random.choice(len(legal_actions), 1, p=(legal_actions / legal_actions.sum()))[0] | ||
state, reward, done, _ = env.step(actions) | ||
temp_image = env.render().to_image() | ||
images.append(imageio.imread(temp_image)) | ||
imageio.mimsave("mt10c1.gif", images) | ||
env.reset() | ||
self.assertEqual(env.current_time_step, 0) |