graphenv.examples.tsp.tsp_state.TSPState
- class TSPState(graph_generator, G=None, tour=[0])[source]
Bases:
graphenv.vertex.Vertex
Create a TSP vertex that defines the graph search problem.
- Parameters
generator – a function that creates a networkx graph
G (Optional[networkx.classes.graph.Graph]) – A fully connected networkx graph.
tour (List[int]) – A list of nodes in visitation order that led to this state. Defaults to [0] which begins the tour at node 0.
graph_generator (Callable[[], networkx.classes.graph.Graph]) –
- Return type
None
Methods
Convenience function for duplicating the existing node.
Optional method for rendering the current state of the environment.
Attributes
children
Gets the child vertices of this vertex.
Returns: An optional dictionary with additional information about the state
observation
Gets the observation of this vertex.
Returns the graph env's observation space.
Returns the graph env reward.
Returns the root node of the graph env.
terminal
Returns: True if this is a terminal vertex in the graph.
- property info: Dict
Returns: An optional dictionary with additional information about the state
- new(tour=[0], new_graph=False, **kwargs)[source]
Convenience function for duplicating the existing node.
- Parameters
G – Networkx graph.
tour (List[int]) – List of visited nodes.
- Returns
New TSP state.
- property observation_space: gymnasium.spaces.dict.Dict
Returns the graph env’s observation space.
- Returns
Dict observation space.
- render()[source]
Optional method for rendering the current state of the environment.
- Return type
Any
- property reward: float
Returns the graph env reward.
- Returns
Negative distance between last two nodes in the tour.
- property root: graphenv.examples.tsp.tsp_state.TSPState
Returns the root node of the graph env.
- Returns
Node with node 0 as the starting point of the tour, and generates a new graph using the given constructor