Beispiel #1
0
    def main(self, filename):

        # #拿到图
        initG = commons.get_networkByFile(filename)
        max_sub_graph = commons.judge_data(initG)
        # source_list = product_sourceList(max_sub_graph, 2)
        source_list = commons.product_sourceList(max_sub_graph, 1)
        # print('两个节点的距离', nx.shortest_path_length(max_sub_graph, source=source_list[0], target=source_list[1]))
        infectG, T = commons.propagation1(max_sub_graph, source_list)
        infectG1, T = commons.propagation1(max_sub_graph, source_list)
        subinfectG = commons.get_subGraph_true(infectG)  # 只取感染点,为2表示,真实的感染图。
        # 将在这里进行单源测试。

        subinfectG1 = commons.get_subGraph_true(infectG1)

        # 多个观察点
        result_node = self.mutiple_Observation(infectG, subinfectG,
                                               subinfectG1, source_list[0])

        print('真实源是', source_list[0])
        print('预测源是', result_node[0])
        distance = nx.shortest_path_length(subinfectG,
                                           source=source_list[0],
                                           target=result_node[0])
        print('结果是', distance)
        return distance
Beispiel #2
0
    def main(self, dir):
        '''
            走来不要那么难,先搞定树吧。才能继续搞定图。
            :return:
            '''
        pre = '../../data/'
        last = '.txt'
        self.initG = commons.get_networkByFile(fileName=pre + dir +
                                               last)  # 获取图,
        max_sub_graph = commons.judge_data(self.initG)
        source_list = commons.product_sourceList(max_sub_graph,
                                                 self.fix_number_source)
        self.true_Source_list = source_list
        self.infectG = commons.propagation1(max_sub_graph,
                                            self.true_Source_list)  # 开始传染

        subinfectG = commons.get_subGraph(self.infectG)
        subinfectG.to_undirected()
        subinfectG.remove_edges_from(subinfectG.selfloop_edges())
        data = nx.core_number(subinfectG)

        # Graph.to_undirected()
        print('data', data)
        data_sort = sorted(data.items(), key=lambda x: x[1], reverse=True)
        print('data_sort', data_sort)
        print('max-core', data_sort[0][1])
        core_number1 = 0
        #看下源点在那一层。
        for node, core_number in data_sort:
            if node in source_list:
                print('node,core_number', [node, core_number])
                core_number1 = core_number
        return core_number1
    def main(self, dir):
        '''
        :return:
        '''
        # filename= '../data/treenetwork3000.txt' #半径为40
        # 对于树图,以及普通图。参数可能设置不一样,h变换不一样。需要手动调整。

        # dir = './data_center/treenetwork3000.txt'
        pre = '../data/'
        last = '.txt'
        # filename = ''
        # self.get_networkByFile(fileName=pre + dir + last)  # 获取图,
        self.radius = 6  #CA-GRQC半径。
        # self.get_networkByFile(fileName=filename)  # 获取图,

        self.initG = commons.get_networkByFile(fileName=pre + dir +
                                               last)  # 获取图,
        max_sub_graph = commons.judge_data(self.initG)
        source_list = commons.product_sourceList(max_sub_graph,
                                                 self.fix_number_source)
        self.true_Source_list = source_list
        self.infectG = commons.propagation1(self.initG,
                                            self.true_Source_list)  # 开始传染

        # self.revsitionAlgorithm_pre(self.infectG)  # 找到反转算法后的生成答案点
        self.cal_BFS_monte_Carlo('./data_center/' + dir +
                                 '.txt')  # 找到结果后构建BFS树,进行采样判断覆盖率。
        self.cal_reverse_algorithm(self.infectG)  # 找到反转算法后的生成答案点
        self.distance_error = commons.cal_distance(self.infectG,
                                                   self.true_Source_list,
                                                   self.findSource_list)
    def main(self):
        initG = commons.get_networkByFile('../../../data/CA-GrQc.txt')
        # initG = commons.get_networkByFile('../../../data/treenetwork3000.txt')

        max_sub_graph = commons.judge_data(initG)
        # source_list = product_sourceList(max_sub_graph, 2)

        source_list = commons.product_sourceList(max_sub_graph, 1)

        # print('查看两源距离')
        # print('distance',nx.shortest_path_length(max_sub_graph,source=source_list[0],target=source_list[1]))
        infectG = commons.propagation1(max_sub_graph, source_list)
        subinfectG = commons.get_subGraph(infectG)
        '''
        思路,单源定位,看看单源定位和覆盖率效果。
        '''
        # singleRegionList = list(subinfectG.nodes)
        #进行覆盖率走,并进行jaya算法。
        test_source_list = commons.revsitionAlgorithm_singlueSource(subinfectG)
        print('souce     target', [source_list[0], test_source_list])
        print(
            'result',
            nx.shortest_path_length(infectG,
                                    source=test_source_list[0],
                                    target=source_list[0]))
        return nx.shortest_path_length(infectG,
                                       source=source_list[0],
                                       target=test_source_list[0])
Beispiel #5
0
    def main(self, filename):

        # #拿到图
        initG = commons.get_networkByFile(filename)
        max_sub_graph = commons.judge_data(initG)
        print('是否是一棵树?', nx.is_tree(max_sub_graph))
        # source_list = product_sourceList(max_sub_graph, 2)
        source_list = self.produce_source(max_sub_graph, 1)
        # print('两个节点的距离', nx.shortest_path_length(max_sub_graph, source=source_list[0], target=source_list[1]))
        infectG, T = commons.propagation1(max_sub_graph, source_list)

        subinfectG = commons.get_subGraph_true(infectG)  # 只取感染点,为2表示,真实的感染图。
        # 将在这里进行单源测试。
        '''   第一种,就是jarden center '''
        #
        object_single = single_Source_detection.Single_source()
        reverse_node = object_single.revsitionAlgorithm_singlueSource(
            subinfectG)
        result_node = self.single_source_bound_ture(subinfectG,
                                                    reverse_node[0],
                                                    source_list[0])
        print('真实源是', source_list[0])
        print('预测源是', result_node[0])
        distance = nx.shortest_path_length(subinfectG,
                                           source=source_list[0],
                                           target=result_node[0])
        print('结果是', distance)
        return distance
    def main(self, dir):
        '''
        :return:
        '''
        # filename= 'treenetwork3000.txt' #半径为40
        #对于树图,以及普通图。参数可能设置不一样,h变换不一样。需要手动调整。
        # filename = 'CA-GrQc.txt'
        self.radius = 6

        pre = '../data/'
        last = '.txt'
        # filename = ''
        self.initG = commons.get_networkByFile(fileName=pre + dir +
                                               last)  # 获取图,
        max_sub_graph = commons.judge_data(self.initG)
        source_list = commons.product_sourceList(max_sub_graph,
                                                 self.fix_number_source)
        self.true_Source_list = source_list
        self.infectG = commons.propagation1(self.initG,
                                            self.true_Source_list)  # 开始传染
        self.revsitionAlgorithm_pre(self.infectG)  # 找到反转算法后的生成答案点
        self.cal_BFS_monte_Carlo()  # 找到最好的覆盖率结果。
        self.cal_reverse_algorithm(self.infectG)  # 找到反转算法后的生成答案点
        self.distance_error = commons.cal_distance(self.infectG,
                                                   self.true_Source_list,
                                                   self.findSource_list)
    def main(self):
        initG = commons.get_networkByFile('../../../data/CA-GrQc.txt')
        # initG = commons.get_networkByFile('../../../data/treenetwork3000.txt')

        max_sub_graph = commons.judge_data(initG)
        # source_list = product_sourceList(max_sub_graph, 2)

        source_list = commons.product_sourceList(max_sub_graph, 2)

        print('查看两源距离')
        print(
            'distance',
            nx.shortest_path_length(max_sub_graph,
                                    source=source_list[0],
                                    target=source_list[1]))
        infectG = commons.propagation1(max_sub_graph, source_list)
        subinfectG = commons.get_subGraph(infectG)
        '''
        思路,单源定位,看看单源定位效果。
        '''

        test_source_list = commons.revsitionAlgorithm_get_goodnode(subinfectG)
        print('test_soucce_list')
        if set(test_source_list) > set(source_list):
            print('是的,是真子集。')
