Table of Contents

Class GraphInstance

Namespace
Gym.Spaces
Assembly
Gym.dll

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

nodes object

The node features: (n, ...), one row per node.

edges object

The edge features, (m, ...), or null for a graph without edge features.

edgeLinks NDArray

The (m, 2) integer array of the two node indices each edge connects, or null when there are no edges.

Properties

The (m, 2) node indices each edge connects (Gymnasium's edge_links), or null.

public NDArray? EdgeLinks { get; }

Property Value

NDArray

Edges

The edge features (Gymnasium's edges), one row per edge, or null.

public object? Edges { get; }

Property Value

object

Nodes

The node features (Gymnasium's nodes), one row per node.

public object? Nodes { get; }

Property Value

object

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

nodes object

The node features.

edges object

The edge features, or null.

edgeLinks NDArray

The 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

other GraphInstance

The other instance.

Returns

bool

true when all three fields are equal.

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

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.