Esempio n. 1
0
    def __init__(self, game_id, player_name, is_not_tcp):
        self.game_id = game_id
        self.player_name = player_name
        self.is_my_turn = False
        self.winner_status = GameWinnerStatus.NoWinner
        self.last_turn_illegal = False
        self.action_options = []
        self.winning_points_dim = np.zeros(shape=(9, 9), dtype=int)

        # join_game(self.game_id, self.player_name)

        if not is_not_tcp:
            self.tcp = TCP(game_id, player_name, self.on_recieved)
            self.wait_for_my_turn()

        self.action_space = spaces.Discrete(Global.num_of_actions)

        self.observation_space = spaces.Tuple((
            spaces.MultiBinary([9, 9]),
            spaces.MultiBinary([9, 9]),
            spaces.MultiBinary([9, 9]),
            spaces.MultiBinary([9, 9]),
            spaces.MultiBinary([9, 9])
        ))

        self.seed()
    def __init__(self, agent_ids):

        self.round = 0
        self.running = False
        self.agents = {}
        self.agents_last_obs = {}
        self.phase = 0
        self.observation_space = spaces.Tuple(
            (spaces.Box(low=0, high=1, shape=(15, 15, 9)),
             spaces.Box(low=0, high=1, shape=(4, )), spaces.MultiBinary(3),
             spaces.Box(low=0, high=1, shape=(1, )),
             spaces.MultiBinary(len(self.available_actions))))
        # spaces.Dict({'walls': spaces.MultiBinary(tiles),
        # 'free': spaces.MultiBinary(tiles),
        # 'crates': spaces.MultiBinary(tiles),
        # 'player': spaces.MultiBinary(tiles),
        # 'opponents': spaces.MultiBinary(tiles),
        # 'coins': spaces.MultiBinary(tiles),
        # 'bombs': spaces.Box(low=0, high=4, shape=(17, 17)),
        # 'explosions': spaces.Box(low=0, high=2, shape=(17, 17)),
        # 'scores' : spaces.Box(low=0, high=1, shape=(4,)),
        # 'current_round': spaces.Box(low=0, high=1, shape=(1,))
        # })
        # spaces.Box(low=0, high=4, shape=(17,17,8))
        self.action_space = spaces.Discrete(6)
        for i in agent_ids:
            #agent_id = f'agent_{i}'  # _{uuid.uuid1()}'
            self.agents[i] = Agent(i)
        self.new_round()
 def __init__(self, n_bits=10, continuous=False, max_steps=None):
     super(BitFlippingEnv, self).__init__()
     # The achieved goal is determined by the current state
     # here, it is a special where they are equal
     self.observation_space = spaces.Dict({
         'observation':
         spaces.MultiBinary(n_bits),
         'achieved_goal':
         spaces.MultiBinary(n_bits),
         'desired_goal':
         spaces.MultiBinary(n_bits)
     })
     if continuous:
         self.action_space = spaces.Box(-1,
                                        1,
                                        shape=(n_bits, ),
                                        dtype=np.float32)
     else:
         self.action_space = spaces.Discrete(n_bits)
     self.continuous = continuous
     self.state = None
     self.desired_goal = np.ones((n_bits, ))
     if max_steps is None:
         max_steps = n_bits
     self.max_steps = max_steps
     self.current_step = 0
     self.reset()
Esempio n. 4
0
    def __init__(self, text, *, seed=None, goal: int = None):
        model = parse(text)
        self.seed(seed)

        if model.values == 'cost':
            raise ValueError('Unsupported `cost` values.')

        self.model = model
        self.discount = model.discount
        self.state_space = spaces.MultiBinary(len(model.states))
        self.action_space = spaces.Discrete(len(model.actions))
        self.observation_space = observation = spaces.MultiBinary(
            len(self.model.states))
        self.goal = None
        self.reward_range = model.R.min(), model.R.max()

        self.rewards_dict = {r: i for i, r in enumerate(np.unique(model.R))}

        if model.start is None:
            self.start = np.full(self.state_space.n, 1 / self.state_space.n)
        else:
            self.start = model.start
        self.T = model.T.transpose(1, 0, 2).copy()

        # self.R = model.R.transpose(1, 0, 2, 3).copy()
        self.R = model.R.transpose(1, 0, 2).copy()
        if goal is None:
            raise NotImplementedError("Need a goal")
        self.goal = np.zeros(len(self.model.states))
        self.goal[goal] = 1

        #self.state = -1
        self.state = np.zeros(len(model.states), dtype=np.int)
