From e8dbf3221e8ccc90211e622a14e8a9367ccc70f6 Mon Sep 17 00:00:00 2001 From: Henry Wallace Date: Mon, 25 Nov 2024 11:13:12 +0000 Subject: [PATCH] Now just generates adjacency matrix, this is still a bit slow but substantially faster than doing an unecessary sort! --- .../cider/app_structures/main_screen.py | 8 ++-- .../cider/data_structures/relational_graph.py | 47 +++++++++++++++++-- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/python/daqconf/cider/app_structures/main_screen.py b/python/daqconf/cider/app_structures/main_screen.py index ad948f54..a26495dc 100644 --- a/python/daqconf/cider/app_structures/main_screen.py +++ b/python/daqconf/cider/app_structures/main_screen.py @@ -26,12 +26,12 @@ class MainScreen(Screen): BINDINGS = [ # Binding("ctrl+s", "save_configuration", "Save Configuration"), Binding("ctrl+s", "save_configuration_with_message", "Save Configuration"), - Binding("ctrl+o", "open_configuration", "Open Configuration"), + Binding("o", "open_configuration", "Open Configuration"), Binding("ctrl+q", "request_quit", "Exit Cider"), - Binding("ctrl+e", "modify_relations", "Modify Relation to Object"), - Binding("ctrl+r", "rename_configuration", "Rename Conf Object"), + Binding("e", "modify_relations", "Modify Relation to Object"), + Binding("r", "rename_configuration", "Rename Conf Object"), Binding("d", "toggle_disable", "Toggle Disable"), - Binding("ctrl+a", "add_configuration", "Add Conf Object"), + Binding("a", "add_configuration", "Add Conf Object"), Binding("ctrl+d", "destroy_configuration", "Delete Conf Object"), ] diff --git a/python/daqconf/cider/data_structures/relational_graph.py b/python/daqconf/cider/data_structures/relational_graph.py index 1d01dd8b..ccc0a7c0 100644 --- a/python/daqconf/cider/data_structures/relational_graph.py +++ b/python/daqconf/cider/data_structures/relational_graph.py @@ -15,6 +15,39 @@ from daqconf.cider.data_structures.configuration_handler import ConfigurationHandler +class RelationalGraph: + def __init__(self, config_handler: ConfigurationHandler): + self._handler = config_handler + + self.__generate_adjacency_matrix() + + def __generate_adjacency_matrix(self): + """Generates adjacency matrix from configuration handler object i.e. finds connected DALs + """ + self._adjacency_matrix = np.zeros((self._handler.n_dals, self._handler.n_dals)) + + for i, dal in enumerate(self._handler.conf_obj_list): + for connection_category in self._handler.get_relationships_for_conf_object(dal): + # Allows for multiply connected nodes + for connection in list(connection_category.values())[0]: + # Loop over just conf objects + self._adjacency_matrix[i][self._handler.conf_obj_list.index(connection)] += 1 + + @property + def adjacency_matrix(self)->NDArray: + return self._adjacency_matrix + + @property + def top_level_nodes(self): + # Means we automatically rebuild the graph, this is inefficient but vaguely fine + self.__generate_adjacency_matrix() + return [dal for i, dal in enumerate(self._handler.conf_obj_list) if np.all(self.adjacency_matrix[i])==0] + + +''' +HW: Leaving here for now for posterity, this is a great way to organise a FIXED configuration +but is horribly slow for constant updates + class RelationalGraph: def __init__(self, config_handler: ConfigurationHandler): """Construct relational graph @@ -105,10 +138,10 @@ def __longest_path(self, start_id: int): return dist def __calculate_longest_paths(self)->None: - ''' + """ Idea is to find shortest paths on -G for each top level node where G is the connection graph. Layer each item lives on is then simply max(longest_path) for each top level item - ''' + """ self._topological_ordered_matrix = self.__get_topological_order() for node_id in range(self._handler.n_dals): @@ -116,6 +149,12 @@ def __calculate_longest_paths(self)->None: self._max_distance = self._max_distance.astype(int) + def add_node(self, node_dal): + pass + + def remove_node(self, node_dal): + pass + @property def top_level_nodes(self): # Means we automatically rebuild the graph @@ -123,6 +162,4 @@ def top_level_nodes(self): self.generate_graph() return [dal for i, dal in enumerate(self._handler.conf_obj_list) if self._max_distance[i]==0] - - - \ No newline at end of file +''' \ No newline at end of file