Exemple #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
    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('是的,是真子集。')
    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])
    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, 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)
Exemple #6
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
Exemple #7
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
Exemple #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
Exemple #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
Exemple #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
Exemple #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)
Exemple #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.propagation1(initG, 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 = 4)
            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.txt', "a") as f:
            # f.write("这是个测试!")  # 这句话自带文件关闭功能,不需要再写f.close()
            f.write(str(variance_list) + '\n')
        return variance_list
Exemple #13
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
Exemple #14
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')
Exemple #15
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
    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
                                                                  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()))
    # subinfectG_temp = nx.bfs_tree(subInfectG, source=source_list[0])
    # subinfectG = subinfectG_temp.to_undirected()

    jordan_center_object = jordan()
    center = jordan_center_object.jordan_centrality(subInfectG)
Exemple #18
0








    # #拿到图
    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, [78])
    # 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()))
    # subinfectG_temp = nx.bfs_tree(subInfectG, source=source_list[0])
    # subinfectG = subinfectG_temp.to_undirected()


Exemple #19
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
Exemple #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表示,真实的感染图。
        '''
        思路:
        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
Exemple #21
0
    def product_many_region(self, p, t, infectG, subinfetG, true_list):
        #这里的随便,我就用源点了。
        for i in true_list:
            G_temp = commons.propagation1(infectG, i, number=2)

        pass
    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