Sample action from an action space for given state
198807
def step(self, observations):
        
        q_values = self(observations)

        return {
            'actions': self.q_head.sample(q_values),
            'q': q_values
        }
573233
def act( self ):
        ''''''
        if self.action_set == 'discrete_absolute':
            actions = ['movenorth 1', 'movesouth 1', 'movewest 1', 'moveeast 1']
        elif self.action_set == 'discrete_relative':
            actions = ['move 1', 'move -1', 'turn 1', 'turn -1']
        elif self.action_set == 'teleport':
            while True:
                dx = random.randint(-10,10)
                dz = random.randint(-10,10)
                if not dx == 0 or not dz == 0:
                    break
            self.expected_x = self.prev_x + dx
            self.expected_y = self.prev_y
            self.expected_z = self.prev_z + dz
            self.expected_yaw = self.prev_yaw
            self.require_move = True
            self.require_yaw_change = False
            actions = ['tp '+str(self.expected_x)+' '+str(self.expected_y)+' '+str(self.expected_z)]
        else:
            print('ERROR: Unsupported action set:',self.action_set)
            exit(1)
        i_action = random.randint(0,len(actions)-1)
        action = actions[ i_action ]
        print('Sending',action)
        self.agent_host.sendCommand( action )
        if self.action_set == 'discrete_absolute':
            self.expected_x = self.prev_x + [0,0,-1,1][i_action]
            self.expected_y = self.prev_y
            self.expected_z = self.prev_z + [-1,1,0,0][i_action]
            self.expected_yaw = self.prev_yaw
            self.require_move = True
            self.require_yaw_change = False
        elif self.action_set == 'discrete_relative':
            if i_action == 0 or i_action == 1:
                i_yaw = indexOfClosest( [0,90,180,270], self.prev_yaw )
                forward = [ (0,1), (-1,0), (0,-1), (1,0) ][ i_yaw ]
                if i_action == 0:
                    self.expected_x = self.prev_x + forward[0]
                    self.expected_z = self.prev_z + forward[1]
                else:
                    self.expected_x = self.prev_x - forward[0]
                    self.expected_z = self.prev_z - forward[1]
                self.expected_y = self.prev_y
                self.expected_yaw = self.prev_yaw
                self.require_move = True
                self.require_yaw_change = False
            else:
                self.expected_x = self.prev_x
                self.expected_y = self.prev_y
                self.expected_z = self.prev_z
                self.expected_yaw = math.fmod( 360 + self.prev_yaw + [90,-90][i_action-2], 360 )
                self.require_move = False
                self.require_yaw_change = True
        elif self.action_set == 'teleport':
            pass
        else:
            print('ERROR: Unsupported action set:',self.action_set)
            exit(1)
493209
function (state, action) {
    if (state) {
      let initialValue = state.value || {}
      if (state.baseModel) {
        initialValue = recursiveClean(initialValue, state.baseModel)
        state.baseModel = getDereferencedModelSchema(state.baseModel)
        state.model = evaluateConditions(state.baseModel, initialValue, undefined, initialValue)
        // leave this undefined to force consumers to go through the proper CHANGE_VALUE channel
        // for value changes
        state.value = undefined
      }
      if (state.view && !state.baseView) {
        state.baseView = state.view
      }
      if (state.baseView) {
        state.view = evaluateViewConditions(state.baseView, initialValue)
      }
    }

    const newState = initialState(state || {})
    newState.lastAction = 'INIT'
    newState.value = immutable(newState.value)
    return newState
  }
1227441
def from_list(cls, actions):
        ''''''
        bitmask = 0
        for a in actions:
            bitmask |= cls.action_bitmask(a)
        return Action(bitmask)
1355456
def simulate(self, action):
    
    with tf.name_scope('environment/simulate'):
      if action.dtype in (tf.float16, tf.float32, tf.float64):
        action = tf.check_numerics(action, 'action')
      observ_dtype = self._parse_dtype(self._batch_env.observation_space)
      observ, reward, done = tf.py_func(
          lambda a: self._batch_env.step(a)[:3], [action],
          [observ_dtype, tf.float32, tf.bool], name='step')
      observ = tf.check_numerics(observ, 'observ')
      reward = tf.check_numerics(reward, 'reward')
      return tf.group(
          self._observ.assign(observ),
          self._action.assign(action),
          self._reward.assign(reward),
          self._done.assign(done))
975083
def action_scope(self, action_fluents: Sequence[tf.Tensor]) -> Dict[str, TensorFluent]:
        '''
        '''
        return dict(zip(self.rddl.domain.action_fluent_ordering, action_fluents))
547328
def inference(self, limit=1000):
        '''
        
        '''
        route_list = []
        memory_list = []
        state_key = self.__start_point_tuple
        x, y = state_key
        end_x, end_y = self.__end_point_tuple
        for i in range(limit):
            q_df = self.q_df[self.q_df.state_key == state_key]
            if len(memory_list):
                q_df = q_df[~q_df.action_key.isin(memory_list)]
            if q_df.shape[0] > 1:
                q_df = q_df.sort_values(by=["q_value"], ascending=False)
                action_key = q_df.iloc[0, :]["action_key"]
                q_value = q_df.iloc[0, :]["q_value"]
            elif q_df.shape[0] == 1:
                action_key = q_df.action_key.values[0]
                q_value = q_df.q_value.values[0]
            else:
                action_key_list = self.extract_possible_actions(state_key)
                action_key_list = [v for v in action_key_list if v not in memory_list]
                q_value = 0.0
                if len(action_key_list):
                    action_key = random.choice(action_key_list)
                    _q_df = q_df[q_df.action_key == action_key]
                    if _q_df.shape[0]:
                        q_value = _q_df.q_value.values[0]

            state_key = self.update_state(
                state_key=state_key,
                action_key=action_key
            )
            x, y = state_key
            route_list.append((x, y, q_value))
            memory_list.append(state_key)
            if self.check_the_end_flag(state_key) is True:
                break

        return route_list
