示例#1
0
def getGA(width, poly, nfp_asst, generations=10):
    polys_GA = PolyListProcessor.getPolyObjectList(poly, [0])
    ga = GA(width,
            polys_GA,
            nfp_asst=nfp_asst,
            generations=generations,
            pop_size=10)
    origin = ga.length_record[0]
    best = ga.global_lowest_length
    return origin - best
示例#2
0
def BLFwithSequence(test_path, width, seq_path=None, GA_algo=False):
    if seq_path != None:
        f = open(seq_path, 'r')
        seqs = f.readlines()
    data = np.load(test_path, allow_pickle=True)
    test_name = test_path.split('_xy')[0]
    height = []
    if GA_algo: p = Pool()
    multi_res = []
    for i, line in enumerate(tqdm(data)):
        polys_final = []
        if seq_path != None:  # 指定序列
            seq = seqs[i].split(' ')
        else:  # 随机序列
            seq = np.array(range(len(line)))
            np.random.shuffle(seq)
        for j in range(len(line)):
            if seq_path != None:
                index = int(seq[j])
            else:
                index = seq[j]
            polys_final.append(line[index])
        nfp_asst = NFPAssistant(polys_final,
                                load_history=True,
                                history_path='record/{}/{}.csv'.format(
                                    test_name, i))
        #nfp_asst=None
        if GA_algo == True:  # 遗传算法
            polys_GA = PolyListProcessor.getPolyObjectList(polys_final, [0])
            multi_res.append(
                p.apply_async(GA, args=(width, polys_GA, nfp_asst)))
        else:
            blf = BottomLeftFill(width, polys_final, NFPAssistant=nfp_asst)
            #blf.showAll()
            height.append(blf.getLength())
    if GA_algo:
        p.close()
        p.join()
        for res in multi_res:
            height.append(res.get().global_lowest_length)
    return height
示例#3
0
        # print('结束温度的局部最优的序列:',temp_best_list)
        print('结束温度的局部最优高度:', temp_lowest_length)
        # print('最好序列:',global_best_list)
        print('最好序列高度:', global_lowest_length)

        PolyListProcessor.showPolyList(self.width, global_best_list)

        self.showBestResult(temp_lowest_length_list, global_lowest_length_list)

    def showBestResult(self, list1, list2):
        plt.figure(1)
        plt.subplot(311)
        plt.plot(list1)  #每个温度下平衡路径长度
        plt.subplot(312)
        plt.plot(list2)  #每个温度下最好路径长度
        plt.grid()
        plt.show()


if __name__ == '__main__':
    starttime = datetime.datetime.now()

    polys = getData(6)
    all_rotation = [0]  # 禁止旋转
    poly_list = PolyListProcessor.getPolyObjectList(polys, all_rotation)

    SA(poly_list)

    endtime = datetime.datetime.now()
    print(endtime - starttime)
示例#4
0
        self.showBestResult(temp_lowest_length_list, global_lowest_length_list)

    def showBestResult(self, list1, list2):
        plt.figure(1)
        plt.subplot(311)
        plt.plot(list1)  #每个温度下平衡路径长度
        plt.subplot(312)
        plt.plot(list2)  #每个温度下最好路径长度
        plt.grid()
        plt.show()


if __name__ == '__main__':
    starttime = datetime.datetime.now()
    # polys=getConvex(num=5)
    polys = getData()
    print(len(polys))
    poly_list = PolyListProcessor.getPolyObjectList(polys + polys + polys, [0])
    # TOPOS(polys,1500)
    nfp_assistant = NFPAssistant(polys,
                                 store_nfp=False,
                                 get_all_nfp=True,
                                 load_history=True)
    GA(760, poly_list, nfp_asst=nfp_assistant)
    # SA(poly_list)

    # GetBestSeq(1000,getConvex(num=5),"decrease")
    endtime = datetime.datetime.now()
    print(endtime - starttime)
    bfl.showAll()