if __name__ == '__main__': ad_part1 = 'G:/190708-190712data/MNJ-HPC-002ZP1-20190709.csv' ad_part2 = 'G:/190708-190712data/MNJ-HPT-001ZP1-20190708.csv' ad_part3 = 'G:/190708-190712data/MNJ-HPC-001ZP2-20190708.csv' # new_part1--part2--part1 runout = np.stack((-pre.idata(ad_part1, [3]), pre.idata(ad_part1, [1]), pre.idata(ad_part1, [4]), -pre.idata(ad_part1, [2]), -pre.idata(ad_part2, [4]), pre.idata(ad_part2, [2]), pre.idata(ad_part2, [3]), pre.idata(ad_part2, [1]), -pre.idata(ad_part3, [3]), pre.idata(ad_part3, [1]), pre.idata(ad_part3, [4]), pre.idata(ad_part3, [2])), axis=0) r = [84/2, 206.5/2, 80/2, 200/2, 206.5/2, 84/2, 200/2, 80/2, 84/2, 206.5/2, 80/2, 200/2] h = [192, 120, 192] Dim = 1 # 初始决策变量维数(=总的级数-1) n = 2 # 累计的已固定好的级数 aim = Stack_rigidity(runout, r, h) myAlgorithm, obj_trace, var_trace, best_gen, best_ObjV, phase, res, n = main(aim, n, Dim, phase=[0, 180]) """====================================================================原格式==============================================================""" # from MyProblem_1 import MyProblem_2 # if __name__ == '__main__': # """===============================实例化问题对象===========================""" # ad_part1 = 'G:/190708-190712data/MNJ-HPC-002ZP1-20190709.csv' # ad_part2 = 'G:/190708-190712data/MNJ-HPT-001ZP1-20190708.csv' # ad_part3 = 'G:/190708-190712data/MNJ-HPC-001ZP2-20190708.csv' # runout = np.stack((-pre.idata(ad_part1, [3]), pre.idata(ad_part1, [1]), pre.idata(ad_part1, [4]), # -pre.idata(ad_part1, [2]), -pre.idata(ad_part2, [4]), pre.idata(ad_part2, [2]), # pre.idata(ad_part2, [3]), pre.idata(ad_part2, [1]), -pre.idata(ad_part3, [3]), # pre.idata(ad_part3, [1]), pre.idata(ad_part3, [4]), pre.idata(ad_part3, [2])), axis=0) # r = [84/2, 206.5/2, 80/2, 200/2, 206.5/2, 84/2, 200/2, 80/2,
pre.idata(ad_part3, [4]), pre.idata(ad_part3, [2])), axis=0) r = [ 84 / 2, 206.5 / 2, 80 / 2, 200 / 2, 206.5 / 2, 84 / 2, 200 / 2, 80 / 2, 84 / 2, 206.5 / 2, 80 / 2, 200 / 2, 206.5 / 2, 84 / 2, 200 / 2, 80 / 2, 84 / 2, 206.5 / 2, 80 / 2, 200 / 2, 84 / 2, 206.5 / 2, 80 / 2, 200 / 2 ] h = [192, 120, 192, 120, 192, 192] Dim = 5 # 初始决策变量维数(=总的级数-1) n = 0 # 累计的已固定好的级数 phase = None # [0, 180, 280] start1 = time.perf_counter() Para = Para(runout, r) para = Para.getPara() end1 = time.perf_counter() print( f'para耗时 {int((end1 - start1) // 60)} 分 {(end1 - start1) % 60:.8f} 秒') aim = Stack_rigidity(runout, r, h, para) population, myAlgorithm, obj_trace, var_trace, best_gen, best_ObjV, phase, res, n = main( aim, n, Dim, phase) """==========================判断是否再次使用算法=======================""" # while len(res[:, 0]) - n > 0: # 如果未固定好的级数(=总的级数-已固定好的级数)大于0,则还需继续搜索,直到一级也不剩时终止。 # print('---------------------------------------------------------------') # print('后续最优相位寻找中...') # Dim = len(res[:, 0]) - n # 更新后的决策变量维数 # population, myAlgorithm, obj_trace, var_trace, best_gen, best_ObjV, phase, res, n = main(aim, n, Dim, phase[:n]) # print('搜索完毕!') draw_figure(aim.plot_center(phase)) end = time.perf_counter() print(f'总耗时 {int((end - start) // 60)} 分 {(end - start) % 60:.8f} 秒')
part2_radial_runout_down, part2_radial_runout_up), axis=0) part1_r_flat_down = 84 / 2 part1_r_flat_up = 206.5 / 2 part1_r_radial_down = 80 / 2 part1_r_radial_up = 200 / 2 part2_r_flat_down = 206.5 / 2 part2_r_flat_up = 84 / 2 part2_r_radial_down = 200 / 2 part2_r_radial_up = 80 / 2 r = [ part1_r_flat_down, part1_r_flat_up, part1_r_radial_down, part1_r_radial_up, part2_r_flat_down, part2_r_flat_up, part2_r_radial_down, part2_r_radial_up ] aim = Stack_rigidity(runout, r, [687, 388]) problem = MyProblem_1(aim) # 生成问题对象 """=================================种群设置===============================""" Encoding = 'RI' # 编码方式 NIND = 10 # 种群规模 Field = ea.crtfld(Encoding, problem.varTypes, problem.ranges, problem.borders) # 创建区域描述器 population = ea.Population(Encoding, Field, NIND) # 实例化种群对象(此时种群还没被初始化,仅仅是完成种群对象的实例化) """===============================算法参数设置=============================""" myAlgorithm = ea.soea_SEGA_templet(problem, population) # 实例化一个算法模板对象 # myAlgorithm.mutOper.Pm = 0.2 # 修改变异算子的变异概率 # myAlgorithm.recOper.XOVR = 0.9 # 修改交叉算子的交叉概率 myAlgorithm.MAXGEN = 20 # 最大进化代数 myAlgorithm.drawing = 2 # 设置绘图方式(0:不绘图;1:绘制结果图;2:绘制目标空间过程动画;3:绘制决策空间过程动画) """==========================调用算法模板进行种群进化======================="""
"""=======================================前两级相位为:0,180=======================================""" if __name__ == '__main__': ad_part1 = 'G:/190708-190712data/MNJ-HPC-002ZP1-20190709.csv' ad_part2 = 'G:/190708-190712data/MNJ-HPT-001ZP1-20190708.csv' ad_part3 = 'G:/190708-190712data/MNJ-HPC-001ZP2-20190708.csv' # new_part1--part2--part1--part2 runout = np.stack((-pre.idata(ad_part1, [3]), pre.idata(ad_part1, [1]), pre.idata(ad_part1, [4]), -pre.idata(ad_part1, [2]), -pre.idata(ad_part2, [4]), pre.idata(ad_part2, [2]), pre.idata(ad_part2, [3]), pre.idata(ad_part2, [1]), -pre.idata(ad_part3, [3]), pre.idata(ad_part3, [1]), pre.idata(ad_part3, [4]), pre.idata(ad_part3, [2]), -pre.idata(ad_part2, [4]), pre.idata(ad_part2, [2]), pre.idata(ad_part2, [3]), pre.idata(ad_part2, [1])), axis=0) r = [84/2, 206.5/2, 80/2, 200/2, 206.5/2, 84/2, 200/2, 80/2, 84/2, 206.5/2, 80/2, 200/2, 206.5/2, 84/2, 200/2, 80/2] h = [192, 120, 192, 120] find_index = 0 start = time.perf_counter() aim = Stack_rigidity(runout, r, h, find_index) a = np.zeros((36, 36)) for i in range(36): for j in range(36): a[i, j] = max(aim.bias_n(0, 180, i * 10, j * 10)[2:, 0]) # pool = Pool(4) # res = pool.map() s = np.where(a.min() == a[:, :]) # s = [[29], [19]] end = time.perf_counter() print('最小目标值为:%s' % (a[s[0], s[1]])) # a[s[0], s[1]] = 0.01606076 print('位置为:%s; %s' % (s[0] * 10, s[1] * 10)) print(f'耗时:{end - start}s')
pre.idata(ad_part2, [3]), pre.idata(ad_part2, [1]), -pre.idata(ad_part1, [3]), pre.idata(ad_part1, [1]), pre.idata(ad_part1, [4]), -pre.idata(ad_part1, [2]), -pre.idata(ad_part3, [3]), pre.idata(ad_part3, [1]), pre.idata(ad_part3, [4]), pre.idata(ad_part3, [2])), axis=0) r = [ 84 / 2, 206.5 / 2, 80 / 2, 200 / 2, 206.5 / 2, 84 / 2, 200 / 2, 80 / 2, 84 / 2, 206.5 / 2, 80 / 2, 200 / 2, 206.5 / 2, 84 / 2, 200 / 2, 80 / 2, 84 / 2, 206.5 / 2, 80 / 2, 200 / 2, 84 / 2, 206.5 / 2, 80 / 2, 200 / 2 ] h = [192, 120, 192, 120, 192, 192] find_index = 0 Para = Para(runout, r) para = Para.getPara() aim = Stack_rigidity(runout, r, h, para) n = 6 x = [[0, 180, 280] + [i * 10, j * 10] + [190] for i in range(36) for j in range(36)] PoolType = 'Thread' start = time.perf_counter() """========================================分割线=============================================""" args = list(zip(x, [aim] * len(x), [n] * len(x))) # 返回一个迭代器,每次返回一行数据 if PoolType == 'Thread': pool = ThreadPool(12) # 设置线程池的大小 elif PoolType == 'Process': num_cores = int(mp.cpu_count()) # 获得计算机的核心数 pool = ProcessPool(num_cores) # 设置池的大小 a0 = pool.map(aimFunc3, args) # 使用pool.map函数 a = np.zeros((36, 36)) for i in range(36):
ad_part1 = 'G:/190708-190712data/MNJ-HPC-002ZP1-20190709.csv' ad_part2 = 'G:/190708-190712data/MNJ-HPT-001ZP1-20190708.csv' ad_part3 = 'G:/190708-190712data/MNJ-HPC-001ZP2-20190708.csv' runout = np.stack((-pre.idata(ad_part1, [3]), pre.idata( ad_part1, [1]), pre.idata(ad_part1, [4]), -pre.idata(ad_part1, [2]), -pre.idata(ad_part2, [4]), pre.idata(ad_part2, [2]), pre.idata(ad_part2, [3]), pre.idata(ad_part2, [1]), -pre.idata(ad_part3, [3]), pre.idata(ad_part3, [1]), pre.idata(ad_part3, [4]), pre.idata(ad_part3, [2])), axis=0) r = [ 84 / 2, 206.5 / 2, 80 / 2, 200 / 2, 206.5 / 2, 84 / 2, 200 / 2, 80 / 2, 84 / 2, 206.5 / 2, 80 / 2, 200 / 2 ] h = [192, 120, 192] aim = Stack_rigidity(runout, r, h) Dim = 2 n = 0 phase = None problem = MyProblem(aim, n, Dim, phase) # 生成问题对象 """=================================种群设置===============================""" Encoding = 'RI' # 编码方式 NIND = 15 # 种群规模 Field = ea.crtfld(Encoding, problem.varTypes, problem.ranges, problem.borders) # 创建区域描述器 population = ea.Population(Encoding, Field, NIND) # 实例化种群对象(此时种群还没被初始化,仅仅是完成种群对象的实例化) """===============================算法参数设置=============================""" myAlgorithm = ea.soea_studGA_templet(problem, population) # 实例化一个算法模板对象 myAlgorithm.MAXGEN = 15 # 最大进化代数 myAlgorithm.drawing = 2 # 设置绘图方式(0:不绘图;1:绘制结果图;2:绘制目标空间过程动画;3:绘制决策空间过程动画)
if __name__ == '__main__': ad_part1 = 'G:/190708-190712data/MNJ-HPC-002ZP1-20190709.csv' ad_part2 = 'G:/190708-190712data/MNJ-HPT-001ZP1-20190708.csv' ad_part3 = 'G:/190708-190712data/MNJ-HPC-001ZP2-20190708.csv' # new_part1--part2--part1 runout = np.stack((-pre.idata(ad_part1, [3]), pre.idata(ad_part1, [1]), pre.idata(ad_part1, [4]), -pre.idata(ad_part1, [2]), -pre.idata(ad_part2, [4]), pre.idata(ad_part2, [2]), pre.idata(ad_part2, [3]), pre.idata(ad_part2, [1]), -pre.idata(ad_part3, [3]), pre.idata(ad_part3, [1]), pre.idata(ad_part3, [4]), pre.idata(ad_part3, [2])), axis=0) r = [84/2, 206.5/2, 80/2, 200/2, 206.5/2, 84/2, 200/2, 80/2, 84/2, 206.5/2, 80/2, 200/2] h = [192, 120, 192] Dim = 2 # 初始决策变量维数(=总的级数-1) n = 0 # 累计的已固定好的级数 aim = Stack_rigidity(runout, r, h) myAlgorithm, obj_trace, var_trace, best_gen, best_ObjV, phase, res, n = main(aim, n, Dim, phase=None) """==========================判断是否再次使用算法=======================""" while len(res[:, 0]) - n > 0: # 如果未固定好的级数(=总的级数-已固定好的级数)大于0,则还需继续搜索,直到一级也不剩时终止。 print('---------------------------------------------------------------') print('后续最优相位寻找中...') Dim = len(res[:, 0]) - n # 更新后的决策变量维数 if Dim == 1: # 如果只剩最后一级零件,则遍历找出最优 start = time.perf_counter() traversal = np.zeros((36, 2)) for i in range(36): traversal[i, :] = aim.bias_n_li(phase[:n] + [i * 10])[n:, :] s = np.where(traversal[:, 0] == traversal[:, 0].min())[0][0] n += 1 end = time.perf_counter() print('遍历结束。')