Beispiel #8
0
    def main(self, filename):

        # #拿到图
        initG = commons.get_networkByFile(filename)

        # ecc=nx.eccentricity(initG)
        # sort_ecc=sorted(ecc.items(),key=lambda  x:x[1])
        # product_srouce =sort_ecc[0][0]
        max_sub_graph = commons.judge_data(initG)
        # source_list = product_sourceList(max_sub_graph, 2)
        source_list = commons.product_sourceList(max_sub_graph, 1)
        # print('两个节点的距离', nx.shortest_path_length(max_sub_graph, source=source_list[0], target=source_list[1]))
        infectG, T = commons.propagation1(max_sub_graph, [1000])
        # infectG1, T = commons.propagation1(max_sub_graph, [source_list])
        subinfectG = commons.get_subGraph_true(infectG)  # 只取感染点,为2表示,真实的感染图。
        #将在这里进行单源测试。
        print(sorted(list(subinfectG.nodes())))
        #
        # result_node = self.revsitionAlgorithm_singlueSource(subinfectG)
        # ''' 第二种,就是coverage/distance'''
        # result_node= self.single_source_bydistance_coverage(infectG,subinfectG,source_list[0])
        # '''  第3种,距离中心'''
        # result_node = self.single_source_bydistance( subinfectG)

        #'''  第6种,质量距离中心'''
        # result_node = self.single_source_byQuality_centrality(infectG,subinfectG)

        # #''''第7种,特征向量中心性
        # result_node = self.single_source_bybetweenness_centrality( subinfectG)
        # #''''第8种,反转加t性
        # result_node = self.single_source_get_T_jarden_center( T,subinfectG)

        #第9种,谣言中心性‘’

        result_node = self.rumor_center(infectG, subinfectG, 1000)

        #
        # # #’‘ 乔丹中心性
        #   result_node = self.jarden_cente_networkx(infectG,subinfectG,source_list[0])

        # 覆盖率加我们的操作
        # result_node = self.coverage_BFS_single_source(infectG,subinfectG,source_list[0])

        # #多个观察点
        # result_node = self.coverage_BFS_single_source(infectG,subinfectG,source_list[0])

        #基于覆盖率的计算方式

        # result_node = self.belief_algorithm(infectG, subinfectG,1000)
        print('真实源是', source_list[0])
        # print('预测源是',result_node[0])
        distance = nx.shortest_path_length(subinfectG,
                                           source=1000,
                                           target=result_node[0])
        print('结果他们的距离是', distance)
        return distance
Beispiel #9
0
    def main(self, filename):
        # #拿到图
        # subGraph=self.get_Graph('../Propagation_subgraph/many_methods/result/chouqu.txt')

        # initG = commons.get_networkByFile('../../../data/CA-GrQc.txt')
        # initG = commons.get_networkByFile('../../../data/3regular_tree1000.txt')
        # initG = commons.get_networkByFile('../../data/4_regular_graph_3000_data.txt')

        initG = commons.get_networkByFile(filename)
        # initG = commons.get_networkByFile('../../../data/4_regular_graph_3000_data.txt')

        # initG = commons.get_networkByFile('../../../data/email-Eu-core.txt')

        max_sub_graph = commons.judge_data(initG)
        # source_list = product_sourceList(max_sub_graph, 2)
        source_list = commons.product_sourceList(max_sub_graph, 2)
        # print('两个节点的距离', nx.shortest_path_length(max_sub_graph, source=source_list[0], target=source_list[1]))
        infectG = commons.propagation1(max_sub_graph, source_list)

        # subinfectG = commons.get_subGraph_true(infectG)  # 只取感染点,为2表示,真实的感染图。
        single_Source_detection_object = single_Source_detection.Single_source(
        )
        '''
        底下将是所有的步骤组合操作。目前是2源的。
        1  抽取子图操作
        2  分区
        3 分别多源定位
        '''

        # 1  抽取子图操作,共有3种抽取子图操作。我们选择那3种呢?
        subinfectG = commons.get_subGraph_true(infectG)  # 只取感染点,为2表示,真实的感染图。
        '''''' '# 2 分区,分区的太多了,我们看看那种好。' ''

        result = self.findmultiplesource(infectG, subinfectG, sourceNumber=2)

        result_source_list = []
        for community in result:
            subsubinfectG = nx.Graph()
            for edge in list(subinfectG.edges()):
                if edge[0] in community and (edge[1] in community):
                    subsubinfectG.add_edge(edge[0], edge[1])
            # 看下图连通吗。
            maxsubsubinfectG = self.judge_data(subsubinfectG)
            # 开始单源定位了。
            '''jar center'''
            source_node = single_Source_detection_object.revsitionAlgorithm_singlueSource(
                maxsubsubinfectG)
            # source_node = single_Source_detection_object.single_source_bydistance_coverage(infectG, maxsubsubinfectG)
            result_source_list.append(source_node[0])

        distance = commons.cal_distance(max_sub_graph, source_list,
                                        result_source_list)

        return distance
