Joakim Hansen
Joakim Hansen

Reputation: 59

How do I pass a list of tuples as the action space in OpenAI Gym?

When making an OpenAI Gym environment from scratch, an action space has to be defined. Which is done with their own "data structures" from the packet 'spaces'. There are several different types of spaces like Box, Discrete etc. I have a list of tuples I want to use as the action space instead. Is there a way to do this?

I could've potentially used spaces.Box(low=0, high=1, shape(4,12), dtype=np.int) , but this adds a lot of illegal actions. I'm open to solutions using for example spaces.Box and then ban/remove illegal actions, but preferably just insert my premade list of tuples.

Upvotes: 3

Views: 2872

Answers (1)

davidlrobinson
davidlrobinson

Reputation: 21

OpenAI Gym has a Tuple action space. Example usage:

from gym import spaces
action_space = spaces.Tuple((
        spaces.Discrete(9),
        spaces.Discrete(5)))

Upvotes: 1

Related Questions