class LocalFlipEnvironment(GraphEnvironment):
Constructor: LocalFlipEnvironment(graph_invariant, graph_order, episode_length, flip_only, ...)
This class inherits from the GraphEnvironment class and models a graph building game used for
constructing 2-edge-colored looped complete graphs in which the edges (resp. arcs) are
initially fully colored in some manner, and the agent moves from one vertex to another, thereby
traversing existing edges (resp. arcs) and potentially flipping them. More precisely, in each
step, the agent is located at a vertex and selects an incident edge (resp. an outgoing arc),
traverses it, and moves to the opposite endpoint. While traversing an edge (resp. arc), the
agent may flip its proper edge color. The user can select the graph order, choose whether the
graphs are directed or undirected, and specify whether loops are allowed. Additionally, the
user can configure the mechanism that controls how the initial fully colored graphs are
generated, which may be either deterministic or nondeterministic. The user can also select the
vertex at which the agent starts the potential flipping procedure.
The RL tasks in this environment are continuing, and the total number of actions to be performed, i.e., the episode length, is configurable.
Each state is represented by a binary numpy.ndarray of type numpy.uint8 and length
flattened_length + graph_order, where graph_order is the configured graph order and
flattened_length is the flattened length of the graphs to be constructed. In the state
vectors, the first flattened_length bits indicate which of the flattened_length edges
(resp. arcs) are currently of color 1. The edges (resp. arcs) are ordered according to the
selected flattened ordering, which may be either row-major or clockwise. The final
graph_order bits form a one-hot encoding of the vertex at which the agent is currently
located.
The environment supports two action-handling modes. If flip_only is set to False (the
default), each action is represented by a numpy.int32 integer between 0 and
2 * graph_order - 1. For an action value a, the quantity a % graph_order specifies
the vertex to which the agent moves, while a // graph_order determines whether the
traversed edge (resp. arc) is flipped. A value of 1 indicates that the proper edge color is
changed, whereas 0 indicates that it remains unchanged. If flip_only is set to True,
then every traversed edge (resp. arc) must be flipped. In this case, each action is a
numpy.int32 integer between 0 and graph_order - 1 specifying the destination vertex, with
the traversed edge (resp. arc) necessarily flipped. If loops are not allowed, then the agent
cannot move to its current vertex.
| Method | __init__ |
This constructor initializes an instance of the LocalFlipEnvironment class. |
| Method | episode |
This setter allows the user to potentially reconfigure the episode length between two independent batches of episodes. It should not be used while a batch of episodes is currently in progress. |
| 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 ... |
| Instance Variable | initial |
A GraphGenerator function that defines how the underlying fully colored graphs are generated for the initial states. This attribute may be reconfigured between independent batches of episodes. |
| Instance Variable | starting |
A nonnegative int below the configured graph order that determines the vertex at which the agent should start the potential flipping procedure. This attribute may be reconfigured between independent batches of episodes. |
| 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 method applies a batch of actions to the current batch of states and updates 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 | _current |
Either None or a numpy.ndarray of type numpy.int32 specifying the vertex where the agent is currently located in each episode run in parallel. |
| Instance Variable | _episode |
A positive int specifying the episode length, i.e., the total number of actions in each episode. |
| Instance Variable | _flattened |
A positive int equal to the flattened length of the graphs to be constructed. |
| Instance Variable | _flattened |
An item of the FlattenedOrdering enumeration specifying the edge (resp. arc) ordering (row-major or clockwise). |
| Instance Variable | _flip |
A bool indicating whether all traversed edges (resp. arcs) must be flipped. |
| Instance Variable | _graph |
A positive int that describes the order of the graphs to be constructed. |
| 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 | _status |
See the description of the GraphEnvironment._status attribute. |
| Instance Variable | _step |
Either None or a nonnegative int counting how many actions have been executed in the current batch of episodes. When _step_count equals _episode_length, the episode has reached a final state. This attribute is updated after each call to ... |
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, episode_length: int | None = None, flip_only: bool = False, flattened_ordering: FlattenedOrdering = FlattenedOrdering.ROW_MAJOR, is_directed: bool = False, allow_loops: bool = False, initial_graph_generator: GraphGenerator | None = None, starting_vertex: int = 0, graph_invariant_diff: GraphInvariantDiff | None = None, sparse_setting: bool = False):
¶
This constructor initializes an instance of the LocalFlipEnvironment 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. |
episodeint | None | Either None, or a positive int specifying the number of actions
in each episode. If None, the episode length defaults to the flattened length of the
graphs to be constructed. The default value is None. |
flipbool | A bool specifying whether the traversed edges (resp. arcs) must be
flipped. The default value is False. |
flattenedFlattenedOrdering | An item of the FlattenedOrdering enumeration specifying
whether the edges (resp. arcs) are ordered row-major or clockwise. The default value is
FlattenedOrdering.ROW_MAJOR. |
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. |
initialGraphGenerator | None | Either None or a GraphGenerator function that
determines how the initial fully colored graphs are generated for the batch of initial
states. If None, all edges (resp. arcs) in all graphs are initially colored with
color 0. The default value is None. |
startingint | A nonnegative int strictly less than graph_order specifying
the vertex at which the agent starts the potential flipping procedure. The default
value is 0. |
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. |
A GraphGenerator function that defines how the underlying
fully colored graphs are generated for the initial states. This attribute may be
reconfigured between independent batches of episodes.
A nonnegative int below the configured graph order that determines
the vertex at which the agent should start the potential flipping procedure. This attribute
may be reconfigured between independent batches of episodes.
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 method applies a batch of actions to the current batch of states and updates the
_state_batch and _status attributes to reflect the resulting states and the updated
batch status.
| 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. |
| Note | |
If loops are not allowed and an action attempts to traverse a loop, a RuntimeError
is raised. |
Either None or a numpy.ndarray of type numpy.int32 specifying
the vertex where the agent is currently located in each episode run in parallel.
A positive int specifying the episode length, i.e., the total number
of actions in each episode.
An item of the FlattenedOrdering enumeration specifying the edge
(resp. arc) ordering (row-major or clockwise).
Either None or a nonnegative int counting how many actions have been
executed in the current batch of episodes. When _step_count equals _episode_length, the
episode has reached a final state. This attribute is updated after each call to
GraphEnvironment.reset_batch or GraphEnvironment.step_batch.