Beispiel #10
0
    def main(self, filename, method):

        # #拿到图
        initG = commons.get_networkByFile(filename)
        max_sub_graph = commons.judge_data(initG)
        # source_list = product_sourceList(max_sub_graph, 2)
        source_list = commons.product_sourceList(max_sub_graph, 1)
        # print('两个节点的距离', nx.shortest_path_length(max_sub_graph, source=source_list[0], target=source_list[1]))
        infectG = commons.propagation1(max_sub_graph, source_list)
        subinfectG = commons.get_subGraph_true(infectG)  # 只取感染点,为2表示,真实的感染图。
        # 将在这里进行种子节点覆盖。
        ''' 第1种,就是coverage/distance'''
        func = getattr(self, method)
        sort_partion = func(infectG, subinfectG, source_list[0])
        return sort_partion
Beispiel #11
0
 def main(self,dir):
     '''
     走来不要那么难,先搞定树吧。才能继续搞定图。
     :return:
     '''
     pre = '../data/'
     last = '.txt'
     # filename = ''
     self.initG = commons.get_networkByFile(fileName=pre+dir+last)  # 获取图,
     max_sub_graph = commons.judge_data( self.initG)
     source_list = commons.product_sourceList(max_sub_graph, self.fix_number_source)
     self.true_Source_list = source_list
     self.infectG = commons.propagation1(max_sub_graph,self.true_Source_list)  # 开始传染
     self.cal_ecctity()      #找到最好的覆盖率结果。
     self.cal_reverse_algorithm(self.infectG)  # 找到反转算法后的生成答案点
     self.distance_error = commons.cal_distance(self.infectG, self.true_Source_list, self.findSource_list)
Beispiel #12
0
    def main(self):
        initG = commons.get_networkByFile('../../data/CA-GrQc.txt')
        max_sub_graph = commons.judge_data(initG)
        # source_list = product_sourceList(max_sub_graph, 2)

        source_list = commons.product_sourceList(max_sub_graph,
                                                 commons.fix_number_source)
        infectG = commons.BFS_coverage(max_sub_graph, source_list)
        subinfectG = commons.get_subGraph(infectG)
        #求解中心性
        pre = '../data_center/'
        last = '.txt'
        filname = 'CA-GrQc'
        center_list = commons.get_center_list(subinfectG)
        print('center_list', center_list)
        dfs_result_dict = defaultdict(list)
        #对每个节点都做BFS,从而判断真实源点在BFS那一层。
        result = []
        for center in center_list:
            temp = []
            # commons.test_BFS_node(subinfectG, source = center,)
            dfs_result_dict = commons.test_BFS_node(subinfectG,
                                                    source_node=center,
                                                    depth=7)
            print('dfs_result_dict', dfs_result_dict)
            for source in source_list:
                for depth, depth_list in dfs_result_dict.items():
                    if source in depth_list:
                        temp.append([center, source, depth])
            result.append(temp)
        print(result)
        variance_list = []
        #使用方差计算。
        for every_ecc in result:
            distemp = [i[2] for i in every_ecc]  #收集每种中心性的方差,方差越小越好。
            # 求标准差
            arr_std = np.std(distemp, ddof=1)
            variance_list.append(arr_std)
        print('variancelist,每次的结果', variance_list)
        with open('./result_bfs.txt', "a") as f:
            # f.write("这是个测试!")  # 这句话自带文件关闭功能,不需要再写f.close()
            f.write(str(time.asctime(time.localtime(time.time()))) + '\n')
            f.write(
                str(variance_list).replace('[', '').replace(']', '') + '\n')
        return variance_list
    def main(self):
        # initG = commons.get_networkByFile('../../../data/CA-GrQc.txt')
        initG = commons.get_networkByFile('../../../data/Wiki-Vote.txt')

        max_sub_graph = commons.judge_data(initG)
        source_list = commons.product_sourceList(max_sub_graph, 3)
        infectG, progration_number, y_list1 = self.get_paogration(
            max_sub_graph, source_list)
        y_list2 = [0 for i in range(progration_number + 1)]
        y_list2node = [[] for i in range(progration_number + 1)]
        for source_index in range(len(source_list)):
            temp, node_list_temp = self.get_BFS(max_sub_graph,
                                                source_list[source_index],
                                                progration_number)
            # print('temp', temp)
            for index in range(len(node_list_temp)):
                y_list2node[index].extend(node_list_temp[index])

        # y_list2node这个list中每一项可能有重复感染的,需要求差级。
        temp_all = []
        temp_all.extend(y_list2node[0])
        y_list2[0] = len(set(temp_all))
        print(y_list2[0])
        for i in range(1, len(y_list2node)):
            # ist(set(t) - set(s))
            c = list(set(y_list2node[i]) - set(temp_all))  # 求差集(项在t中,但不在s中
            y_list2[i] = len(set(c))
            temp_all.extend(y_list2node[i])

        print(y_list2)

        # print(len(y_list2))
        # print(len(y_list1))
        Probability = 0.5
        self.plot(range(len(y_list1)), y_list1, 'progration', Probability)
        self.plot(range(len(y_list1)), y_list2, 'bfs', Probability)
        self.plot_plus(range(len(y_list2)), y_list1, y_list2, 'every_t',
                       Probability)
        self.plot_sum_increase(range(len(y_list2)), y_list1, y_list2, 'sum',
                               Probability)
Beispiel #14
0
    def main(self):
        initG = commons.get_networkByFile('../../../data/CA-GrQc.txt')
        max_sub_graph = commons.judge_data(initG)
        # source_list = product_sourceList(max_sub_graph, 2)

        source_list = commons.product_sourceList(max_sub_graph, 1)
        infectG = commons.propagation1(max_sub_graph, source_list)
        subinfectG = commons.get_subGraph(infectG)
        '''
        思路,单源定位,看看单源定位效果。
        '''

        test_source_list=commons.revsitionAlgorithm_singlueSource(subinfectG)
        print('test_soucce_list')
        min = 8
        for  soucre  in test_source_list:
            distance =nx.shortest_path_length(infectG,source=soucre,target=source_list[0])
            if distance<= min:
                min = distance
        print('最小距离是', min)
        print('variancelist,每次的结果', min)
        return min