Esempio n. 5
0
    def __init__(self):
        # There shall be two teams to begin with
        self.nbTeamMembers = 5
        self.observation_size = 7
        # This is what the agents will be allowed to see each turn --> The observation space
        # Documentation hardly exists,
        # from reading the code I'll just align binary, event if that seems like a sub-optimal solution
        # self.observation_space = spaces.Box(
        #     low=0,
        #     high=1,
        #     # //!!\\ Temporary fix :
        #     # openAI baselines don't like multi dimensional input spaces so we're attempting 1d which will be hell to interpret.
        #     # should revert asap
        #     shape=(
        #         self.observation_size
        #         * self.observation_size
        #         * self.nbTeamMembers
        #         * 2
        #         * 4,
        #     ),
        #     dtype=np.int64,
        # )

        self.observation_space = spaces.MultiBinary(self.observation_size *
                                                    self.observation_size *
                                                    self.nbTeamMembers * 2 * 4)

        # self.action_space = spaces.Box(
        #     low=0, high=1, shape=(2 * self.nbTeamMembers * 5,), dtype=np.int64
        # )
        self.action_space = spaces.MultiBinary(2 * self.nbTeamMembers * 5)

        self.np_random = None
        self.seed()
        self.reset()
Esempio n. 6
0
 def __init__(
         self,
         size,
         max_episode_length,
         name,
         uav_observation_noise=0.3,
         target_observation_noise=0.5,
         listen_noise_reduction=0.1,
         reward_scale=1.):
     self.n = 2
     self._grid_size = size
     self.max_episode_length = max_episode_length
     self.agents = [UAVAgent(i, i == 0) for i in range(self.n)]
     self.t = 0
     self.reward_range = reward_scale
     self.num_targets = 1
     self.random = np.random.RandomState()
     self._locations = [(None, None), (None, None)]
     # The target may move to any adjacent or diagonally adjacent location or stay still.
     # The UAV may move in any cardinal direction {N, E, S, W} or stay still and listen.
     self.action_space = [
         spaces.Discrete(9), spaces.Discrete(5)
     ]
     self.observation_space = [
         spaces.MultiBinary(2 * np.sum(size)),
         spaces.MultiBinary(2 * np.sum(size))
     ]
     self.observation_noise = [
         target_observation_noise, uav_observation_noise
     ]
     self._listen_noise_red = listen_noise_reduction
     self.name = name
    def __init__(self, user_params=None):
        """Initializes the College Admissions environment with initial params.

    Args:
      user_params: Dict. Any params not passed will take default values in
        Params.
    Raise:
      ValueError: If provided params not as expected.
    """
        # TODO(): make parameter handling consistent across environments.
        # Called env_params unlike in other environments because this environment
        # incorporates params with the default to get the comprehensive environment
        # params.
        env_params = Params()
        if user_params is not None:
            env_params = Params(**user_params)
        # The jury's action is a dict containing the threshold which specifies a 1D
        # threshold on scores above which applicants will be admitted and an epsilon
        # probability value, which specifies the probability value for an
        # epsilon greedy agent and is 0 by default.
        self.action_space = spaces.Dict({
            "threshold":
            spaces.Box(
                low=env_params.score_params.min,
                high=env_params.score_params.max,
                dtype=np.float32,
                shape=(),
            ),
            "epsilon_prob":
            spaces.Box(low=0, high=1, dtype=np.float32, shape=()),
        })  # type: spaces.Space

        # The observations include test scores, [0, 1], eligibility of selected
        # applicants, ground truth for selected candidates and applicant group ids.
        self.observable_state_vars = {
            "test_scores_y":
            spaces.Box(
                low=env_params.score_params.min,
                high=env_params.score_params.max,
                dtype=np.float32,
                shape=(env_params.num_applicants, ),
            ),
            "selected_applicants":
            spaces.MultiBinary(env_params.num_applicants),
            "selected_ground_truth":
            spaces.MultiDiscrete([3] * env_params.num_applicants),
            "applicant_groups":
            spaces.MultiBinary(env_params.num_applicants),
        }  # type: Dict[Text, spaces.Space]
        super(CollegeAdmissionsEnv, self).__init__(env_params)
        if env_params.gaming_control != np.inf and (
                env_params.gaming_control > 1
                or env_params.gaming_control < 0):
            raise ValueError("Gaming control needs to be in [0, 1]")

        if env_params.noise_dist not in ["gaussian", "beta"]:
            raise ValueError("Undefined noise distribution.")
        self._state_init()
