def Astar_path(start_x,start_y,end_x,end_y): #创建一个10*10的地图 CloseList = []#路径列表 decode = de.Decode() decode.addPattern() map2d=decode.envMat #w,h=np.shape(map2d) #显示地图当前样子 #map2d.showArray2D() #创建AStar对象,并设置起点为0,0终点为9,0 aStar=AStar(map2d,Point(start_x,start_y),Point(end_x,end_y)) #开始寻路 pathList=aStar.start() #遍历路径点,在map2d上以'8'显示 print('pathList\n',pathList) for point in pathList: map2d[point.x][point.y]=8 CloseList.append((point.x,point.y)) print(CloseList) # print(point) print("----------------------") #再次显示地图 #map2d.showArray2D() print('map2d:\n',map2d) return CloseList
def decode_image(image_path, password, text_field): # calling Decode class constructor decode_action = decode.Decode(image_path, password) # calling a method inside Decode class to check if all the supplied arguments are valid # returns status with status message msg = decode_action.are_values_valid() # checkin the status of the returned message if not msg[1]: # showing error message if the supplied values are not valid messagebox.showerror("Error Decoding", msg[0]) else: # calling method inside Decode class to decode the text inside image # returns text or error message with boolean status value decoded_text = decode_action.decode_from_image() # checking status of the message and if message extraction is successful, displaying on the window if decoded_text[1]: # enabling the disabled text widget on the decode window text_field.config(state=NORMAL) # clearing the text field before inserting the decoded text text_field.delete(1.0, END) # inserting the decoded text text_field.insert(1.0, decoded_text[0]) # re-disabling the widget to prevent accidental insertion text_field.config(state=DISABLED) # showing success message messagebox.showinfo("Text Decoded", "Decode operation was successful.") else: # showing error message if any error occurs during decoding process messagebox.showerror("Error Decoding", decoded_text[0])
def __init__(self): # Run the net interface as this is the active thread. self.__netif = netif.NetIF(self.__netCallback) self.__netif.start() # Create a VNA reader self.__vna = vna.VNA() # Create a decoder self.__decoder = decode.Decode()
def start(fileCfgName='6_40_40_329_office_Cfg.txt', runTimes=0): start = time.time() decode = de.Decode(fileCfgName) decode.addPattern() Pstart_x = decode.robRowLst Pstart_y = decode.robColLst Robot_NUM = decode.robNum model = 7 model_NUM = 3 Gm = 1000 Np = 200 Fangan_final_choose, Gmin = GA_search(Gm, Np, Pstart_x, Pstart_y, Robot_NUM, model, model_NUM, fileCfgName) print(Fangan_final_choose) decode = de.Decode(fileCfgName) decode.addPattern() decode.chrom = Fangan_final_choose.flatten() decode.chrom = decode.chrom.astype(int) c_rate, makeSpan = decode.calFitness() print('c_rate', c_rate) print('makeSpan', makeSpan) #drawconvergence(Gm,Gmin) end = time.time() print('cost.time:', end - start) # decode.writePath() # drawPic() # org_exe_name = 'D:\\py_code\\ComplexSystemIntelligentControl\\bin\\exc\\Debug\\MultiCover.exe' # fileCfgName = '5_20_20_80_Outdoor_Cfg.txt' # degNameCfg = conFileDir + fileCfgName # proOrgStatic = subprocess.Popen([org_exe_name,degNameCfg],stdin =subprocess.PIPE,stdout = subprocess.PIPE) # for line in proOrgStatic.stdout: # print(line) # drawPic(fileCfgName,8,str(runTimes),False) return decode.chrom, c_rate, makeSpan
def DecodeMessage(): ImageToDecrypt = input("Enter the name of the image which you would like to decrypt (with extension): ") #image = Image.open(UserInputImage, 'r') DecryptPasscode = input("Please enter the correct passphrase to decrypt the image: ") print("We are decrypting your image: '" + ImageToDecrypt + "' using the passcode you provided: '" + DecryptPasscode + "' . \nPlease wait for a while..." ) print ("Decoding your message") # Decode the message from the image DecodeImage = decode.Decode(ImageToDecrypt) MessageRetrieved = DecodeImage.reveal_function() if(MessageRetrieved.endswith(DecryptPasscode)): print( MessageRetrieved ) else: print("Incorrect passcode. Please try again!")
# -*- coding: utf-8 -*- """ Created on Sun Nov 8 19:36:54 2020 @author: mi """ import my import decode import serial ser = serial.Serial("/dev/ttyUSB0", 115200, timeout=10) #print(ser) print("串口连接成功,串口信息:\n") print(ser) while (1): txt = ser.readlines(40000) if txt != []: if len(str(txt[0])) > 4000: print("成功接收蓝牙数据") with open("/home/xilinx/jupyter_notebooks/spaq/picture.txt", "w", encoding='utf-8') as f: f.write(str(txt[0])[2:-2]) print("成功保存图片base64编码数据") f.close() break decode.Decode() score = my.test() ser.write(score.encode("utf-8"))
def GA_search(Gm, Np, Pstart_x, Pstart_y, Robot_NUM, model, model_NUM, fileCfgName): D = Robot_NUM CR = 0.65 MR = 0.05 decode = de.Decode(fileCfgName) decode.addPattern() #可选择的模式数量 Fangan = np.zeros((Np, D, model_NUM * 2 + 1)) Fangan_before = np.zeros((Np, D, model_NUM * 2)) Fangan_model = np.random.randint(0, model - 1, size=[Np, D, model_NUM]) Fangan_step = np.random.randint(1, 400, size=[Np, D, model_NUM]) #1000应该根据环境的空余大小来定,以后要更改 Fangan_before[:, :, np.s_[::2]] = Fangan_model Fangan_before[:, :, np.s_[1::2]] = Fangan_step n = [i for i in range(1, D + 1)] rob_Priority = list(itertools.permutations(n, D)) #生成全排列组合 for i in range(Np): rand_Priority = np.random.randint(0, perm(D, D) - 1) Pri = rob_Priority[rand_Priority] Pri = array(Pri) #print('Pri',Pri) Pri = Pri[:, np.newaxis] #print('Fangan[i,:,:]',Fangan_before[i,:,:]) Fangan[i, :, :] = np.hstack((Pri, Fangan_before[i, :, :])) Fangan = Fangan.astype(int) Gmin = np.zeros(Gm) Fangan_final = np.zeros((Gm, D, model_NUM * 2 + 1)) fitness = np.zeros(Np) fitness_choose = np.zeros(Np) fitness_final = np.zeros(Np) #先对初始解计算适应值 for i in range(Np): # decode = de.Decode() # decode.addPattern() decode.chrom = Fangan[i, :, :].flatten() c_rate, makeSpan = decode.calFitness() fitness[i] = makeSpan / (len(decode.robReachSet)) + (1 - c_rate) #开始循环寻优 for G in range(Gm): #交叉 Fangan_next_1 = Fangan #print('Fangan_next_1:\n',Fangan_next_1) ##调试用 for ii in range(Np): if random.random() < CR: #dx=np.arange(0,Np-1,4) dx = random.sample(range(0, Np - 1), 3) dx_pos = np.where(dx == ii) A1 = np.delete(dx, dx_pos) index_x1 = np.random.randint(0, D - 1) temp_x = Fangan_next_1[A1[0], :, index_x1] Fangan_next_1[A1[0], :, index_x1] = Fangan_next_1[A1[1], :, index_x1] Fangan_next_1[A1[1], :, index_x1] = temp_x Fangan_next_2 = Fangan_next_1 #print('Fangan_next_2--1:\n',Fangan_next_2) ##调试用 #变异 for ii in range(Np): if random.random() < MR: index_x2 = np.random.randint(0, D - 1) Fangan_again = np.zeros(model_NUM * 2) Fangan_model_again = np.random.randint(0, model - 1, model_NUM) Fangan_step_again = np.random.randint(1, 400, model_NUM) Fangan_again[np.s_[::2]] = Fangan_model_again Fangan_again[np.s_[1::2]] = Fangan_step_again Fangan_again = np.hstack((Fangan_next_2[ii, index_x2, 0], Fangan_again)) Fangan_next_2[ii, index_x2, :] = Fangan_again #print('Fangan_next_2--2:\n',Fangan_next_2) ##调试用 #选择 for i in range(Np): #print('---------------Env-----------\n',Env) #decode = de.Decode() #decode.addPattern() decode.chrom = Fangan_next_2[i, :, :].flatten() c_rate, makeSpan = decode.calFitness() if (c_rate >= 1): fitness_choose[i] = makeSpan else: fitness_choose[i] = 1000000000 # fitness_choose[i]=makeSpan/(len(decode.robReachSet))+(1-c_rate) Fangan_all = np.vstack((Fangan, Fangan_next_2)) #Fangan_all=[] #fitness_all=[] fitness_all = np.hstack((fitness, fitness_choose)) #print('Fangan_all:\n',len(Fangan_all)) value_min_all = fitness_all.min() Fangan_next_3 = Fangan_next_2 for i in range(Np): dx = random.sample(range(0, 2 * Np - 1), 3) temp_fitness = np.mat( [fitness_all[dx[0]], fitness_all[dx[1]], fitness_all[dx[2]]]) value_min = temp_fitness.min() pos_min = np.argmin(temp_fitness) fitness_final[i] = value_min if pos_min == 0: Fangan_next_3[i, :, :] = Fangan_all[dx[0], :, :] elif pos_min == 1: Fangan_next_3[i, :, :] = Fangan_all[dx[1], :, :] elif pos_min == 2: Fangan_next_3[i, :, :] = Fangan_all[dx[2], :, :] # compare=np.array(fitness_choose<fitness)+0 # #print(compare) ##调试用 # compare_reshape=compare.reshape(Np,1,1) # #print(compare_reshape) ##调试用 # Fangan_next_3=np.multiply(compare_reshape,Fangan_next_2)+np.multiply((1-compare_reshape),Fangan) # fitness_final=np.multiply(compare,fitness_choose)+np.multiply((1-compare),fitness) value_min = fitness_final.min() if value_min_all != value_min: pos_min = np.argmin(fitness_all) dx = random.sample(range(0, Np - 1), 1) fitness_final[dx] = value_min_all Fangan_next_3[dx, :, :] = Fangan_all[pos_min, :, :] value_min = value_min_all Gmin[G] = value_min pos_min = np.argmin(fitness_final) Fangan_final[G, :, :] = Fangan_next_3[pos_min, :, :] #保存最优个体 fitness = fitness_final Fangan = Fangan_next_3 best_pos = np.argmin(Gmin) Fangan_final_choose = Fangan_final[best_pos, :, :] return Fangan_final_choose, Gmin
layout['annotations'] = annotations layout['shapes'] = shapeLst layout['yaxis'] = dict(scalenchor ='x') pathTrace = go.Scatter(x = [5], y = [5], mode= 'lines', line = dict(shape = 'spline', width = 4), name = 'Path_'+str(1)) drawData = [] drawData.append(pathTrace) fig = dict(data = drawData ,layout = layout) plotly.offline.plot(fig,filename = 'ppp.html',validate=False) if __name__ == '__main__': decode=de.Decode() Env=decode.envMat pattern = Pattern([1,1,1],[0,0,0]) turnLst = [1,1,1] print(GClockWise([0,1])) print(GClockWise([0,-1])) test = (1,1) print('sstr',test[0]) pattern.locationLst = [0,0,0] pattern.turnLst = turnLst pattern.addDic() print(pattern.dic) drawPattern(pattern.dic) # print(sorted(pts, key=clockwiseangle_and_distance))
paramType = "prtype" paramName = "prname" tree = ET.ElementTree(file='protocol.xml') root = tree.getroot() # 读取所有类 cVector = [] for elem in root: if elem.tag == classTag: tClass = N.ClassNode(elem.attrib[className]) for methods in elem: if methods.tag == methodTag: tMethods = M.Method(methods.attrib[methodName], methods.attrib[methodFlow]) for params in methods: if params.tag == paramTag: tParam = Parameter.Parameter(params.attrib[paramName], params.attrib[paramType]) tMethods.appendPara(tParam) tClass.addMethod(tMethods) cVector.append(tClass) print(cVector) for t in cVector: t.display() for t in cVector: dec = decode.Decode(t) dec.decode()
def GA_search(Gm, Np, Pstart_x, Pstart_y, Robot_NUM, model, model_NUM): D = Robot_NUM CR = 0.9 MR = 0.01 #可选择的模式数量 Fangan = np.zeros((Np, D, model_NUM * 2 + 1)) Fangan_before = np.zeros((Np, D, model_NUM * 2)) Fangan_model = np.random.randint(0, model - 1, size=[Np, D, model_NUM]) Fangan_step = np.random.randint(1, 400, size=[Np, D, model_NUM]) #1000应该根据环境的空余大小来定,以后要更改 Fangan_before[:, :, np.s_[::2]] = Fangan_model Fangan_before[:, :, np.s_[1::2]] = Fangan_step n = [1, 2, 3, 4, 5] rob_Priority = list(itertools.permutations(n, 5)) #生成全排列组合 for i in range(Np): rand_Priority = np.random.randint(0, perm(5, 5) - 1) Pri = rob_Priority[rand_Priority] Pri = array(Pri) print('Pri', Pri) Pri = Pri[:, np.newaxis] print('Fangan[i,:,:]', Fangan_before[i, :, :]) Fangan[i, :, :] = np.hstack((Pri, Fangan_before[i, :, :])) Fangan = Fangan.astype(int) Gmin = np.zeros(Gm) Fangan_final = np.zeros((Gm, D, model_NUM * 2 + 1)) fitness = np.zeros(Np) fitness_choose = np.zeros(Np) #先对初始解计算适应值 for i in range(Np): decode = de.Decode() decode.addPattern() decode.chrom = Fangan[i, :, :].flatten() c_rate, makeSpan = decode.calFitness() fitness[i] = makeSpan * (1 - c_rate) #开始循环寻优 for G in range(Gm): #交叉 Fangan_next_1 = Fangan #print('Fangan_next_1:\n',Fangan_next_1) ##调试用 for ii in range(Np): if random.random() < CR: #dx=np.arange(0,Np-1,4) dx = random.sample(range(0, Np - 1), 3) dx_pos = np.where(dx == ii) A1 = np.delete(dx, dx_pos) index_x1 = np.random.randint(0, D - 1) temp_x = Fangan_next_1[A1[0], :, index_x1] Fangan_next_1[A1[0], :, index_x1] = Fangan_next_1[A1[1], :, index_x1] Fangan_next_1[A1[1], :, index_x1] = temp_x Fangan_next_2 = Fangan_next_1 #print('Fangan_next_2--1:\n',Fangan_next_2) ##调试用 #变异 for ii in range(Np): if random.random() < MR: index_x2 = np.random.randint(0, D - 1) Fangan_again = np.zeros(model_NUM * 2) Fangan_model_again = np.random.randint(0, model - 1, model_NUM) Fangan_step_again = np.random.randint(1, 400, model_NUM) Fangan_again[np.s_[::2]] = Fangan_model_again Fangan_again[np.s_[1::2]] = Fangan_step_again Fangan_again = np.hstack((np.random.randint(1, 5), Fangan_again)) Fangan_next_2[ii, index_x2, :] = Fangan_again #print('Fangan_next_2--2:\n',Fangan_next_2) ##调试用 #选择 for i in range(Np): #print('---------------Env-----------\n',Env) decode = de.Decode() decode.addPattern() decode.chrom = Fangan_next_2[i, :, :].flatten() c_rate, makeSpan = decode.calFitness() fitness_choose[i] = makeSpan * (1 - c_rate) compare = np.array(fitness_choose < fitness) + 0 #print(compare) ##调试用 compare_reshape = compare.reshape(Np, 1, 1) #print(compare_reshape) ##调试用 Fangan_next_3 = np.multiply(compare_reshape, Fangan_next_2) + np.multiply( (1 - compare_reshape), Fangan) fitness_final = np.multiply(compare, fitness_choose) + np.multiply( (1 - compare), fitness) value_min = fitness_final.min() Gmin[G] = value_min pos_min = np.argmin(fitness_final) Fangan_final[G, :, :] = Fangan_next_3[pos_min, :, :] #保存最优个体 fitness = fitness_final Fangan = Fangan_next_3 best_pos = np.argmin(Gmin) Fangan_final_choose = Fangan_final[best_pos, :, :] return Fangan_final_choose
pathSum = 0 ct_lst = [] for i in range(robNum): str_path = 'path_len'+str(i) path_len = readCfg.getSingleVal(str_path) ct_lst.append(path_len) pathSum = pathSum + path_len dataNameSp = file.split('auctionSTCEstDeg') dataNameSp[0] = dataNameSp[0] +'.txt' astc_dic[dataNameSp[0]] = (astc_ms,pathSum) dataDic = dict() lowBoundDic = dict() reachableDic = dict() for i in range(len(confileLst)): decode = dc.Decode(cfgFileName = confileLst[i]) decode.addPattern() decode.chrom = pathLst[i] c_rate,makeSpan = decode.calFitness() r_rate = decode.pathRepeatCover() if(confileLst[i] in dataDic): # print('WTF') dataDic[confileLst[i]].append((makeSpan,c_rate,r_rate)) else: dataDic[confileLst[i]] = [(makeSpan,c_rate,r_rate)] lowBound = decode.calLowBound() lowBoundDic[confileLst[i]] = lowBound reachableDic[confileLst[i]] = len(decode.robReachSet) print(c_rate) print(makeSpan) dataProCfg = conFileDir +'dataPro.txt'
# Press ⌃R to execute it or replace it with your code. # Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings. import encode import decode def print_hi(name): # Use a breakpoint in the code line below to debug your script. print(f'Hi, {name}') # Press ⌘F8 to toggle the breakpoint. # Press the green button in the gutter to run the script. if __name__ == '__main__': print_hi('PyCharm') i = 0 iteration_times = 100 dataNum = 5 # should not be to large, 20 might be too big, usually 5~10 dataMade = 3 # around dataNum/2 dataLost = 3 # must less or equal to dataMade while i < iteration_times: encoder = encode.Encode(dataNum, dataMade) encoder.encoding() checker = decode.Check(dataLost) lostRows = checker.make_lost(encoder) decoder = decode.Decode(lostRows) decoder.decoding(encoder, checker) print(i) i = i + 1
def __init__(self): self.e = encode.Encode() self.d = decode.Decode()