Beispiel #15
0
    def main(self):
        initG = commons.get_networkByFile('../../../data/CA-GrQc.txt')
        # initG = commons.get_networkByFile('../../../data/treenetwork3000.txt')

        max_sub_graph = commons.judge_data(initG)
        # source_list = product_sourceList(max_sub_graph, 2)

        source_list = commons.product_sourceList(max_sub_graph, 1)

        # print('查看两源距离')
        # print('distance',nx.shortest_path_length(max_sub_graph,source=source_list[0],target=source_list[1]))
        infectG = commons.propagation1(max_sub_graph, source_list)
        subinfectG = commons.get_subGraph(infectG)

        singleRegionList = list(subinfectG.nodes)
        '''
        思路,单源定位,看看单源定位和覆盖率效果。
        '''
        # 再从真实源点看,真实源点的覆盖率是多少?
        TrueCoverage = commons.jayawith_dynami_H_TrueSource(
            infectG, source_list, 1, [4, 5, 6, 7, 8, 9, 10], singleRegionList)
        print('True_Source_Coverage', TrueCoverage)
        #进行覆盖率走,并进行jaya算法。
        results = commons.jayawith_dynami_H(infectG, singleRegionList, 1,
                                            [4, 5, 6], singleRegionList)
        print('good_coverage_soucre', results)

        with open('result_coverage_compare.txt', "a") as f:
            # f.write("这是个测试!")  # 这句话自带文件关闭功能,不需要再写f.close()
            f.write(str(time.asctime(time.localtime(time.time()))) + '\n')
            f.write('覆盖率比较结果,真实源点' + str(TrueCoverage[2]) + '\n')
            f.write('覆盖率比较结果,找到的覆盖率比较好的点' + str(results[2]) + '\n')
            f.write('两者距离   ' + str(
                nx.shortest_path_length(
                    infectG, source=source_list[0], target=results[0][0])) +
                    '\n')
    def main(self):
        # initG = commons.get_networkByFile('../../../data/CA-GrQc.txt')

        initG = commons.get_networkByFile('../../../data/Wiki-Vote.txt')

        max_sub_graph = commons.judge_data(initG)
        source_list = commons.product_sourceList(max_sub_graph, 1)
        infectG, progration_number, y_list1 = self.get_paogration(
            max_sub_graph, source_list)
        # print('progration_number',progration_number)
        # print('len(y_list1)',len(y_list1))

        print('y_list1', y_list1)
        y_list2 = self.get_BFS(max_sub_graph, source_list[0],
                               progration_number)
        print(len(y_list2))
        print(len(y_list1))
        Probability = 0.5
        self.plot(range(len(y_list1)), y_list1, 'progration', Probability)
        self.plot(range(len(y_list1)), y_list2, 'bfs', Probability)
        self.plot_plus(range(len(y_list2)), y_list1, y_list2, 'every_t',
                       Probability)
        self.plot_sum_increase(range(len(y_list2)), y_list1, y_list2, 'sum',
                               Probability)
Beispiel #17
0
    def main(self, filename):
        # #拿到图
        # subGraph=self.get_Graph('../Propagation_subgraph/many_methods/result/chouqu.txt')

        # initG = commons.get_networkByFile('../../../data/CA-GrQc.txt')
        # initG = commons.get_networkByFile('../../../data/3regular_tree1000.txt')
        # initG = commons.get_networkByFile('../../data/4_regular_graph_3000_data.txt')

        initG = commons.get_networkByFile(filename)
        # initG = commons.get_networkByFile('../../../data/4_regular_graph_3000_data.txt')

        # initG = commons.get_networkByFile('../../../data/email-Eu-core.txt')

        max_sub_graph = commons.judge_data(initG)
        # source_list = product_sourceList(max_sub_graph, 2)
        source_list = commons.product_sourceList(max_sub_graph, 2)
        # print('两个节点的距离', nx.shortest_path_length(max_sub_graph, source=source_list[0], target=source_list[1]))
        infectG = commons.propagation1(max_sub_graph, source_list)

        subinfectG = commons.get_subGraph_true(infectG)  # 只取感染点,为2表示,真实的感染图。
        '''
        底下将是所有的步骤组合操作。目前是2源的。
        1  抽取子图操作
        2  分区
        3 分别多源定位
        '''

        # 1  抽取子图操作,共有3种抽取子图操作。我们选择那3种呢?
        subinfectG = commons.get_subGraph_true(infectG)  # 只取感染点,为2表示,真实的感染图。
        '''''' '# 2 分区,分区的太多了,我们看看那种好。' ''

        result = self.findmultiplesource(infectG, subinfectG, sourceNumber=2)

        distance = commons.cal_distance(max_sub_graph, source_list, result)

        return distance
        # up_message的第一项是它作为子树的节点个数,第二项是子树上所有节点的子树个数的乘积。
        '''
        注意这里的upmessage——dict——temp参数已经变了。
        '''
        down_messages_dict_temp,jordan_center = self.jordan_centrality_down(root_node, root_node,
                                                                  root_node,infectG,upmessage_dict_temps)
        print('down_message_dict_temp',down_messages_dict_temp)
        print('down_message_dict_temp',down_messages_dict_temp[jordan_center])
        print(upmessage_dict_temps[jordan_center])
        return jordan_center



