Example #1
0
 def extract_path(
     self,
     start: Node,
     end: Node,
     filter_fn: Callable[[Set[Edge], str], Set[Edge]] = lambda es, n: set(
         [e for e in es if e.start().id() == n]),
     costfn: Callable[[Edge, float], float] = lambda x, y: y + 1.0,
     is_min=True,
 ):
     """"""
     if (BaseGraphOps.is_in(self, start) is False
             or BaseGraphOps.is_in(self, end) is False):
         raise ValueError("start or end node is not inside tree")
     #
     upset = self.upset_of(start)
     if end not in upset:
         raise ValueError("end node is not in upset of start.")
     downset = self.downset_of(end)
     upset_edges = set()
     for u in upset:
         for e in BaseGraphOps.outgoing_edges_of(self, u):
             upset_edges.add(e)
     downset_edges = set()
     for d in downset:
         for e in BaseGraphOps.outgoing_edges_of(self, d):
             downset_edges.add(e)
     problem_set = upset_edges.intersection(downset_edges)
     ucs_path = Path.from_ucs(
         g=self,
         goal=end,
         start=start,
         filter_fn=filter_fn,
         costfn=costfn,
         is_min=is_min,
         problem_set=problem_set,
     )
     return ucs_path
Example #2
0
 def egen(x):
     return BaseGraphOps.outgoing_edges_of(self, x)
Example #3
0
 def test_outgoing_edges_of_1(self):
     """"""
     out_edges1 = BaseGraphOps.outgoing_edges_of(self.graph_2, self.n1)
     comp1 = frozenset([self.e1, self.e4])
     self.assertEqual(out_edges1, comp1)
Example #4
0
 def test_outgoing_edges_of_2(self):
     """"""
     out_edges2 = BaseGraphOps.outgoing_edges_of(self.graph_2, self.n2)
     comp2 = frozenset([self.e2])
     self.assertEqual(out_edges2, comp2)
Example #5
0
 def test_outgoing_edges_of(self):
     """"""
     edges = BaseGraphOps.outgoing_edges_of(self.graph, self.n2)
     self.assertEqual(edges, frozenset([self.e2, self.e1]))