class LinearBuildEnvironment(GraphEnvironment):
Constructor: LinearBuildEnvironment(graph_invariant, graph_order, flattened_ordering, edge_colors, ...)
This class inherits from the GraphEnvironment class and models a graph building game in which
the edges (resp. arcs) are initially uncolored and are then properly colored one by one, either
in row-major order or clockwise order. Users can configure the graph order, the number of
proper edge colors, whether the graphs are directed or undirected, and whether loops are
allowed. Edges (resp. arcs) are properly colored according to the reconstruction from a
flattened format. If loops are not allowed, the corresponding edges are ignored; if the graphs
are undirected, only the upper-triangular part of the adjacency matrix is considered (including
or excluding the diagonal depending on whether loops are allowed), and each edge is effectively
colored in both directions simultaneously.
The RL tasks in this environment are episodic. The episode length equals the flattened length, i.e., the number of entries in any of the two flattened formats with color numbers. This number depends on the graph order, on whether the graphs are directed, and on whether loops are allowed.
Each state is represented by a binary numpy.ndarray vector of type numpy.uint8 and length
edge_colors * flattened_length, where edge_colors is the configured number of proper
edge colors and flattened_length is the flattened length of the graph. In the state
vectors, the first flattened_length bits indicate which edges (resp. arcs) have been
colored with color 1, the next flattened_length bits indicate which edges (resp. arcs) have
been colored with color 2, and this pattern continues for each color up to edge_colors - 1.
The final flattened_length bits form a one-hot encoding of the next edge (resp. arc) to be
properly colored. A value of 1 at a given position indicates which edge (resp. arc) is to be
colored next, while all zeros signify a terminal state in which all edges (resp. arcs) have
been properly colored.
Each action is represented by a numpy.int32 integer between 0 and edge_colors - 1, which
specifies the color to assign to the next edge (resp. arc) in the selected order.
| Method | __init__ |
This constructor initializes an instance of the LinearBuildEnvironment class. |
| Method | state |
This abstract method must be implemented by any concrete subclass. It extracts the batch of underlying graphs corresponding to a provided batch of states. Implementations must return a Graph object containing the graphs corresponding to each row in ... |
| Property | action |
This abstract property must be implemented by any concrete subclass. It must return None if no episodes are currently being run in parallel, or if every action is available in every current state. Otherwise, it must return a two-dimensional ... |
| Property | action |
This abstract property must be implemented by any concrete subclass. It must return the total number of distinct actions that can be executed in the environment, as a positive int. |
| Property | episode |
This abstract property must be implemented by any concrete subclass. It must return the predetermined common length of all episodes run in parallel, i.e., the total number of actions executed in each episode, as a positive ... |
| Property | is |
This abstract property must be implemented by any concrete subclass. It must return a bool indicating whether the environment is continuing (True) or episodic (False). |
| Property | state |
This abstract property must be implemented by any concrete subclass. It must return the data type of the one-dimensional numpy.ndarray vectors that represent states, as a numpy.dtype. |
| Property | state |
This abstract property must be implemented by any concrete subclass. It must return the number of entries in each state vector, i.e., the length of the one-dimensional numpy.ndarray vectors that represent states, as a positive ... |
| Method | _initialize |
This abstract method must be implemented by any concrete subclass. It must initialize a batch of episodes of the specified size and update the _state_batch and _status attributes so that they represent the newly initialized batch. |
| Method | _transition |
This abstract method must be implemented by any concrete subclass. It must apply a batch of actions to the current batch of states and update the _state_batch and _status attributes to reflect the resulting states and the updated batch status... |
| Instance Variable | _allow |
A bool indicating whether loops are allowed in the graphs to be constructed. |
| Instance Variable | _edge |
The number of proper edge colors in the graphs to be constructed, given as a positive int that is at least 2. |
| Instance Variable | _flattened |
A positive int equal to the flattened length of the graphs to be constructed, which also equals the total number of steps needed to reach a terminal state. |
| Instance Variable | _flattened |
An item of the FlattenedOrdering enumeration specifying whether the edges (resp. arcs) are colored in row-major or clockwise order. |
| Instance Variable | _is |
A bool indicating whether the graphs to be constructed are directed or undirected. |
| Instance Variable | _state |
See the description of the GraphEnvironment._state_batch attribute. |
| Instance Variable | _state |
A positive int equal to _edge_colors * _flattened_length, i.e., the length of each state vector. |
| Instance Variable | _status |
See the description of the GraphEnvironment._status attribute. |
| Instance Variable | _step |
Either None or a nonnegative int between 0 and _flattened_length indicating the index of the next edge (resp. arc) to properly color according to _flattened_ordering. When _step_count equals _flattened_length... |
Inherited from GraphEnvironment:
| Method | reset |
This method initializes a batch of episodes of a specified size and returns the resulting batch of states, the corresponding values of the selected graph invariant (if computed), and the status of the batch of episodes... |
| Method | state |
This method extracts the underlying graph corresponding to a single state. |
| Method | step |
This method applies a batch of actions to the current batch of episodes and returns the resulting batch of states, the corresponding values of the selected graph invariant (if computed), and the updated status of the batch... |
| Instance Variable | sparse |
A bool indicating whether the graph invariant values should be computed only for the final batch of actions. |
| Instance Variable | __graph |
Either None or a Graph object representing the current batch of underlying graphs. This attribute is updated only when required by the sparse setting. |
| Instance Variable | __graph |
A GraphInvariant function specifying the graph invariant to be maximized. |
| Instance Variable | __graph |
Either None or a one-dimensional numpy.ndarray of type numpy.float32 containing the current batch of graph invariant values. As with __graph_batch, this attribute is updated only when required by the sparse setting. |
| Instance Variable | __graph |
Either None, indicating that graph invariant values are always computed directly using __graph_invariant, or a GraphInvariantDiff function used to incrementally update invariant values after state transitions. |
GraphInvariant, graph_order: int, flattened_ordering: FlattenedOrdering = FlattenedOrdering.ROW_MAJOR, edge_colors: int = 2, is_directed: bool = False, allow_loops: bool = False, graph_invariant_diff: GraphInvariantDiff | None = None, sparse_setting: bool = False):
¶
This constructor initializes an instance of the LinearBuildEnvironment class.
| Parameters | |
graphGraphInvariant | A GraphInvariant function that computes the graph invariant
values associated with a batch of underlying graphs. These values are the quantities to
be maximized by the environment. |
graphint | A positive int (not below 2) that represents the graph order of the
graphs to be constructed. |
flattenedFlattenedOrdering | An item of the FlattenedOrdering enumeration indicating
whether the edges (resp. arcs) should be properly colored in the row-major or clockwise
order. The default value is FlattenedOrdering.ROW_MAJOR. |
edgeint | A positive int (not below 2) specifying the number of proper edge
colors in the graphs to be constructed. The default value is 2. |
isbool | A bool indicating whether the graphs to be constructed are directed.
The default value is False. |
allowbool | A bool indicating whether loops are allowed in the graphs to be
constructed. The default value is False. |
graphGraphInvariantDiff | None | Either None, indicating that graph invariant values are
always computed directly using graph_invariant, or a GraphInvariantDiff function
that computes element-wise differences of the graph invariant values when the
environment transitions from one batch of underlying graphs to another. The default
value is None. |
sparsebool | A bool indicating whether the sparse setting is enabled. If set to
True, the graph invariant values are computed only for the final batch of actions.
Otherwise, the graph invariant values are computed after every batch of actions. The
default value is False. |
This abstract method must be implemented by any concrete subclass. It extracts the batch of
underlying graphs corresponding to a provided batch of states. Implementations must return
a Graph object containing the graphs corresponding to each row in state_batch,
preserving the row order. This method must be pure and must not modify any attributes of
the class instance.
| Parameters | |
statenp.ndarray | A two-dimensional numpy.ndarray whose rows represent individual
states from which the underlying graphs are to be extracted. |
| Returns | |
Graph | A Graph object representing the extracted batch of graphs. |
This abstract property must be implemented by any concrete subclass. It must return None
if no episodes are currently being run in parallel, or if every action is available in
every current state. Otherwise, it must return a two-dimensional numpy.ndarray matrix
a of type bool whose entry a[i, j] is True if and only if action j is
available in the current state of the i-th episode.
This abstract property must be implemented by any concrete subclass. It must return the
total number of distinct actions that can be executed in the environment, as a positive
int.
This abstract property must be implemented by any concrete subclass. It must return the
predetermined common length of all episodes run in parallel, i.e., the total number of
actions executed in each episode, as a positive int.
This abstract property must be implemented by any concrete subclass. It must return the
data type of the one-dimensional numpy.ndarray vectors that represent states, as a
numpy.dtype.
This abstract property must be implemented by any concrete subclass. It must return the
number of entries in each state vector, i.e., the length of the one-dimensional
numpy.ndarray vectors that represent states, as a positive int.
This abstract method must be implemented by any concrete subclass. It must initialize a
batch of episodes of the specified size and update the _state_batch and _status
attributes so that they represent the newly initialized batch.
| Parameters | |
batchint | The number of episodes to initialize in the batch, given as a positive
int. |
This abstract method must be implemented by any concrete subclass. It must apply a batch of
actions to the current batch of states and update the _state_batch and _status
attributes to reflect the resulting states and the updated batch status. Implementations
may also update additional subclass-specific attributes as required.
| Parameters | |
actionnp.ndarray | A one-dimensional numpy.ndarray of type numpy.int32 containing the
actions to be applied. The length of action_batch must match the number of states
in _state_batch. |
The number of proper edge colors in the graphs to be constructed, given as
a positive int that is at least 2.
A positive int equal to the flattened length of the graphs to be
constructed, which also equals the total number of steps needed to reach a terminal state.
An item of the FlattenedOrdering enumeration specifying whether
the edges (resp. arcs) are colored in row-major or clockwise order.
Either None or a nonnegative int between 0 and _flattened_length
indicating the index of the next edge (resp. arc) to properly color according to
_flattened_ordering. When _step_count equals _flattened_length, the state is
terminal. This attribute is initially None and updated after each call to
GraphEnvironment.reset_batch or GraphEnvironment.step_batch.