409569
def p_state(self, state):
        ''''''
        state[0] = State(state[1][0], state[1][1], state[1][2], state[1][3], state[2])
280943
def step(self, observation, argmax_sampling=False):
        
        action_pd_params, value_output = self(observation)
        actions = self.action_head.sample(action_pd_params, argmax_sampling=argmax_sampling)

        # log likelihood of selected action
        logprobs = self.action_head.logprob(actions, action_pd_params)

        return {
            'actions': actions,
            'values': value_output,
            'action:logprobs': logprobs
        }
195430
def build_action(self, action):
        
        try:
            self.action = Action.from_string(action)
        except ValueError:
            raise

        return self
177254
function initWithActions (actionType, actions) {
    var prev = actions[0].copy()
      , now
      , i
    for (i=1; i<actions.length; i++) {
        now = actions[i].copy()
        if (now) {
            prev = new actionType({one: prev, two: now})
        } else {
            break
        }
    }

    return prev
}
16402
def inference(self, state_arr, limit=1000):
        '''
        
        '''
        self.__inferencing_flag = True

        agent_x, agent_y = np.where(state_arr[0] == 1)
        agent_x, agent_y = agent_x[0], agent_y[0]
        self.__create_enemy(self.__map_arr)
        result_list = [(agent_x, agent_y, 0.0)]
        result_val_list = [agent_x, agent_y]
        for e in range(self.__enemy_num):
            result_val_list.append(self.__enemy_pos_list[e][0])
            result_val_list.append(self.__enemy_pos_list[e][1])
        result_val_list.append(0.0)
        result_list.append(tuple(result_val_list))

        self.t = 0
        while self.t < limit:
            next_action_arr = self.extract_possible_actions(state_arr)
            next_q_arr = self.function_approximator.inference_q(next_action_arr)
            action_arr, q = self.select_action(next_action_arr, next_q_arr)
            self.__move_enemy(action_arr)

            agent_x, agent_y = np.where(action_arr[0] == 1)
            agent_x, agent_y = agent_x[0], agent_y[0]
            
            result_val_list = [agent_x, agent_y]
            for e in range(self.__enemy_num):
                result_val_list.append(self.__enemy_pos_list[e][0])
                result_val_list.append(self.__enemy_pos_list[e][1])
            try:
                result_val_list.append(q[0])
            except IndexError:
                result_val_list.append(q)

            result_list.append(tuple(result_val_list))

            # Update State.
            state_arr = self.update_state(state_arr, action_arr)

            # Epsode.
            self.t += 1
            # Check.
            end_flag = self.check_the_end_flag(state_arr)
            if end_flag is True:
                break

        return result_list
810765
def actions(acts, done):
    '''
    
    '''

    def _intermediate(acc, action):
        result = action(acc['state'])
        values = concatv(acc['values'], [result['answer']])

        return {'values': values, 'state': result['state']}

    def _actions(seed):
        init = {'values': [], 'state': seed}

        result = reduce(_intermediate, acts, init)

        keep = remove(lambda x: x is None, result['values'])

        return done(keep, result['state'])

    return _actions
1116194
def performAction(self, action):
        
        gs = [g for g in self.case.online_generators if g.bus.type !=REFERENCE]

        assert len(action) == len(gs)

        logger.info("Action: %s" % list(action))

        # Set the output of each (non-reference) generator.
        for i, g in enumerate(gs):
            g.p = action[i]

        # Compute power flows and slack generator set-point.
        NewtonPF(self.case, verbose=False).solve()
        #FastDecoupledPF(self.case, verbose=False).solve()

        # Store all generator set-points (only used for plotting).
        self._Pg[:, self._step] = [g.p for g in self.case.online_generators]

        # Apply the next load profile value to the original demand at each bus.
        if self._step != len(self.profile) - 1:
            pq_buses = [b for b in self.case.buses if b.type == PQ]
            for i, b in enumerate(pq_buses):
                b.p_demand = self._Pd0[i] * self.profile[self._step + 1]

        self._step += 1

        logger.info("Entering step %d." % self._step)
769453
def current_state_by_controller(*given_controller_names, actions: [])
      if given_controller_names.any? { |name| name == controller_name.to_sym }
        if actions.present?
          Array(actions).include?(action_name.to_sym)
        else
          true
        end
      end
    end
1031237
def main(unused_argv):
  """"""
  feats = features.Features(
      # Actually irrelevant whether it's feature or rgb size.
      features.AgentInterfaceFormat(
          feature_dimensions=features.Dimensions(
              screen=FLAGS.screen_size,
              minimap=FLAGS.minimap_size)))
  action_spec = feats.action_spec()
  flattened = 0
  count = 0
  for func in action_spec.functions:
    if FLAGS.hide_specific and actions.FUNCTIONS[func.id].general_id != 0:
      continue
    count += 1
    act_flat = 1
    for arg in func.args:
      for size in arg.sizes:
        act_flat *= size
    flattened += act_flat
    print(func.str(True))
  print("Total base actions:", count)
  print("Total possible actions (flattened):", flattened)
1041164
def build_action(self, runnable, regime, action):
        

        if isinstance(action, StateAssignment):
            return self.build_state_assignment(runnable, regime, action)
        if isinstance(action, EventOut):
            return self.build_event_out(action)
        if isinstance(action, Transition):
            return self.build_transition(action)
        else:
            return ['pass']