Example #1
0
 def graph_props(self):
     """!
     Several graph properties computed with dfs passage
     """
     if self._props is None:
         self._props = BaseGraphSearcher.depth_first_search(
             self,
             edge_generator=lambda node: BaseGraphOps.edges_of(self, node),
             check_cycle=True,
         )
     return self._props
Example #2
0
    def find_shortest_paths(self, n1: Node) -> Dict[str, Union[dict, set]]:
        """!
        \brief Find shortest path between given node and all other nodes.

        This mostly the same function from Graph with the difference being the
        edge generating function. We consider every edge that is incident with
        nodes not just incoming or outgoing edges.
        """
        return BaseGraphSearcher.breadth_first_search(
            self,
            n1=n1,
            edge_generator=lambda x: BaseGraphOps.edges_of(self, x),
        )
Example #3
0
    def find_maximum_spanning_tree(self, weight_fn=lambda x: 1):
        """!
        \brief obtain maximum weight spanning tree from graph.

        \see find_minimum_spanning_tree()

        \param weight_fn weighting function for edges.
        """
        # t = Tree.find_mst_prim(self, edge_generator=self.edges_of)
        t, L = Tree.find_mnmx_st(
            self,
            edge_generator=lambda x: BaseGraphOps.edges_of(self, x),
            weight_function=weight_fn,
            is_min=False,
        )
        return t, L
Example #4
0
    def find_minimum_spanning_tree(self,
                                   weight_fn: Callable[[Edge],
                                                       int] = lambda x: 1):
        """!
        \brief Obtain the minimum spanning tree of the graph instance

        \param weight_fn weighting function used to extract weights from edges.

        We apply the generic weighted tree extraction algorithm from Tree.
        We consider that the graph is evenly weighted, however if this is not
        the case the weighting function can be used for determining weight of
        each edge.
        """
        # t = Tree.find_mst_prim(self, edge_generator=self.edges_of)
        t, L = Tree.find_mnmx_st(
            self,
            edge_generator=lambda x: BaseGraphOps.edges_of(self, x),
            weight_function=weight_fn,
        )
        return t, L
Example #5
0
 def egen(x):
     return BaseGraphOps.edges_of(self, x)
 def egen(node):
     return BaseGraphOps.edges_of(self.ugraph, node)
Example #7
0
 def test_edges_of(self):
     """"""
     edges = BaseGraphOps.edges_of(self.graph, self.n2)
     self.assertEqual(edges, set([self.e1, self.e2]))