コード例 #1
0
 def partition(self):
     W = self._G.edge_properties["weights"]
     _, P = graph_tool.flow.min_cut(self._G, W)
     label = self._G.new_edge_property('string')
     graph_tool.map_property_values(W, label, lambda w: str(w))
     graph_tool.draw.graph_draw(self._G,
                                edge_pen_width=W,
                                vertex_fill_color=P,
                                edge_text=label,
                                output='/tmp/min_cut.pdf')
     P1, P2 = [], []
     for v, which in enumerate(P):
         x = self._M.f(v)
         if which:
             P1.append(x)
         else:
             P2.append(x)
     return P1, P2
コード例 #2
0
 def partition_flow(self):
     H, s, t = _to_hammock(self._G)
     W = H.edge_properties["weights"]
     R = graph_tool.flow.push_relabel_max_flow(H, s, t, W)
     P = graph_tool.flow.min_st_cut(H, s, W, R)
     label = H.new_edge_property('string')
     graph_tool.map_property_values(W, label, lambda w: str(w))
     graph_tool.draw.graph_draw(H,
                                edge_pen_width=W,
                                vertex_fill_color=P,
                                edge_text=label,
                                output='/tmp/min_cut.pdf')
     P1, P2 = [], []
     for v, which in enumerate(P):
         if v != s and v != t:
             x = self._M.f(v)
             if which:
                 P1.append(x)
             else:
                 P2.append(x)
     return P1, P2
コード例 #3
0
    def process_drawing_properties(self,
                                   graph,
                                   vsize=None,
                                   vlabel=None,
                                   color_by_type=None,
                                   esize=None):
        g = graph
        vcount = len(list(g.vertices()))
        print(vcount)

        #Set output size
        if vcount <= 25:
            self.output_dimension = 500
            vmin = 10
            vmax = 20
            emin = 2
            emax = 8
            font_size = 8
        elif (vcount * 5) >= 30000:
            self.output_dimension = 30000
            vmin = 3
            vmax = 10
            emin = 1
            emax = 5
            font_size = 5
        else:
            self.output_dimension = vcount * 20
            vmin = 10
            vmax = 20
            emin = 2
            emax = 8
            font_size = 8

        self.set_drawing_properties(vertex_font_size=font_size)

        if vsize is not None and type(vsize) == int or type(vsize) == float:
            vertex_size = vsize
            self.set_drawing_properties(vertex_size=vertex_size)
            print('SET HERE')
        elif vsize == 'cscore':
            vertex_size = g.new_vertex_property("double")
            graph_tool.map_property_values(g.vp.cscore, vertex_size,
                                           lambda x: x + 0.1)
            vertex_size = graph_tool.draw.prop_to_size(vertex_size,
                                                       mi=vmin,
                                                       ma=vmax,
                                                       log=False,
                                                       power=0.5)
            self.set_drawing_properties(vertex_size=vertex_size)
        if vlabel == 'title':
            label = g.vp.title
            self.set_drawing_properties(vertex_text=label)
        if color_by_type:
            vertex_color = g.new_vertex_property("string")
            graph_tool.map_property_values(
                g.vp.ns, vertex_color, lambda x: '#2e3436'
                if x == '14.0' else '#a40000')
            self.set_drawing_properties(vertex_fill_color=vertex_color)
        if esize == 'cscore':
            edge_size = g.new_edge_property("double")
            graph_tool.map_property_values(g.ep.cscore, edge_size,
                                           lambda x: x + 0.1)
            edge_size = graph_tool.draw.prop_to_size(edge_size,
                                                     mi=emin,
                                                     ma=emax,
                                                     log=False,
                                                     power=0.5)
            self.set_drawing_properties(edge_pen_width=edge_size)