Esempio n. 8
0
 def __init__(self, bits):
     self.action_space = spaces.Discrete(bits)
     self.max_steps = bits
     self.observation_space = spaces.MultiBinary(bits)
     self.goal_space = spaces.MultiBinary(bits)
     self.bits = bits
     self.state = torch.zeros((self.bits, ))
     self.goal = torch.zeros((self.bits, ))
     self.reset()
 def get_space():
     from gym import spaces
     return spaces.Dict(
         dict(UI=spaces.Box(low=0,
                            high=1,
                            dtype=np.float,
                            shape=(SCREEN_H, SCREEN_W, 3)),
              permissions=spaces.MultiBinary(len(INTERESTED_PERMISSIONS)),
              receivers=spaces.MultiBinary(len(INTERESTED_BROADCASTS)),
              APIs=spaces.MultiBinary(len(INTERESTED_APIS))))
Esempio n. 10
0
 def observation_space(self) -> spaces.Dict:
     if self._observation_space is None:
         self._observation_space = spaces.Dict([
             ('occupied', spaces.MultiBinary(28)),
             ('player_owned', spaces.MultiBinary(28)),
             ('piece_type', spaces.MultiDiscrete([3] * 28)),
             ('player_captures', spaces.MultiDiscrete([3, 3, 3])),
             ('opponent_captures', spaces.MultiDiscrete([3, 3, 3])),
         ])
     return self._observation_space
Esempio n. 11
0
def test_bernoulli_kl():
    """ distribution test """
    logits_0 = torch.from_numpy(np.random.randn(100, 8, 5))
    logits_1 = torch.from_numpy(np.random.randn(100, 8, 5))

    dist_0 = BernoulliProbabilityDistribution(
        logits=logits_0, action_space=spaces.MultiBinary(5))
    dist_1 = BernoulliProbabilityDistribution(
        logits=logits_1, action_space=spaces.MultiBinary(5))

    assert dist_0.kl(dist_1).numpy().ndim == 2
    assert dist_0.kl(dist_1).numpy().shape == (100, 8)
Esempio n. 12
0
 def __init__(self, n_bits=8):
     self.n_actions = n_bits
     self.action_space = spaces.Discrete(n_bits)
     self.d_observations = n_bits
     self.d_goals = n_bits
     self.observation_space = spaces.Dict({
         "observation":
         spaces.MultiBinary(n_bits),
         "desired_goal":
         spaces.MultiBinary(n_bits),
         "achieved_goal":
         spaces.MultiBinary(n_bits),
     })
     self.max_episode_steps = n_bits
Esempio n. 13
0
 def _observationSpace(self):
     #### Observation vector ### X        Y        Z       Q1   Q2   Q3   Q4   R       P       Y       VX       VY       VZ       WR       WP       WY       P0            P1            P2            P3
     obs_lower_bound = np.array([-np.inf, -np.inf, 0.,     -1., -1., -1., -1., -np.pi, -np.pi, -np.pi, -np.inf, -np.inf, -np.inf, -np.inf, -np.inf, -np.inf, 0.,           0.,           0.,           0.])
     obs_upper_bound = np.array([np.inf,  np.inf,  np.inf, 1.,  1.,  1.,  1.,  np.pi,  np.pi,  np.pi,  np.inf,  np.inf,  np.inf,  np.inf,  np.inf,  np.inf,  self.MAX_RPM, self.MAX_RPM, self.MAX_RPM, self.MAX_RPM])
     return spaces.Dict({str(i): spaces.Dict({"state": spaces.Box(low=obs_lower_bound,
                                                                  high=obs_upper_bound,
                                                                  dtype=np.float32
                                                                  ),
                                              "neighbors": spaces.MultiBinary(self.NUM_DRONES),
                                              "rgb": spaces.Box(low=0,
                                                                high=255,
                                                                shape=(self.IMG_RES[1], self.IMG_RES[0], 4),
                                                                dtype=np.uint8
                                                                ),
                                              "dep": spaces.Box(low=.01,
                                                                high=1000.,
                                                                shape=(self.IMG_RES[1],
                                                                 self.IMG_RES[0]),
                                                                dtype=np.float32
                                                                ),
                                              "seg": spaces.Box(low=0,
                                                                high=100,
                                                                shape=(self.IMG_RES[1],
                                                                self.IMG_RES[0]),
                                                                dtype=np.int
                                                                )
                                              }) for i in range(self.NUM_DRONES)})
