def get_ind_activities_per_resource(physical_constituency_matrix: types.ConstituencyMatrix) -> \ Tuple[List[List[int]], List[int]]: """ Return the index of activities per resource and the total number of activities per resource. :param physical_constituency_matrix: Constituency matrix from environment. We assume it has orthogonal rows. :return: (activities_per_resource, num_activities_per_resource): - activities_per_resource: List of lists of activities per resource. - num_activities_per_resource: List of number of activities per resource. """ assert agents_utils.has_orthogonal_rows(physical_constituency_matrix), \ "Physical constituency matrix must have orthogonal rows." activities_per_resource = [] # type: List[List[int]] num_activities_per_resource = [] # type: List[int] for c in physical_constituency_matrix: activities_c = np.nonzero(c)[0] assert activities_c.size > 0 activities_per_resource += [activities_c.tolist()] num_activities_per_resource += [activities_c.size] return activities_per_resource, num_activities_per_resource
def __init__(self, physical_constituency_matrix: types.ConstituencyMatrix, buffer_processing_matrix: types.BufferMatrix, mpc_seed: Optional[int] = None) -> None: """ Obtain feasible binary actions from activity rates with feedback on how many actions have been performed so far for a given horizon. The actions are drawn from a probability distribution that aims to match the activity rates after some horizon. The feedback allows to adjust the distribution so that underperformed activities are emphasised. Feasible actions refer to those that drain nonempty buffers. In the case that some action is infeasible, then the corresponding resource performs other activity. :param physical_constituency_matrix: Constituency matrix from environment. We assume it has orthogonal rows. :param buffer_processing_matrix: Buffer processing matrix from environment. :return: None. """ # Ensure that constituency_matrix has a single one per column. assert agents_utils.has_orthogonal_rows(physical_constituency_matrix), \ "Physical constituency matrix must have orthogonal rows." super().__init__(physical_constituency_matrix, mpc_seed) self.buffer_processing_matrix = buffer_processing_matrix self.activities_per_resource, self.num_activities_per_resource \ = self.get_ind_activities_per_resource(physical_constituency_matrix)
def __init__(self, physical_constituency_matrix: types.ConstituencyMatrix, mpc_seed: Optional[int] = None) -> None: """ :param physical_constituency_matrix: Matrix with those rows from the constituency matrix that represent physical resources, so that it must have a single one per column. If the constituency_matrix of the problem has multiple ones per column (e.g. the "3x3 input queued switch"), then the matrix should not be used with this class. :param mpc_seed: MPC policy random seed. """ # Ensure that constituency_matrix has a single one per column. assert agents_utils.has_orthogonal_rows(physical_constituency_matrix), \ "Physical constituency matrix must have orthogonal rows." super().__init__(physical_constituency_matrix, mpc_seed)
def __init__(self, env: crw.ControlledRandomWalk, state_option: bool, cost_option: bool, rate_option: bool, name: str, agent_seed: Optional[int] = None) -> None: """ Non-idling policy for push models where each activity can be done only by one resource. Buffers on which to work and activities to performed are decided based on a custom combination of buffers state, buffer cost, and activity rate. Flags are used to specify which combination of such parameters is used to determine priority. In order to be able to work on a buffer, its state has to be higher than zero. If there are multiple options with the same value, each resource chooses among them randomly. :param env: the environment to stepped through. :param state_option: whether the current state is considered when computing the priority values. :param cost_option: whether the cost is considered when computing the priority values. :param rate_option: whether the activities rate is considered when computing the priority values. :param name: Agent identifier. :return: None. """ # verify that at least an option has been selected assert any([state_option, cost_option, rate_option]) # verify that each activity can be performed by only one resource assert agents_utils.has_orthogonal_rows(env.constituency_matrix), \ "Constituency matrix must have orthogonal rows." # verify that the environment is a push model for resource_constraints in env.list_boundary_constraint_matrices: assert np.all(np.sum(resource_constraints, axis=1) >= 1) super().__init__(env, name, agent_seed) self._state_option = state_option self._cost_option = cost_option self._rate_option = rate_option self.env = env
def test_assert_orthogonal_rows_false(): matrix = np.array([[1, 0, 0, 1], [1, 1, 1, 0]]) assert not utils.has_orthogonal_rows(matrix)