コード例 #4
0
def process(graph_on, i, k, er, zeta, largest, onepath, twopath, threepath, lc,
            op, tp, thp, p_lc, p_op, p_tp, p_thp, exp_deg, N_vertices,
            N_random_shuffles, time_stops):
    #    start = i * N_random_shuffles
    #    stop = (i+1) * N_random_shuffles

    er.initial_properties(zeta)

    er.process()

    #    graph_draw(er.g_c, vertex_text = er.g_c.vertex_index, vertex_halo = er.g_c.vp.stecaj,vertex_font_size=12, output_size=(600, 600))
    #    print("originalni graf")
    #    er.set_directedness(False)

    one_tot = er.one_path()
    two_tot = er.two_path()
    three_tot = er.three_path()
    largest_tot = er.largest_component()

    original_time = list(er.remember_time())
    l = 0
    while (l < time_stops):
        gt.map_property_values(er.g_c.vertex_index, er.g_c.vp.time,
                               lambda x: original_time[x])
        er.network_part(time_stops, l)
        #        graph_draw(er.g_c, vertex_text = er.g_c.vertex_index, vertex_halo = er.g_c.vp.stecaj,vertex_font_size=12, output_size=(600, 600))
        #        print(er.g_c.num_edges())
        er.only_causal()
        er.g_c.set_edge_filter(er.g_c.ep.causal)
        #        graph_draw(er.g_c, vertex_text = er.g_c.vertex_index, vertex_halo = er.g_c.vp.stecaj,vertex_font_size=12, output_size=(600, 600))
        #        print(er.g_c.num_edges())
        er.set_directedness(False)
        largest[l][k][i].append(er.largest_component() / largest_tot)
        onepath[l][k][i].append(er.one_path() / one_tot)
        twopath[l][k][i].append(er.two_path() / two_tot)
        threepath[l][k][i].append(er.three_path() / three_tot)
        er.g_c.clear_filters()
        er.g_c.set_vertex_filter(er.g_c.vp.t_part)
        er.set_directedness(True)
        er.reset_edges()
        j = 0
        while (j < N_random_shuffles):
            er.shuffle_time()
            er.only_causal()
            er.g_c.set_edge_filter(er.g_c.ep.causal)
            er.set_directedness(False)
            lc[l][k][i].append(er.largest_component() / largest_tot)
            op[l][k][i].append(er.one_path() / one_tot)
            tp[l][k][i].append(er.two_path() / two_tot)
            thp[l][k][i].append(er.three_path() / three_tot)
            er.g_c.clear_filters()
            er.g_c.set_vertex_filter(er.g_c.vp.t_part)
            er.set_directedness(True)
            er.reset_edges()
            j += 1
        er.g_c.clear_filters()
        l += 1

    er.clear_graph()

    #    print(onepath)
    #    print(op)

    l = 0
    while (l < time_stops):
        p_lc[l][k].append(
            stats_and_histo.statistics(
                graph_on, lc[l][k][i], largest[l][k][i],
                r'largest zeta = {0},  network default = {1}%.txt'.format(
                    round(zeta, 3), round(100 * (l + 1) / time_stops, 2)),
                exp_deg, N_vertices, N_random_shuffles, zeta))
        p_op[l][k].append(
            stats_and_histo.statistics(
                graph_on, op[l][k][i], onepath[l][k][i],
                r'onepath zeta = {0} network default = {1}%.txt'.format(
                    round(zeta, 3), round(100 * (l + 1) / time_stops, 2)),
                exp_deg, N_vertices, N_random_shuffles, zeta))
        p_tp[l][k].append(
            stats_and_histo.statistics(
                graph_on, tp[l][k][i], twopath[l][k][i],
                r'twopath zeta = {0} network default = {1}%.txt'.format(
                    round(zeta, 3), round(100 * (l + 1) / time_stops, 2)),
                exp_deg, N_vertices, N_random_shuffles, zeta))
        p_thp[l][k].append(
            stats_and_histo.statistics(
                graph_on, thp[l][k][i], threepath[l][k][i],
                r'threepath zeta = {0} network default = {1}%.txt'.format(
                    round(zeta, 3), round(100 * (l + 1) / time_stops, 2)),
                exp_deg, N_vertices, N_random_shuffles, zeta))
        l += 1
コード例 #5
0
 def shuffle_time(self):
     time_list = self.g_c.vp.time.get_array()
     rnd.shuffle(time_list)
     gt.map_property_values(self.g_c.vertex_index, self.g_c.vp.time,
                            lambda x: time_list[x])