GraSIF / office /office_graph.py
Onisci's picture
Load data
7cec401 verified
import networkx as nx
from nodes import ROOMS, OFFICES, ASSETS, OBJECTS
def add_edges(graph):
for node_name in graph.nodes:
node = graph.nodes[node_name]
match node['type']:
case 'place':
graph.add_edge(node_name,('scene',1))
case 'asset':
graph.add_edge(node_name,node['place'])
case 'object':
graph.add_edge(node_name,node['related_to'])
case 'agent':
graph.add_edge(node_name,node['location'])
case 'scene':
pass
case _:
print(f"Unknown node type: {node['type']}")
def create_office_graph():
"""Initializes and builds the office scene graph."""
graph = nx.Graph()
graph.add_node(('scene', 1), name='SayPlan Office', type='scene')
# Add places (offices and rooms) and connect them to the scene
for place in (OFFICES + ROOMS):
graph.add_node(place, type='place')
# Add assets and connect them to their places
for asset, place, states, affordances, properties in ASSETS:
graph.add_node(asset, place=place, states=states, affordances=affordances, properties=properties, type='asset')
# Add objects and connect them to their related assets/objects
for obj, relation, related_to, states, affordances, properties in OBJECTS:
graph.add_node(obj, relation=relation, related_to=related_to, states=states, affordances=affordances, properties=properties, type='object')
# Add the agent and connect it to its location
agent_node = ('agent', 1)
agent_location = ('mobile_robotics_lab', 1)
graph.add_node(agent_node, location=agent_location, holding='', type='agent')
add_edges(graph)
return graph
# Initialize the graph by calling the function
office_graph = create_office_graph()