File size: 1,799 Bytes
7cec401
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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()