if __name__ == '__main__':
    # #拿到图
    initG = commons.get_networkByFile('../../../data/3regular_tree9.txt')
    max_sub_graph = commons.judge_data(initG)
    # source_list = product_sourceList(max_sub_graph, 2)
    source_list = commons.product_sourceList(max_sub_graph, 1)
    # print('两个节点的距离', nx.shortest_path_length(max_sub_graph, source=source_list[0], target=source_list[1]))
    infectG, T = commons.propagation1(max_sub_graph,source_list)
    # infectG1, T = commons.propagation1(max_sub_graph, [source_list])
    subInfectG = commons.get_subGraph_true(infectG)  # 只取感染点,为2表示,真实的感染图。

    # result_node = rumor_center(infectG, subinfectG, source_list[0])

    # 将图构造成两个list,一个是感染点list,一个是感染和它的邻居点构造成的list
    # infect_node = []
    # infect_neighbour_list = []
    # print(infectG.number_of_nodes())
    # random_node = random.choice(list(subInfectG.nodes()))
    def main(self, filename):
        # #拿到图
        # subGraph=self.get_Graph('../Propagation_subgraph/many_methods/result/chouqu.txt')

        # initG = commons.get_networkByFile('../../../data/CA-GrQc.txt')
        # initG = commons.get_networkByFile('../../../data/3regular_tree1000.txt')
        initG = commons.get_networkByFile(filename)

        # initG = commons.get_networkByFile('../../../data/CA-GrQc.txt')
        # initG = commons.get_networkByFile('../../../data/4_regular_graph_3000_data.txt')

        # initG = commons.get_networkByFile('../../../data/email-Eu-core.txt')

        max_sub_graph = commons.judge_data(initG)
        # source_list = product_sourceList(max_sub_graph, 2)
        source_list = commons.product_sourceList(max_sub_graph, 2)
        # print('两个节点的距离', nx.shortest_path_length(max_sub_graph, source=source_list[0], target=source_list[1]))
        infectG = commons.propagation1(max_sub_graph, source_list)

        subinfectG = commons.get_subGraph_true(infectG)  # 只取感染点,为2表示,真实的感染图。
        self.judge_data(subinfectG)
        '''
        思路:
        1  借助概率p= 0,5以及不同的时间t生成大量的集合。假设知道时间吧。
        2 然后用这些集合去覆盖感染区域,尽可能让blue中点多,而红色区域少。
            这种方法还可以用来确定种子节点的。

        '''

        # 1  抽取子图操作,共有3种抽取子图操作。我们选择那3种呢?
        subinfectG = commons.get_subGraph_true(infectG)  # 只取感染点,为2表示,真实的感染图。
        '''''' '# 2 分区,分区的太多了,我们看看那种好。' ''
        partion_graph_object = Partion_graph.Partion_graph()

        #开始分区,怎么分呢?
        #根据边界节点来。两部分的边界节点,能够找到两个点使得他们到边界点的距离最短?

        #
        # result = partion_graph_object.other_k_center(infectG, subinfectG, source_list, source_number=2)
        #

        # single_source = commons.revsitionAlgorithm_singlueSource(subinfectG)
        distance_iter = nx.shortest_path_length(subinfectG)
        everynode_distance = []
        for node, node_distance in distance_iter:
            # print(node_distance)
            sort_list = sorted(node_distance.items(),
                               key=lambda x: x[1],
                               reverse=True)
            # print('sort_list',sort_list)
            everynode_distance.append([node, sort_list[0][0], sort_list[0][1]])
        # print('everynode_idstance',everynode_distance)
        sort_every_distance = sorted(everynode_distance,
                                     key=lambda x: x[2],
                                     reverse=True)
        print('sort_every_distance', sort_every_distance)

        #从两个最远的点进行BFS直到找到单源的位置。

        # print(nx.shortest_path_length(infectG,source=single_source[0],target=sort_every_distance[0][0]))
        # print(nx.shortest_path_length(infectG, source=single_source[0], target=sort_every_distance[0][1]))
        #
        # print(nx.shortest_path_length(infectG, source=single_source[0], target=sort_every_distance[1][0]))
        # print(nx.shortest_path_length(infectG, source=single_source[0], target=sort_every_distance[1][1]))
        #
        # print(nx.shortest_path_length(infectG, source=single_source[0], target=sort_every_distance[2][0]))
        # print(nx.shortest_path_length(infectG, source=single_source[0], target=sort_every_distance[2][1]))

        # #根据最远得点,把我们的那个啥,分区,然后利用分区点进行单源定位。。
        node_twolist = [[], []]
        lengthA_dict = nx.single_source_bellman_ford_path_length(
            subinfectG, sort_every_distance[0][0], weight='weight')
        lengthB_dict = nx.single_source_bellman_ford_path_length(
            subinfectG, sort_every_distance[0][1], weight='weight')
        for node in list(subinfectG.nodes):
            if lengthA_dict[node] > lengthB_dict[node]:  # 这个点离b近一些。
                node_twolist[1].append(node)
            elif lengthA_dict[node] < lengthB_dict[node]:
                node_twolist[0].append(node)
            # else:
            #     node_twolist[0].append(node)
            #     node_twolist[1].append(node)
        print('len(node_twolist[0]', len(node_twolist[0]))
        print('len(node_twolist[1]', len(node_twolist[1]))
        # 边界点。
        bound_list = []
        for node_temp in list(infectG.nodes()):
            # print(node_temp)
            if infectG.node[node_temp]['SI'] == 2:
                neighbors_list = list(nx.neighbors(infectG, node_temp))
                neighbors_infect_list = [
                    x for x in neighbors_list if infectG.node[x]['SI'] == 2
                ]
                if len(neighbors_list) != 1 and len(
                        neighbors_infect_list) == 1:
                    # if  len(neighbors_infect_list) == 1:
                    bound_list.append(node_temp)

        print('boundelist', len(bound_list))

        print('len(kjlk)',
              len([x for x in bound_list if x in list(subinfectG.nodes())]))
        left = [x for x in bound_list if x in node_twolist[0]]
        right = [x for x in bound_list if x in node_twolist[1]]

        print('left', left)
        print('right', right)

        left_source = commons.revsitionAlgorithm_singlueSource_receive(
            subinfectG, left)
        right_source = commons.revsitionAlgorithm_singlueSource_receive(
            subinfectG, right)
        if set(left) < set(list(subinfectG.nodes())):
            print('left在感染点里面啊')
        if set(right) < set(list(subinfectG.nodes())):
            print('left在感染点里面啊')
        distance = commons.cal_distance(infectG,
                                        [left_source[0], right_source[0]],
                                        source_list)

        return distance