Esempio n. 14
0
 def action_space(self):
     action_space = copy.deepcopy(self.state_space)
     action_space["gripper_force"] = spaces.Box(low=0,
                                                high=self.MAX_FORCES,
                                                shape=(1, ))
     action_space["wait"] = spaces.MultiBinary(n=1)
     return action_space
Esempio n. 15
0
    def observation_space(self):
        """
        Return observation space in gym box
        :return:
        """

        obs = dict(
            # number of days passed
            day=spaces.Discrete(self.max_days),
            # idx is agent id_, value is boll for agent alive
            status_map=spaces.MultiBinary(self.num_players),
            # number in range number of phases [com night, night, com day, day]
            phase=spaces.Discrete(4),
            # targets is now a vector, having an element outputted from each agent
            targets=gym.spaces.Box(low=-1,
                                   high=self.num_players,
                                   shape=(self.num_players, ),
                                   dtype=np.int32),
            # own id
            own_id=gym.spaces.Discrete(self.num_players),
        )

        # add signal if the required
        if self.signal_length > 0:
            # signal is a matrix of dimension [num_player, signal_range]
            signal = dict(signal=gym.spaces.Box(low=-1,
                                                high=self.signal_range - 1,
                                                shape=(self.num_players,
                                                       self.signal_length),
                                                dtype=np.int32))
            obs.update(signal)

        obs = gym.spaces.Dict(obs)

        return obs
Esempio n. 16
0
 def __init__(self,n=10,space_seed=0):
     self.n=n        
     self.action_space = spaces.Discrete(self.n +1) #there is an option NOT to flip any bit( index = n)
     self.observation_space = spaces.MultiBinary(self.n)
     self.state_space = spaces.MultiBinary(self.n)
     self.reward_range = (-1,0)
     spaces.seed(space_seed)
     self.space_seed = space_seed
     self.initial_state = self.sample_state()
     self.goal = self.sample_state()
     self.state = self.initial_state
     self.envstepcount = 0
     self.seed()
     self.reward_max = -np.sum(np.bitwise_xor(self.initial_state,self.goal))+1
     if(np.array_equal(self.goal,self.initial_state)):
          self.reward_max = 0
Esempio n. 17
0
    def __init__(self, config):
        """
        Args:
            puzzle_name: Name of the puzzle to run.
                Choices: "zigzag", "cross", "monolith", "stairs"
        """
        self.config = config
        self.board = puzzles.maps[config.puzzle_name]
        self.map = self.board["map"]
        self.extract_map_features()

        self.action_space = spaces.Discrete(5)
        self.raw_observation_space = spaces.Dict({
            "coords":
            spaces.Tuple((
                spaces.Discrete(self.board_size[1]),
                spaces.Discrete(self.board_size[0]),
            )),
            "height":
            spaces.Discrete(self.max_height),
            "direction":
            spaces.Discrete(4),
            "light_idx":
            spaces.Discrete(self.num_lights),
            "lights_on":
            spaces.MultiBinary(self.num_lights),
        })

        # Seed is not needed because the environment is deterministic
        self.set_reward_fn(*[float(x) for x in config.reward_fn.split(",")])
        self.state = self.reset()
Esempio n. 18
0
    def __init__(self, *args, **kwargs):
        super(TestConverters, self).__init__(*args, **kwargs)
        self.space_d = spaces.Discrete(4)
        self.gym_out_d = 2
        self.rf_out_d = [0, 0, 1, 0]

        self.space_c = spaces.Box(-1, 1, [2, 4])
        self.gym_out_c = np.random.uniform(low=-1, high=1, size=(2, 4))
        self.rf_out_c = self.gym_out_c

        self.space_b = spaces.MultiBinary(4)
        self.gym_out_b = [0, 1, 0, 1]
        self.rf_out_b = [[1, 0], [0, 1], [1, 0], [0, 1]]

        self.space_t = spaces.Tuple((self.space_d, self.space_c, self.space_b,
                                     spaces.Tuple(
                                         (self.space_d, self.space_c))))
        self.gym_out_t = tuple([
            self.gym_out_d, self.gym_out_c, self.gym_out_b,
            tuple([self.gym_out_d, self.gym_out_c])
        ])
        self.rf_out_t = tuple([
            self.rf_out_d, self.rf_out_c, self.rf_out_b,
            tuple([self.rf_out_d, self.rf_out_c])
        ])
