Skip to content

Commit

Permalink
- defined used action as self varaible
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Weber committed Apr 16, 2021
1 parent 5cddd00 commit 962a964
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions openmodelica_microgrid_gym/env/modelica.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def __init__(self, net: Union[str, Network], time_start: float = 0,
self.action_space = gym.spaces.Box(low=np.full(d_i, -1), high=np.full(d_i, 1))
self.observation_space = gym.spaces.Box(low=np.full(d_o, -np.inf), high=np.full(d_o, np.inf))

self.used_action = np.zeros(self.action_space.shape)
self.action_time_delay = action_time_delay
if self.action_time_delay == 0:
self.delay_buffer = None
Expand Down Expand Up @@ -279,6 +280,7 @@ def reset(self) -> np.ndarray:
self.history.reset()
self._failed = False
self._register_render = False
self.used_action = np.zeros(self.action_space.shape)
if self.delay_buffer is not None:
self.delay_buffer.clear()
outputs = self._create_state(is_init=True)
Expand Down Expand Up @@ -320,20 +322,20 @@ def step(self, action: Sequence) -> Tuple[np.ndarray, float, bool, Mapping]:

# enqueue action and get delayed/last action
if self.delay_buffer is not None:
delayed_action = self.delay_buffer.shift(action)
self.used_action = self.delay_buffer.shift(action)
else:
delayed_action = action
self.used_action = action

# Set input values of the model
logger.debug('model input: %s, values: %s', self.model_input_names, delayed_action)
self.model.set(**dict(zip(self.model_input_names, delayed_action)))
logger.debug('model input: %s, values: %s', self.model_input_names, self.used_action)
self.model.set(**dict(zip(self.model_input_names, self.used_action)))

if self.model_parameters:
values = {var: f(self.sim_time_interval[0]) for var, f in self.model_parameters.items()}
else:
values = {}

params = {**values, **self.net.params(delayed_action)}
params = {**values, **self.net.params(self.used_action)}
# delete None values to make model initialization possible (take care in model_params definition!)
params = {k: v for k, v in params.items() if v is not None}
if params:
Expand Down

0 comments on commit 962a964

Please sign in to comment.