Beispiel #20
0
    def main(self, filename):
        # #拿到图
        # subGraph=self.get_Graph('../Propagation_subgraph/many_methods/result/chouqu.txt')

        # initG = commons.get_networkByFile('../../../data/CA-GrQc.txt')
        # initG = commons.get_networkByFile('../../../data/3regular_tree1000.txt')
        initG = commons.get_networkByFile(filename)

        # initG = commons.get_networkByFile('../../../data/CA-GrQc.txt')
        # initG = commons.get_networkByFile('../../../data/4_regular_graph_3000_data.txt')

        # initG = commons.get_networkByFile('../../../data/email-Eu-core.txt')

        max_sub_graph = commons.judge_data(initG)
        # source_list = product_sourceList(max_sub_graph, 2)
        source_list = commons.product_sourceList(max_sub_graph, 2)
        # print('两个节点的距离', nx.shortest_path_length(max_sub_graph, source=source_list[0], target=source_list[1]))
        infectG = commons.propagation1(max_sub_graph, source_list)

        subinfectG = commons.get_subGraph_true(infectG)  # 只取感染点,为2表示,真实的感染图。
        self.judge_data(subinfectG)

        # single_source = commons.revsitionAlgorithm_singlueSource(subinfectG)
        distance_iter = nx.shortest_path_length(subinfectG)
        everynode_distance = []
        for node, node_distance in distance_iter:
            # print(node_distance)
            sort_list = sorted(node_distance.items(),
                               key=lambda x: x[1],
                               reverse=True)
            # print('sort_list',sort_list)
            everynode_distance.append([node, sort_list[0][0], sort_list[0][1]])
        # print('everynode_idstance',everynode_distance)
        sort_every_distance = sorted(everynode_distance,
                                     key=lambda x: x[2],
                                     reverse=True)
        print('sort_every_distance', sort_every_distance)

        #从两个最远的点进行BFS直到找到单源的位置。

        # print(nx.shortest_path_length(infectG,source=single_source[0],target=sort_every_distance[0][0]))
        # print(nx.shortest_path_length(infectG, source=single_source[0], target=sort_every_distance[0][1]))
        #
        # print(nx.shortest_path_length(infectG, source=single_source[0], target=sort_every_distance[1][0]))
        # print(nx.shortest_path_length(infectG, source=single_source[0], target=sort_every_distance[1][1]))
        #
        # print(nx.shortest_path_length(infectG, source=single_source[0], target=sort_every_distance[2][0]))
        # print(nx.shortest_path_length(infectG, source=single_source[0], target=sort_every_distance[2][1]))

        # #根据最远得点,把我们的那个啥,分区,然后利用分区点进行单源定位。。
        node_twolist = [[], []]
        lengthA_dict = nx.single_source_bellman_ford_path_length(
            subinfectG, sort_every_distance[0][0], weight='weight')
        lengthB_dict = nx.single_source_bellman_ford_path_length(
            subinfectG, sort_every_distance[0][1], weight='weight')
        for node in list(subinfectG.nodes):
            if lengthA_dict[node] > lengthB_dict[node]:  # 这个点离b近一些。
                node_twolist[1].append(node)
            elif lengthA_dict[node] < lengthB_dict[node]:
                node_twolist[0].append(node)
            # else:
            #     node_twolist[0].append(node)
            #     node_twolist[1].append(node)
        print('len(node_twolist[0]', len(node_twolist[0]))
        print('len(node_twolist[1]', len(node_twolist[1]))
        # 边界点。
        bound_list = []
        for node_temp in list(infectG.nodes()):
            # print(node_temp)
            if infectG.node[node_temp]['SI'] == 2:
                neighbors_list = list(nx.neighbors(infectG, node_temp))
                neighbors_infect_list = [
                    x for x in neighbors_list if infectG.node[x]['SI'] == 2
                ]
                if len(neighbors_list) != 1 and len(
                        neighbors_infect_list) == 1:
                    # if  len(neighbors_infect_list) == 1:
                    bound_list.append(node_temp)

        print('boundelist', len(bound_list))

        print('len(kjlk)',
              len([x for x in bound_list if x in list(subinfectG.nodes())]))
        left = [x for x in bound_list if x in node_twolist[0]]
        right = [x for x in bound_list if x in node_twolist[1]]

        print('left', left)
        print('right', right)

        left_source = commons.revsitionAlgorithm_singlueSource_receive(
            subinfectG, left)
        right_source = commons.revsitionAlgorithm_singlueSource_receive(
            subinfectG, right)
        if set(left) < set(list(subinfectG.nodes())):
            print('left在感染点里面啊')
        if set(right) < set(list(subinfectG.nodes())):
            print('left在感染点里面啊')
        distance = commons.cal_distance(infectG,
                                        [left_source[0], right_source[0]],
                                        source_list)

        return distance
Beispiel #21
0
    def main(self, filename):
        # #拿到图
        # subGraph=self.get_Graph('../Propagation_subgraph/many_methods/result/chouqu.txt')

        # initG = commons.get_networkByFile('../../../data/CA-GrQc.txt')
        # initG = commons.get_networkByFile('../../../data/3regular_tree1000.txt')
        initG = commons.get_networkByFile(filename)

        # initG = commons.get_networkByFile('../../../data/CA-GrQc.txt')
        # initG = commons.get_networkByFile('../../../data/4_regular_graph_3000_data.txt')

        # initG = commons.get_networkByFile('../../../data/email-Eu-core.txt')

        max_sub_graph = commons.judge_data(initG)
        # source_list = product_sourceList(max_sub_graph, 2)
        source_list = commons.product_sourceList(max_sub_graph, 2)
        # print('两个节点的距离', nx.shortest_path_length(max_sub_graph, source=source_list[0], target=source_list[1]))
        infectG = commons.propagation1(max_sub_graph, source_list)

        subinfectG = commons.get_subGraph_true(infectG)  # 只取感染点,为2表示,真实的感染图。
        '''
        思路:
        1  借助概率p= 0,5以及不同的时间t生成大量的集合。假设知道时间吧。
        2 然后用这些集合去覆盖感染区域,尽可能让blue中点多,而红色区域少。
            这种方法还可以用来确定种子节点的。
            
        
        '''

        # 1  抽取子图操作,共有3种抽取子图操作。我们选择那3种呢?
        subinfectG = commons.get_subGraph_true(infectG)  # 只取感染点,为2表示,真实的感染图。
        '''''' '# 2 分区,分区的太多了,我们看看那种好。' ''

        self.product_many_region(0.5, 6, infectG, subinfectG, source_list)

        partion_graph_object = Partion_graph.Partion_graph()
        result = partion_graph_object.other_k_center(infectG,
                                                     subinfectG,
                                                     source_list,
                                                     source_number=2)

        single_Source_detection_object = single_Source_detection.Single_source(
        )
        print('result', result)
        # 对每一个感染的点建图,用真实的建成一个传播子图
        result_source_list = []
        '''

            3  针对2传回来的多个区域,开始定位源点。
         '''
        for community in result:
            subsubinfectG = nx.Graph()
            for edge in list(subinfectG.edges()):
                if edge[0] in community and (edge[1] in community):
                    subsubinfectG.add_edge(edge[0], edge[1])
            # 看下图连通吗。
            maxsubsubinfectG = self.judge_data(subsubinfectG)
            # 开始单源定位了。
            '''jar center'''
            # source_node = single_Source_detection_object.revsitionAlgorithm_singlueSource(maxsubsubinfectG)
            source_node = single_Source_detection_object.single_source_bydistance_coverage(
                infectG, maxsubsubinfectG)
            #
            # source_node = single_Source_detection_object.single_source_bydistance(maxsubsubinfectG)

            result_source_list.append(source_node[0])

        distance = commons.cal_distance(max_sub_graph, source_list,
                                        result_source_list)

        return distance
    def main(self):
        # #拿到图
        # subGraph=self.get_Graph('../Propagation_subgraph/many_methods/result/chouqu.txt')

        # initG = commons.get_networkByFile('../data/CA-GrQc.txt')
        # initG = commons.get_networkByFile('../data/3regular_tree1000.txt')
        initG = commons.get_networkByFile(
            '../../data/4_regular_graph_3000_data.txt')

        # initG = commons.get_networkByFile('../../../data/CA-GrQc.txt')
        # initG = commons.get_networkByFile('../../../data/4_regular_graph_3000_data.txt')

        # initG = commons.get_networkByFile('../../../data/email-Eu-core.txt')

        max_sub_graph = commons.judge_data(initG)
        # source_list = product_sourceList(max_sub_graph, 2)
        source_list = commons.product_sourceList(max_sub_graph, 2)
        # print('两个节点的距离', nx.shortest_path_length(max_sub_graph, source=source_list[0], target=source_list[1]))
        infectG = commons.propagation1(max_sub_graph, source_list)

        subinfectG = commons.get_subGraph_true(infectG)  # 只取感染点,为2表示,真实的感染图。
        '''
        底下将是所有的步骤组合操作。目前是2源的。
        1  抽取子图操作
        2  分区
        3 分别多源定位
        '''

        # 1  抽取子图操作,共有3种抽取子图操作。我们选择那3种呢?
        subinfectG = commons.get_subGraph_true(infectG)  # 只取感染点,为2表示,真实的感染图。
        '''''' '# 2 分区,分区的太多了,我们看看那种好。' ''
        '''2.1  Different'''

        result = self.Parttion_Different_Time(infectG, sourceNumber=2)
        print('result', len(result))
        single_Source_detection_object = single_Source_detection.Single_source(
        )
        print('result', result)
        # 对每一个感染的点建图,用真实的建成一个传播子图
        result_source_list = []
        '''

            3  针对2传回来的多个区域,开始定位源点。
         '''
        for community_node, community in result:
            subsubinfectG = nx.Graph()
            for edge in list(subinfectG.edges()):
                if edge[0] in community and (edge[1] in community):
                    subsubinfectG.add_edge(edge[0], edge[1])
            # 看下图连通吗。
            maxsubsubinfectG = self.judge_data(subsubinfectG)
            # 开始单源定位了。

            source_node = single_Source_detection_object.revsitionAlgorithm_singlueSource(
                maxsubsubinfectG)
            result_source_list.append(source_node[0])

        distance = commons.cal_distance(max_sub_graph, source_list,
                                        result_source_list)

        return distance