Esempio n. 19
0
    def __init__(self, params=None):
        params = (self.default_param_builder() if params is None else params
                  )  # type: lending_params.Params

        # The action space of the agent is Accept/Reject.
        self.action_space = spaces.Discrete(2)

        # Bank's cash is a scalar and cannot be negative.
        bank_cash_space = spaces.Box(low=0,
                                     high=params.max_cash,
                                     shape=(),
                                     dtype=np.float32)

        # Two-dimensional observation space describes each loan applicant.
        loan_applicant_space = spaces.Box(
            params.min_observation,
            params.max_observation,
            dtype=np.float32,
            shape=(params.applicant_distribution.dim, ))

        group_space = spaces.MultiBinary(params.num_groups)

        self.observable_state_vars = {
            'bank_cash': bank_cash_space,
            'applicant_features': loan_applicant_space,
            'group': group_space
        }

        super(BaseLendingEnv, self).__init__(params)
        self._state_init()
Esempio n. 20
0
    def __init__(self, venv: VecEnv):
        super(ObsDictWrapper, self).__init__(venv, venv.observation_space, venv.action_space)

        self.venv = venv

        self.spaces = list(venv.observation_space.spaces.values())

        # get dimensions of observation and goal
        if isinstance(self.spaces[0], spaces.Discrete):
            self.obs_dim = 1
            self.goal_dim = 1
        else:
            self.obs_dim = venv.observation_space.spaces["observation"].shape[0]
            self.goal_dim = venv.observation_space.spaces["achieved_goal"].shape[0]

        # new observation space with concatenated observation and (desired) goal
        # for the different types of spaces
        if isinstance(self.spaces[0], spaces.Box):
            low_values = np.concatenate(
                [venv.observation_space.spaces["observation"].low, venv.observation_space.spaces["desired_goal"].low]
            )
            high_values = np.concatenate(
                [venv.observation_space.spaces["observation"].high, venv.observation_space.spaces["desired_goal"].high]
            )
            self.observation_space = spaces.Box(low_values, high_values, dtype=np.float32)
        elif isinstance(self.spaces[0], spaces.MultiBinary):
            total_dim = self.obs_dim + self.goal_dim
            self.observation_space = spaces.MultiBinary(total_dim)
        elif isinstance(self.spaces[0], spaces.Discrete):
            dimensions = [venv.observation_space.spaces["observation"].n, venv.observation_space.spaces["desired_goal"].n]
            self.observation_space = spaces.MultiDiscrete(dimensions)
        else:
            raise NotImplementedError(f"{type(self.spaces[0])} space is not supported")
Esempio n. 21
0
    def __init__(self):

        DATAPATH = os.path.abspath("/home/pycrysfml/hklgen/examples/sxtal")
        observedFile = os.path.join(DATAPATH, r"prnio.int")
        infoFile = os.path.join(DATAPATH, r"prnio.cfl")

        #Read data
        self.spaceGroup, self.crystalCell, self.atomList = H.readInfo(infoFile)

        #Return wavelength, refList, sfs2, error, two-theta, and four-circle parameters
        wavelength, refList, sfs2, error = S.readIntFile(observedFile,
                                                         kind="int",
                                                         cell=self.crystalCell)
        self.wavelength = wavelength
        self.refList = refList
        self.sfs2 = sfs2
        self.error = error
        self.tt = [
            H.twoTheta(H.calcS(self.crystalCell, ref.hkl), wavelength)
            for ref in refList
        ]
        self.backg = None
        self.exclusions = []

        self.observation_space = spaces.MultiBinary(len(self.refList))
        self.action_space = spaces.Discrete(len(self.refList))

        self.episodeNum = 0
        self.reset()
