Exemplo n.º 1
0
    def restore_number_edges(self, graph, source, sink, capacity):
        while len(graph.get_edges()) < self.m:
            s = randint(0, self.n)
            t = randint(0, self.n)
            if s == t or s == sink or t == source:
                continue
            if graph.edge(s, t):
                continue

            edge = graph.add_edge(s, t)
            # The capacity will be defined randomly
            cap = randint(1, 15)
            capacity[edge] = cap
            if not self.directed:
                reverse_edge = graph.edge(t, s, add_missing=True)
                capacity[reverse_edge] = cap

        while len(graph.get_edges()) > self.m:
            e = randint(0, len(graph.get_edges()))
            edge = gt.find_edge(graph, graph.edge_index, e)
            if not edge:
                continue
            edge = edge[0]
            s = edge.source()
            t = edge.target()
            if s == t or s == source or t == sink:
                continue

            if edge:
                graph.remove_edge(edge)

                if not self.directed:
                    graph.remove_edge(graph.edge(t, s))

        return graph
Exemplo n.º 2
0
 def get_path(self, target=None):
     tar = target if target else self.found if self.found else self.target
     path = []
     while self.predecessor[tar] >= 0:
         edge = gt.find_edge(self.graph, self.graph.edge_index,
                             self.edge[tar])[0]
         path.append(edge)
         tar = self.predecessor[tar]
     return list(reversed(path))
Exemplo n.º 3
0
def dms_network(n, seed=None):
    if seed:
        rnd.seed(seed)

    g = gt.Graph(directed=False)
    v1 = g.add_vertex()
    v2 = g.add_vertex()
    v3 = g.add_vertex()
    g.add_edge(v1, v2)
    g.add_edge(v2, v3)
    g.add_edge(v3, v1)
    edges = 2

    for _ in range(n - 3):
        new_v = g.add_vertex()
        e = gt.find_edge(g, g.edge_index, rnd.randint(0, edges))[0]
        g.add_edge(e.source(), new_v)
        g.add_edge(new_v, e.target())
        edges += 1

    return g
Exemplo n.º 4
0
    def _update_junctions_grad(self):

        self.grad_wy.a = 0.
        self.grad_ix.a = 0.
        self.grad_zed.a = 0.
        # Radial tension
        radial = self.junctions.radial_tensions.a
        self.grad_ix.a += radial * self.ixs.a / self.rhos.a
        self.grad_wy.a += radial * self.wys.a / self.rhos.a
        self.grad_zed.a += radial * self.zeds.a / self.rhos.a

        # Contribution from junction edges
        for j_edge in self.junctions:
            self._update_edge_grad(j_edge)

        # Contribution from neighboring cells
        for ctoj_edge in gt.find_edge(self.graph, self.is_ctoj_edge, True):
            cell, j_vert = ctoj_edge
            gc_x, gc_y, gc_z = self.volume_grad_cell[cell]
            self.grad_ix[j_vert] += gc_x
            self.grad_wy[j_vert] += gc_y
            self.grad_zed[j_vert] += gc_z
Exemplo n.º 5
0
    def _update_junctions_grad(self):

        self.grad_wy.a = 0.
        self.grad_ix.a = 0.
        self.grad_zed.a = 0.
        # Radial tension
        radial = self.junctions.radial_tensions.a
        self.grad_ix.a += radial * self.ixs.a / self.rhos.a
        self.grad_wy.a += radial * self.wys.a / self.rhos.a
        self.grad_zed.a += radial * self.zeds.a / self.rhos.a

        # Contribution from junction edges
        for j_edge in self.junctions:
            self._update_edge_grad(j_edge)

        # Contribution from neighboring cells
        for ctoj_edge in gt.find_edge(self.graph, self.is_ctoj_edge, True):
            cell, j_vert = ctoj_edge
            gc_x, gc_y, gc_z = self.volume_grad_cell[cell]
            self.grad_ix[j_vert] += gc_x
            self.grad_wy[j_vert] += gc_y
            self.grad_zed[j_vert] += gc_z
Exemplo n.º 6
0
 def edge_st(self, edge):
     '''Returns a tuple of source/target of the given edge'''
     if isinstance(edge, gt.Edge):
         return (edge.source(), edge.target())
     e = gt.find_edge(self.graph, self.graph.edge_index, edge)[0]
     return (e.source(), e.target())
Exemplo n.º 7
0
 def local_junctions(self):
     for edge in gt.find_edge(self.eptm.graph, self.eptm.is_local_edge, 1):
         if self.eptm.is_junction_edge[edge]:
             yield edge
Exemplo n.º 8
0
 def local_junctions(self):
     for edge in gt.find_edge(self.eptm.graph,
                              self.eptm.is_local_edge, 1):
         if self.eptm.is_junction_edge[edge] :
             yield edge