Beispiel #23
0
 def get_Graph(self, filename):
     #通过文件生成图。
     subGraph = commons.get_networkByFile(filename)
     #该图必定连通。
     #开始分区,输出每个区域的点和边。当前是两源的。
     return subGraph
Beispiel #24
0
    def main(self, filename):

        # #拿到图
        # subGraph=self.get_Graph('../Propagation_subgraph/many_methods/result/chouqu.txt')
        # initG = commons.get_networkByFile('../../../data/CA-GrQc.txt')
        # initG = commons.get_networkByFile('../../../data/3regular_tree1000.txt')
        initG = commons.get_networkByFile(filename)
        # initG = commons.get_networkByFile('../../../data/4_regular_graph_3000_data.txt')

        max_sub_graph = commons.judge_data(initG)
        # source_list = product_sourceList(max_sub_graph, 2)
        source_list = commons.product_sourceList(max_sub_graph, 2)
        print(
            '两个节点的距离',
            nx.shortest_path_length(max_sub_graph,
                                    source=source_list[0],
                                    target=source_list[1]))
        #看下分区效果行不行,传播两次,就好了,
        # 一个是SI为2,一个是SI为3。交叉区域为4。
        infectG = commons.propagation_dif_sigl(max_sub_graph, source_list[0],
                                               3)  #3表示一个源点。
        infectG_other = commons.propagation_dif_sigl(infectG, source_list[1],
                                                     4)  # 4标示表示一个源点。 如果两个标示重合,
        #那就取5

        #提起其中某些节点的东西,提取3,4,5
        node_list3 = []
        node_list4 = []
        node_list5 = []
        for nodes in list(infectG_other.nodes):
            if infectG_other.node[nodes]['SIDIF'] == 3:
                node_list3.append(nodes)
            elif infectG_other.node[nodes]['SIDIF'] == 4:
                node_list4.append(nodes)
            elif infectG_other.node[nodes]['SIDIF'] == 5:
                node_list5.append(nodes)
        node_list3.extend(node_list5)
        node_list4.extend(node_list5)

        print('first——node_list3', len(node_list3))
        print('second——node_list4', len(node_list4))
        print('common_node_list', len(node_list5))

        subinfectG = commons.get_subGraph_true(
            infectG_other)  #只取感染点,为2表示,真实的感染图。
        #然后将感染点之间所有边都相连接起来。
        #第一种方法。
        '''
        应该在这个地方进行传播分区的各种实验,先做好2源的分区。
        '''
        # twosource_node_list =self.Partion_graph_K_center(infectG_other,source_list,2)
        #第3种方式

        # twosource_node_list = self.Partion_graph_K_center_seed(infectG_other,subinfectG,source_list,2)
        # twosource_node_list = self.other_k_center(infectG_other, subinfectG, source_list, 2)

        twosource_node_list = self.randmo_BFS(infectG_other, subinfectG,
                                              source_list)
        #进行覆盖率走,并进行jaya算法。
        # twosource_node_list=self.jaya_add_coverage(infectG_other)
        #进行删除边操作。
        # twosource_node_list = self.delete_high_betweenness_edge_centrality_second(infectG_other)
        # print(twosource_node_list)
        # return self.verification(twosource_node_list, [node_list3, node_list4])

        #
        # # 第7种方法。
        #
        # twosource_node_list = self.label_progration_community(subinfectG)
        # print(twosource_node_list)
        # return self.verification(twosource_node_list,[node_list3,node_list4])
        #
        # # #第四种,进行判断高中介性点为中间点。判断比例
        # # twosource_node_list= self.delete_high_betweenness_centrality(infectG_other)
        # #
        #

        #  最后一种,分区的方法了

        # twosource_node_list = self.other_k_center(subinfectG)
        # print(twosource_node_list)
        return self.verification(twosource_node_list, [node_list3, node_list4])
Beispiel #25
0
    print(dfs_result)
    return dfs_result




def get_data(dir):
    a = open(dir)
    lines = a.readlines()
    lists = []  # 直接用一个数组存起来就好了
    for line in lines:
        lists.append(int(line))
    print(lists)


pre = '../data/'
last = '.txt'
filename = 'CA-GrQc'
# filename = 'facebook_combined'
# filename = 'email-Eu-core'
# filename = 'treenetwork3000'
initG = get_networkByFile(pre+filename+last)
# # test_BFS_node(initG)
ConvertGToCsv(initG, './data_center/'+filename+'.txt')
# get_data('./data_center/'+filename+'.txt')