Esempio n. 22
0
 def __init__(self, level):
     self.previous_level = -1
     self.level = level
     self.game = DoomGame()
     self.loader = Loader()
     self.doom_dir = os.path.dirname(os.path.abspath(__file__))
     self._mode = 'algo'  # 'algo' or 'human'
     self.no_render = False  # To disable double rendering in human mode
     self.viewer = None
     self.is_initialized = False  # Indicates that reset() has been called
     self.curr_seed = 0
     self.lock = (DoomLock()).get_lock()
     # self.action_space = spaces.Discrete(43)   # used to be in the old code
     self.action_space = spaces.MultiBinary(NUM_ACTIONS)
     self.allowed_actions = list(range(NUM_ACTIONS))
     self.screen_height = 120
     self.screen_width = 160
     self.screen_resolution = ScreenResolution.RES_160X120
     self.observation_space = spaces.Box(low=0,
                                         high=255,
                                         shape=(self.screen_height,
                                                self.screen_width, 3),
                                         dtype=np.uint8)
     self.seed()
     self._configure()
Esempio n. 23
0
    def __init__(self, size=15):
        self.n_squares_height = size
        self.n_squares_width = size

        self.OBJECT_TO_IDX = {
            'goal': 1,
            'wall': 2,
            'other_agents': 3,
            'my_agent': 4
        }

        self.action_space = spaces.Discrete(4)
        self.observation_space = spaces.MultiBinary(
            (len(self.OBJECT_TO_IDX), self.n_squares_height,
             self.n_squares_width))

        self.seed()
        self.viewer = None
        self.state = None

        self.steps_beyond_done = None

        self.players = []
        self.players_in_game = []
        self.agent_cols = []
Esempio n. 24
0
    def get_spaces(self, n_historical_events):
        observation_space = spaces.MultiBinary(self.n_experts +
                                               2 * n_historical_events)

        action_space = spaces.Discrete(4)

        return observation_space, action_space
Esempio n. 25
0
 def make_observation_space(self, obs_sample):
     """ make per agent observation space from a given sample 
         compatible with original mpe and mpe_hierarchy
     """
     if isinstance(obs_sample, np.ndarray):
         # for original mpe
         obs_dim = len(obs_sample)
         obs_space = spaces.Box(low=-np.inf,
                                high=+np.inf,
                                shape=(obs_dim, ),
                                dtype=np.float32)
     elif isinstance(obs_sample, dict):
         # for mpe_hierarchy
         obs_space = {}
         for k, v in obs_sample.items():
             if k == "masks":
                 n = len(v)
                 space = spaces.MultiBinary(n)
             elif k == "states":
                 assert len(v) > 0
                 n, state_dim = len(v), len(v[0])
                 space = spaces.Tuple((spaces.Box(low=-np.inf,
                                                  high=+np.inf,
                                                  shape=(state_dim, ),
                                                  dtype=np.float32)
                                       for _ in range(n)))
             obs_space[k] = space
         obs_space = spaces.Dict(spaces=obs_space)
     else:
         # default to an empty obs space
         obs_sapce = spaces.Box(low=-np.inf,
                                high=+np.inf,
                                shape=(1, ),
                                dtype=np.float32)
     return obs_space
Esempio n. 26
0
    def _observationSpace(self):
        """Returns the observation space of the environment.

        Returns
        -------
        dict[str, dict[str, ndarray]]
            A Dict with NUM_DRONES entries indexed by Id in string format,
            each a Dict in the form {Box(20,), MultiBinary(NUM_DRONES)}.

        """
        #### Observation vector ### X        Y        Z       Q1   Q2   Q3   Q4   R       P       Y       VX       VY       VZ       WX       WY       WZ       P0            P1            P2            P3
        obs_lower_bound = np.array([
            -np.inf, -np.inf, 0., -1., -1., -1., -1., -np.pi, -np.pi, -np.pi,
            -np.inf, -np.inf, -np.inf, -np.inf, -np.inf, -np.inf, 0., 0., 0.,
            0.
        ])
        obs_upper_bound = np.array([
            np.inf, np.inf, np.inf, 1., 1., 1., 1., np.pi, np.pi, np.pi,
            np.inf, np.inf, np.inf, np.inf, np.inf, np.inf, self.MAX_RPM,
            self.MAX_RPM, self.MAX_RPM, self.MAX_RPM
        ])
        return spaces.Dict({
            str(i): spaces.Dict({
                "state":
                spaces.Box(low=obs_lower_bound,
                           high=obs_upper_bound,
                           dtype=np.float32),
                "neighbors":
                spaces.MultiBinary(self.NUM_DRONES)
            })
            for i in range(self.NUM_DRONES)
        })
