Class GraphInstance
One element of a Graph space: the node features, the edge features and the edge links, as the
(nodes, edges, edge_links) tuple Gymnasium's NamedTuple is. It deconstructs like one:
var (nodes, edges, links) = graph.Sample();.
public sealed class GraphInstance : ITuple, IEquatable<GraphInstance>, INDArrayCarrier, IDisposable
- Inheritance
-
GraphInstance
- Implements
- Inherited Members
- Extension Methods
Remarks
For a Box or Discrete node space (Gymnasium's intended use) Nodes is an
array of shape (n, ...) and Edges one of shape (m, ...); other subspaces give their
batched form (a tuple, a dict), which is why both are typed object.
The instance owns the arrays it holds: Dispose() releases them, nested ones included. Equality is
Python's tuple == through PyEquality (arrays equal when np.array_equal says so).
Reference: gymnasium/spaces/graph.py (GraphInstance).
Constructors
GraphInstance(object?, object?, NDArray?)
A graph from its parts (Gymnasium's GraphInstance(nodes, edges, edge_links)); the instance takes ownership of them.
public GraphInstance(object? nodes, object? edges, NDArray? edgeLinks)
Parameters
nodesobjectThe node features:
(n, ...), one row per node.edgesobjectThe edge features,
(m, ...), or null for a graph without edge features.edgeLinksNDArrayThe
(m, 2)integer array of the two node indices each edge connects, or null when there are no edges.
Properties
EdgeLinks
The (m, 2) node indices each edge connects (Gymnasium's edge_links), or null.
public NDArray? EdgeLinks { get; }
Property Value
Edges
The edge features (Gymnasium's edges), one row per edge, or null.
public object? Edges { get; }
Property Value
Nodes
The node features (Gymnasium's nodes), one row per node.
public object? Nodes { get; }
Property Value
Methods
Deconstruct(out object?, out object?, out NDArray?)
Unpacks the instance, as Python's nodes, edges, edge_links = graph_instance does.
public void Deconstruct(out object? nodes, out object? edges, out NDArray? edgeLinks)
Parameters
nodesobjectThe node features.
edgesobjectThe edge features, or null.
edgeLinksNDArrayThe edge links, or null.
Dispose()
Releases the arrays the instance holds, nested ones (a tuple's or dict's parts) included; idempotent.
public void Dispose()
Equals(GraphInstance?)
Python's tuple == of the three fields (see the remarks for arrays).
public bool Equals(GraphInstance? other)
Parameters
otherGraphInstanceThe other instance.
Returns
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current object.
Returns
GetHashCode()
A hash consistent with Equals(GraphInstance?) that never reads array data (array fields contribute their shapes). Python cannot hash an instance holding arrays at all.
public override int GetHashCode()
Returns
- int
The hash.
ToString()
Gymnasium's NamedTuple repr: GraphInstance(nodes=array([...]), edges=None, edge_links=None).
public override string ToString()
Returns
- string
The text.