initG = commons.get_networkByFile(fileName=pre + filename + last)  # 获取图,
max_sub_graph = commons.judge_data(initG)
    def main(self):
        initG = commons.get_networkByFile('../../../data/CA-GrQc.txt')
        # initG = commons.get_networkByFile('../../../data/treenetwork3000.txt')

        max_sub_graph = commons.judge_data(initG)
        # source_list = product_sourceList(max_sub_graph, 2)

        source_list = commons.product_sourceList(max_sub_graph, 2)
        print('两个节点的距离',nx.shortest_path_length(max_sub_graph,source= source_list[0],target=source_list[1]))
        #看下分区效果行不行,传播两次,就好了,
        # 一个是SI为2,一个是SI为3。交叉区域为4。
        infectG = commons.propagation_dif_sigl(max_sub_graph, source_list[0], 3)    #3表示一个源点。
        infectG_other = commons.propagation_dif_sigl(infectG, source_list[1], 4)  # 4标示表示一个源点。 如果两个标示重合,
        #那就取5

        #提起其中某些节点的东西,提取3,4,5
        node_list3 = []
        node_list4 = []
        node_list5 = []
        for nodes in  list(infectG_other.nodes):
            if infectG_other.node[nodes]['SIDIF']==3:
                node_list3.append(nodes)
            elif  infectG_other.node[nodes]['SIDIF']==4:
                node_list4.append(nodes)
            elif infectG_other.node[nodes]['SIDIF']==5:
                node_list5.append(nodes)
        node_list3.extend(node_list5)
        node_list4.extend(node_list5)

        print('first——node_list3',len(node_list3))
        print('second——node_list4',len(node_list4))

        subinfectG = commons.get_subGraph(infectG_other) #只取感染点,为2表示
        '''
        思路,单源定位,覆盖率效果较好的是不是真的拟合了传播子图。
        '''
        singleRegionList = list(subinfectG.nodes)
        #进行覆盖率走,并进行jaya算法。
        results = commons.jayawith_dynami_H(infectG, singleRegionList, 2, [4, 5, 6], singleRegionList)
        print(results)

        node_coverage1 = []
        node_coverage2 = []

        # #计算两个传播区域的重合区域。

        node_coverage1.extend(list(nx.bfs_tree(infectG, source=results[0][0], depth_limit=results[1])))
        node_coverage2.extend(list(nx.bfs_tree(infectG, source=results[0][1], depth_limit=results[1])))

        #判断那个跟那个拟合。就看BFS树源点跟那个近就可以了。就认为是那个。
        lengtha =nx.shortest_path_length(infectG, source=results[0][0], target=source_list[0])
        lengthb = nx.shortest_path_length(infectG, source=results[0][1], target=source_list[0])
        print('length1',lengtha)
        print('lengthb',lengthb)
        if  lengtha >  lengthb:
            a= [x for x in node_list3 if x in node_coverage2]
            print('len(a)', len(a))
            print(len(a)/len(node_list3))

            b = [x for x in node_list4 if x in node_coverage1]
            print('len(b)',len(b))
            print(len(b)/len(node_list4))

            print('失败匹配')
            c = [x for x in node_list3 if x in node_coverage1]
            print('len(c)', len(c))
            print(len(c) / len(node_list3))
            d = [x for x in node_list4 if x in node_coverage2]
            print('len(c)', len(d))
            print(len(d) / len(node_list4))

        else:
            a = [x for x in node_list3 if x in node_coverage1]
            print('len(a)', a)
            print(len(a) / len(node_list3))
            b = [x for x in node_list4 if x in node_coverage2]
            print('len(b)', b)
            print(len(b) / len(node_list4))

            print('失败匹配')
            c = [x for x in node_list3 if x in node_coverage2]
            print('len(c)', len(c))
            print(len(c) / len(node_list3))
            d = [x for x in node_list4 if x in node_coverage1]
            print('len(c)', len(d))
            print(len(d) / len(node_list4))
    def main(self):
        # initG = commons.get_networkByFile('../../../data/3_regular_tree_2000_data.txt')
        # initG = commons.get_networkByFile('../../../data/4_regular_tree_2000_data.txt')
        # initG = commons.get_networkByFile('../../../data/4_regular_graph_3000_data.txt')

        # initG = commons.get_networkByFile('../../../data/treenetwork3000.txt')

        initG = commons.get_networkByFile('../../../data/CA-GrQc.txt')

        max_sub_graph = commons.judge_data(initG)
        # source_list = product_sourceList(max_sub_graph, 2)

        source_list = commons.product_sourceList(max_sub_graph, 2)
        # print('查看两源距离')
        # print('distance',nx.shortest_path_length(max_sub_graph,source=source_list[0],target=source_list[1]))
        infectG, node_list, edge_list, zhengchang_G = self.propagation1(
            max_sub_graph, source_list)

        with open('node_list.txt', 'w') as f:
            for i in node_list:
                f.write(str(i) + '\n')
        with open('edge_list.txt', 'w') as f:
            for i in edge_list:
                f.write(str(i) + '\n')
        #这是我们抽取的子图。
        subinfectG = self.take_subgraph_last(infectG)
        # self.verification(infectG, subinfectG)

        #我们抽取子图
        center_list = commons.revsitionAlgorithm_singlueSource(subinfectG)

        #实验一般的用的图。

        tmep_graph = commons.get_subGraph(infectG)
        center_list2 = commons.revsitionAlgorithm_singlueSource(tmep_graph)

        #真实感染图
        center_list1 = commons.revsitionAlgorithm_singlueSource(zhengchang_G)

        #将3个图都画出来。并保存
        self.draw_picture(subinfectG, 'result/chouqu')
        self.draw_picture(tmep_graph, 'result/common')
        self.draw_picture(zhengchang_G, 'result/true')

        print('我们抽取子图边数目', subinfectG.number_of_edges())
        print('一般实验图边数目', tmep_graph.number_of_edges())
        print('一般实验图点数目', tmep_graph.number_of_nodes())
        print('真实感染图边数目', zhengchang_G.number_of_edges())
        print('真实感染图点数目', zhengchang_G.number_of_nodes())

        #将图中点保存在文件之中。

        self.output_txt(subinfectG, 'result/chouqu')
        self.output_txt(tmep_graph, 'result/common')
        self.output_txt(zhengchang_G, 'result/true_')

        for center in center_list:
            print(
                'distan抽取子图',
                nx.shortest_path_length(max_sub_graph,
                                        source=center,
                                        target=source_list[0]))
        for center1 in center_list1:
            print(
                'distance真实感染图',
                nx.shortest_path_length(max_sub_graph,
                                        source=center1,
                                        target=source_list[0]))
        for center2 in center_list2:
            print(
                'distance一般实验用图',
                nx.shortest_path_length(max_sub_graph,
                                        source=center2,
                                        target=source_list[0]))