Esempio n. 27
0
    def __init__(self, shape=(22, 10), possible_bricks=bricks.BRICKS):
        self.shape = shape
        self.height = shape[0]
        self.width = shape[1]

        self.bricks = possible_bricks
        self.n_bricks = len(self.bricks)
        self.brick_probabilities = [1. / self.n_bricks for b in self.bricks]
        self.brick_height = [b.shape.shape[0] for b in self.bricks]
        self.brick_vpad = [
            max(self.brick_height) - h for h in self.brick_height
        ]
        self.max_brick_dim = max(max(b.shape.shape) for b in self.bricks)

        self.board_space = spaces.MultiBinary(self.shape)
        self.brick_space = spaces.Discrete(self.n_bricks)

        self.observation_space = spaces.Tuple(
            (self.board_space, self.brick_space))
        self.dtype = self.board_space.sample().dtype
        self.seed()

        # Start the first game
        self.reset()
        self._action_space = None
Esempio n. 28
0
    def __init__(self, agent_conf, name, max_allowed_power):
        # action space specify which transition can be activated
        self.action_space = spaces.Discrete(
            len(EFLEXEnergyGeneratorAgentTransition))  # {0,1,...,n-1}

        # observation is a multi discrete specifying which state is activated
        self.observation_space = spaces.MultiBinary(
            len(EFLEXEnergyGeneratorAgentState) + 1)

        # reward_range
        self.reward_range = (float(-1.0), float(1.0))

        # Simulation related variables.
        self.p_min = agent_conf['p_min']
        self.p_max = agent_conf['p_max']
        self.p_slope = agent_conf['p_slope']
        self.name = name
        self.current_state = None
        self.np_random = None
        self.current_reward = 0.0
        self.obs = None
        self.obs_pre = None
        self.max_allowed_power = max_allowed_power

        self.seed()
        self.reset()

        # Just need to initialize the relevant attributes
        self._configure()
        self.startStep = 0
        self.currentStep = 0
        self.last_power = 0
Esempio n. 29
0
    def __init__(self, width=4, height=4, object_coordinates=None):
        self.n_squares_height = width
        self.n_squares_width = height

        self.OBJECT_TO_IDX = {  # objects will be coded by a 1 in the positions they occupy, and a 0 if absent, except for the arrows
            'goal': 0,
            'void': 1,
            'agent': 2,
            'coin': 3,
            'thorns': 4,
            'arrow': 5  # arrows will be represented by 0 if absent, 
            # and one of [1,2,3,4] representing the direction in which to push the agent
        }

        self.action_space = spaces.Discrete(4)
        self.observation_space = spaces.MultiBinary(
            (len(self.OBJECT_TO_IDX), self.n_squares_height,
             self.n_squares_width))

        self.seed()
        self.viewer = None
        self.state = None
        self.has_been_reset_before = False
        self.moved_into_wall = False
        self.done = False

        self.n_steps = None
        self.steps_beyond_done = None

        if object_coordinates is not None:
            self.setup(object_coordinates)
Esempio n. 30
0
def car():
    return SpaceDict({
        "sensors":
        SpaceDict({
            "position":
            spaces.Box(low=-100, high=100, shape=(3, )),
            "velocity":
            spaces.Box(low=-1, high=1, shape=(3, )),
            "front_cam":
            spaces.Tuple((
                spaces.Box(low=0, high=1, shape=(10, 10, 3)),
                spaces.Box(low=0, high=1, shape=(10, 10, 3)),
            )),
            "rear_cam":
            spaces.Box(low=0, high=1, shape=(10, 10, 3)),
        }),
        "ext_controller":
        spaces.MultiDiscrete((5, 2, 2)),
        "inner_state": {
            "charge":
            spaces.Discrete(100),
            "system_checks":
            spaces.MultiBinary(10),
            "job_status":
            SpaceDict({
                "task": spaces.Discrete(5),
                "progress": spaces.Box(low=0, high=100, shape=()),
            }),
        },
    })