docwza / deep-rl-tsc

Distributed Deep Reinforcement Learning Traffic Signal Control
MIT License
47 stars 10 forks source link

file: deep-rl-tsc/NetworkData.py return for get_intersection_data not specified #1

Open amitesh863 opened 4 years ago

amitesh863 commented 4 years ago

def get_intersection_data(self, net): nodes = [n for n in net.getNodes()]

    nodes = net.getNodes()
    node_data = {str(node.getID()):{} for node in nodes} 

    for node in nodes:
        node_ID = str(node.getID())
        node_data[node_ID]['incoming'] = [str(lane.getID()) for lane in node.getIncoming()]
        node_data[node_ID]['outgoing'] = [str(lane.getID()) for lane in node.getOutgoing()]
nagasriramnani commented 3 months ago

To resolve the issue stated, which involves specifying the return value for the get_intersection_data method and potentially cleaning up the redundant line, you should modify the method to ensure it's clear, efficient, and explicitly returns the node_data dictionary. Here's an enhanced version of the method with comments to guide you through the changes:

def get_intersection_data(self, net):

Obtain all nodes (intersections) from the network object.

# Removed the redundant line that was fetching nodes twice.
nodes = net.getNodes()

# Initialize a dictionary to hold data about each node.
# For each node, we'll store the IDs of incoming and outgoing lanes.
node_data = {str(node.getID()): {} for node in nodes}

# Iterate over each node to populate the node_data dictionary.
for node in nodes:
    node_ID = str(node.getID())  # Convert node ID to string to use as a key.

    # For each node, fetch the IDs of incoming lanes and store them.
    node_data[node_ID]['incoming'] = [str(lane.getID()) for lane in node.getIncoming()]

    # Similarly, fetch and store the IDs of outgoing lanes.
    node_data[node_ID]['outgoing'] = [str(lane.getID()) for lane in node.getOutgoing()]

# Return the populated dictionary containing nodes' incoming and outgoing lanes.
return node_data

Key Changes and Additions: Eliminated Redundancy: Removed the unnecessary line that redundantly fetched the nodes a second time.

Explicit Return Statement: Added a return statement to ensure the method returns the node_data dictionary. This makes it clear what the output of the method is and allows it to be used elsewhere in your code.

This solution addresses the issue by cleaning up the method and ensuring that its intended functionality is fully realized and clearly understood by anyone who uses or reviews this code in the future.

nagasriramnani commented 3 months ago

if it is solved make the response as solved