1. 程式人生 > >物流路徑規劃用遺傳演算法解決例項

物流路徑規劃用遺傳演算法解決例項

網上有很多關於遺傳演算法的教程,但基本千篇一律。這次物流課做了一個跟路徑規劃相關的案例,拿出來與大家分享。
先貼案例。案例摘自《企業物流管理》。

《 R&T批發公司》
R&T批發公司給全印度的零售商批發日用商品。公司在全國有很多倉庫,作為儲存點和貨站供應周邊城鎮的零售點。供應普拉克薩姆(Prakasam)、岡都爾 (Guntur)、克利須那(Krishna)、西哥達瓦里(WestGodavari)、和東哥達瓦里 (EastGodavari)地區的倉庫設在維查雅瓦達(Vijayawada)每週除週六和週日外,每天出去送貨 (每月24天),每個城鎮每月送貨二次或四次,也就是每兩週或每週送貨一次。對某個鎮子來說,每月按一定的週期送貨兩次,或者在第一、第三週,或者在第二、第四周。一週內送貨的日子有排程員決定。於前者類似,可能制定五天內的任何一天送貨。物流管理人員希望能為公司車隊設計高效的送貨路線,一方面將所需車輛數降到最低,另一方面整個月的車輛行駛總里程最短,並且認為這樣能夠使司機和車輛運營成本最低。
送貨量以每次送貨的平均銷售額來表示,該數字為城內經停的所有零售點購貨量的總和。該銷售區的地圖見圖1,繪製座標系,找出各城鎮的座標。座標系的比例尺是1座標單位等於12.2公里。由座標距離轉換成公路距離的轉換系數為1.12公里。表 1給出了各點座標和卸貨點的時間。卸貨時間指將貨物從卡車卸到零售點站臺所用的時間。因為一個鎮子中可能有多個零售點,所以卸貨時間表示城內所有零售點的總卸貨時間。
目前有4部T407、4部T310卡車用於送貨,每部卡車能裝運500000盧比貨物,T310 能運送350000盧比貨物。卡車每天在該地區的平均行駛速度是40公里每小時。T407的經營成本是每月13500盧比貨物,運送成本為每公里5盧比;T310的經營成本為每月7000盧比,運營成本為每公里3盧比。每部卡車配備兩名僱員,一位司機,一位輔助人員。僱員的工資按月發放。如果在路上,每位僱員可得到每天60盧比的誤餐補助和其他費用。計劃在早上6點、中午12點和晚上6點休息。早餐和午餐每餐用30分鐘,晚餐休息60分鐘。休息時間可以不嚴格按計劃執行。非正式的休息時間可以安排在一天的任何時間,要被計入行駛速度和卸貨時間。僱員可以在晚上休息8個小時,第二天早上再上路。沒有加班費,公司的政策是讓僱員每天回到倉庫,不在外面逗留。
正常情況下卡車從早上9 點送貨。卡車回到倉庫後在晚上裝貨,第二天早上再出傳送貨。卡車最早離開倉庫的時間是中午12點,從週一早上直到週五。送貨到遠處需要早點出發來滿足時間視窗和在途時間的要求等。短途送貨的卡車可能在同一天回到倉庫,花2 小時裝貨後由同一批僱員負責再次出發送貨。如果同一批僱員多次送貨則不多發補貼。
公司可以和第三方物流公司簽約,單程送貨到各城鎮的費用為每公里15盧比(不考慮運量或卡車在城內的停留次數)。也可以同時使用自有運輸和受僱運輸模式。
問題 : 設計一個月的運營路線:
1. 所需的車輛數和車的型號。
2. 卡車行駛路線和經停順序。
3. 四周一個月,到各城送貨的日期。
4. 全月卡車使用的時間安排。
5. 僱員排班表。目標是使卡車、僱員和補貼成本最小化。

數學模型如下:(還不太會編輯公式,就先貼圖了)
變數定義
函式定義-經營成本函式
函式定義-運送成本函式
函式定義-時間限制函式
函式定義-載重限制函式
數學模型

之前已經將所需資料轉換成csv檔案,之後直接使用,如果需要檔案的可以發郵件到[email protected]
以下是python實現。

"""
    solve the logistic problem in geneti algorithms
"""
# -*- coding : uft-8 -*-
import math
import numpy as np
import pandas as pd
import random as rnd
import matplotlib.pyplot as plt
import
copy """ with reading the file named 'logistic.csv' use "with open()" """ itemList = \ [[0, 0.0, 'Vijayawada', 19.4, 15.1, 0, 0, 0.0], [1, 1.9323814116266074, 'Tanguturu', 14.5, 5.3, 6600, 2, 1.0], [2, 20.857190790708088, 'Podili', 10.7, 7.0, 24000, 2, 0.5], [3, 33.077041744388232, 'Ongole', 14.5, 6.2, 305000, 4
, 2.5], [4, 33.077041744388232, 'Markapur', 7.7, 8.2, 60000, 2, 0.5], [5, 34.486376839557948, 'KaniGiri', 9.6, 5.1, 24000, 2, 2.5], [6, 34.486376839557948, 'Kondukur', 13.2, 3.5, 90000, 2, 1.0], [7, 35.762110362784796, 'Giddalur', 3.8, 5.0, 25000, 2, 1.0], [8, 35.762110362784796, 'Chirala', 17.2, 9.0, 98000, 4, 2.0], [9, 41.826126709510191, 'Bestavapetta', 6.3, 6.3, 25000, 2, 0.5], [10, 46.397278485704312, 'Addanki', 13.9, 8.8, 60000, 2, 0.5], [11, 47.372912618077464, 'Chilakalurupet', 15.4, 11.4, 92000, 2, 1.0], [12, 59.32442405620133, 'Narasaraopet', 14.5, 12.5, 100000, 4, 1.0], [13, 62.987927732225053, 'Vinukonda', 11.8, 11.0, 65000, 2, 1.0], [14, 62.987927732225053, 'Tadikonda', 18.1, 14.3, 60000, 2, 1.0], [15, 66.744129468890392, 'Sattenapalle', 15.2, 14.0, 45000, 2, 1.0], [16, 68.538275316497419, 'Repalie', 21.3, 10.6, 50000, 2, 1.0], [17, 73.544821959944969, 'Guntur', 18.0, 13.0, 450000, 4, 3.0], [18, 73.544821959944969, 'Vuyyuru', 21.3, 13.6, 39000, 4, 1.0], [19, 74.453128626270612, 'Tenali', 19.7, 12.5, 140000, 4, 1.0], [20, 75.585513278670021, 'Pamarru', 22.3, 13.2, 62000, 2, 1.0], [21, 75.795182234229088, 'Nuzvid', 21.3, 17.5, 37000, 2, 0.5], [22, 75.795182234229088, 'Machilipatnam', 23.8, 12.0, 108000, 4, 1.0], [23, 77.065444537483828, 'Kaikalur', 24.4, 15.5, 48000, 2, 1.0], [24, 88.605535249215663, 'Jaggayyapeta', 14.9, 18.5, 37000, 2, 0.5], [25, 88.605535249215663, 'HanumenJunction', 19.5, 15.2, 50000, 2, 1.0], [26, 89.19358507516111, 'Gudivada', 22.7, 14.3, 180000, 2, 1.0], [27, 89.19358507516111, 'Bapatia', 18.2, 9.7, 82000, 2, 1.0], [28, 107.98018686407246, 'Rajahmundry', 29.5, 19.6, 470000, 4, 3.5], [29, 107.98018686407246, 'Mandapeta', 30.8, 18.3, 170000, 2, 2.0], [30, 114.27222071107218, 'Narasapur', 28.7, 14.5, 160000, 2, 1.0], [31, 117.99400024882618, 'Amaiapuram', 31.5, 15.6, 90000, 2, 1.0], [32, 119.69071254729833, 'Kakinada', 33.5, 19.1, 228000, 4, 2.0], [33, 119.69071254729833, 'Kovvur', 29.0, 19.7, 45000, 2, 1.0], [34, 127.33938989016715, 'Tanuku', 28.8, 17.4, 134000, 2, 1.0], [35, 132.23053168765526, 'Nidavole', 28.5, 18.7, 50000, 2, 1.0], [36, 133.71883894919219, 'Tadepallegudem', 27.7, 17.9, 130000, 4, 1.5], [37, 138.82247427963529, 'Eluru', 23.6, 17.0, 198000, 4, 2.0], [38, 138.82247427963529, 'Palakolu', 25.9, 15.7, 180000, 4, 1.0], [39, 145.45583114719054, 'Bhimavaram', 27.3, 15.3, 148000, 4, 1.5]] for i in range(len(itemList)): if itemList[i][-2] == 4: temp = copy.deepcopy(itemList[i]) itemList.append(temp) for i in range(len(itemList)): itemList[i].append(i) # sort the itemList with the distance # save as item2 item2 = copy.deepcopy(itemList) item2.sort(key = lambda x:x[1]) def getDistance(a, b, item=itemList): """ get the distance between two points :param a: the first point :param b: the second point :param item: the itemList :return: the distance(float) between point a and point b """ x1 = item[a][3] y1 = item[a][4] x2 = item[b][3] y2 = item[b][4] return math.sqrt((x1-x2)**2+(y1-y2)**2) dis = [] for i in range(len(itemList)): for j in range(len(itemList)): dis.append(getDistance(i,j)) # the matrix of distance distance = np.array(dis).reshape((53, 53)) * 12.2 * 1.12 def drawMap(item=itemList): for i in range(len(item)): if item[i][-3] == 4: plt.scatter(item[i][3],item[i][4],color='green',s=item[i][5]/3000.0) elif item[i][-3] == 2: plt.scatter(item[i][3],item[i][4],color='blue',s=item[i][5]/3000.0) else: plt.scatter(item[i][3],item[i][4],color='red',marker='*',s=500) plt.show() def cost(routine, dis=distance): """ get the cost of the routine the labour cost and the delivery cost :param routine : the routine :return: the cost(float) of the routine """ # the labour cost labour_cost = 0.0 for i in range(len(routine)): if i < 4: if len(routine[i]) != 0: labour_cost += 13500 else: if len(routine[i]) != 0: labour_cost += 7000 # the delivery cost delivery_cost = 0.0 for i in range(len(routine)): if len(routine[i]) == 0: continue if i < 4: for j in range(1,len(routine[i])): delivery_cost += dis[routine[i][j - 1],routine[i][j]] * 5 else: for j in range(1,len(routine[i])): delivery_cost += dis[routine[i][j - 1],routine[i][j]] * 3 return labour_cost+delivery_cost def generateRoutine(item=itemList,dis=distance): # 1-4 for T407 # 5-8 FOR T310 x1list = [] x2list = [] x3list = [] x4list = [] x5list = [] x6list = [] x7list = [] x8list = [] routine = [x1list,x2list,x3list,x4list,x5list,x6list,x7list,x8list] for i in range(1,len(item)): # except 0 while True: # put 52 destinations into random 8 routines k = rnd.randint(0,7) # k = rnd.randint(0,5) # 6 trucks if item[i][5] > 350000: k = rnd.randint(0,3) # do not use T470 or T307 # you can choose which car will be used if k == 3 or k == 2 or k == 1: continue if k == 6: continue # init the origin if len(routine[k]) == 0: routine[k].append(0) break # time constrain time = 0.0 for j in range(1,len(routine[k])): time += getDistance(routine[k][j-1],routine[k][j]) / 40.0\ + item[routine[k][j]][-2] if time < 75 : if item[i][5] > 350000: if k < 4: break else: break break # T407 if k < 4: # judge whether the truck can go next destination if routine[k][-1] != 0: # loading constrain last = item[routine[k][-2]][5] now = 500000 - last if now < item[routine[k][-1]][5]: routine[k].append(0) # time constrain past = dis[routine[k][-2]][routine[k][-1]] / 40.0 + item[routine[k][-2]][-2] future = item[routine[k][-1]][-2] + dis[routine[k][-1]][0] / 40.0 if past + future > 8.5: routine[k].append(0) # T310 else: # judge whether the truck can go next destination if routine[k][-1] != 0: # loading constrain last = item[routine[k][-2]][4] now = 350000 - last if now < item[routine[k][-1]][4]: routine[k].append(0) # time constrain past = dis[routine[k][-2]][routine[k][-1]] / 40.0 + item[routine[k][-2]][-2] future = item[routine[k][-1]][-2] + dis[routine[k][-1]][0] / 40.0 if past + future > 8.5: routine[k].append(0) routine[k].append(item[i][0]) routine[k].append(0) return routine def randomoptimize(): """ random searching :return: the best routine and the best cost """ best = 999999999 bestr = None for i in range(0,10000): # Create a random solution r = generateRoutine() # Get the cost simplify(r) c = cost(r) # Compare it to the best one so far if c < best: best = c bestr = r print best print bestr for t in range(len(bestr)): print t,' >>> ',bestr[t] return bestr,best def getXY(num, item=itemList): """ get the X and Y of a point :param num: the num of the point :param item: itemList :return: the X and Y of the point """ return item[num][3],item[num][4] def draw(routine,item=itemList): """ draw the routine :param routine: the input routine :param item: itemList :return: the picture of the routine """ # for i in range(len(itemList)): # plt.scatter(getXY(itemList[i][0],item),'yellow') style = ['c-','r-','g-','b-','c--','r--','g--','b--'] for i in range(len(routine)): pointX = [] pointY = [] for j in range(len(routine[i])): pointX.append(getXY(routine[i][j])[0]) pointY.append(getXY(routine[i][j])[1]) # plt.plot(point,color[i]) # plt.scatter(pointX,pointY,style=style[i]) plt.plot(pointX,pointY,style[i]) def p(routine): """ print the routine in some way :param routine: the input routine :return: None. Print the routine in the console """ for t in range(len(routine)): print t,' >>> ',routine[t] def isValid(routine,dis=distance,item=itemList): """ judge the routine whether is valid :param routine: the input routine :param dis: the distance matrix :return: if the routine is valid, return True. Otherwise return false """ for k in range(len(routine)): for num in range(1,len(routine[k])): if routine[k][num] == 0: continue last = 0.0 past = 0.0 for i in range(len(routine[k])): if routine[k][num-1-i] == 0: break last += item[routine[k][num-1-i]][5] past += dis[routine[k][num-2-i],routine[k][num-1-i]] / 40.0 + item[routine[k][num-1-i]][-2] if k < 4: now = 500000 - last else: now = 350000 - last future = item[routine[k][num]][-2] + float(dis[routine[k][num],0] / 40.0 + dis[routine[k][num-1],routine[k][num]] / 40.0) if now < item[routine[k][num]][5]: # print 'loading error at ',k,' : ',routine[k] # print 'at ',num # print 'last: ',last # print 'now: ',now # print 'need: ',itemList[routine[k][num]][5] return False if past + future > 14: # print 'time error at ',k,' : ',routine[k] # print 'at ',num # print 'past: ',past # print 'future: ',future return False sum = 0.0 if num in range(1,len(routine[k])): sum += item[routine[k][num]][-2] + dis[routine[k][num-1],routine[k][num]] / 40.0 if sum > 140: # print 'time out of limit at ',k,'--',num # print 'sum time is ',sum return False return True def simplify(routine,dis=distance,item=itemList): """ simplify the routine remove the 0 between the point which can be reached at one time add the 0 between the point which can not be reached at one time :param routine: the input routine :param dis: the distance matrix :return: the simplified routine """ # remove 0 for k in range(len(routine)): if len(routine[k]) > 0: record = [] for num in range(2,len(routine[k])): if routine[k][num-1] == 0: if routine[k][num-2] != 0: last = 0.0 past = 0.0 for i in range(len(routine[k])): if routine[k][num-2-i] == 0: break last += item[routine[k][num-2-i]][5] past += float(dis[routine[k][num-3-i],routine[k][num-2-i]] / 40.0) + item[routine[k][num-2-i]][-2] if k < 4: now = 500000 - last else: now = 350000 - last future = item[routine[k][num]][-2] + float(dis[routine[k][num],[routine[k][num-2]]] / 40.0 + dis[routine[k][num],0] / 40.0) if now >= item[routine[k][num]][5]: if past + future < 8.5: if routine[k][num-1] == 0: record.append(num-1) else: record.append(num-1) if len(record) != 0: record.reverse() for num in record: del(routine[k][num]) # add 0 for k in range(len(routine)): if len(routine[k]) > 0: num = 2 while True: if num >= len(routine[k]): break if routine[k][num-1] != 0: last = 0.0 past = 0.0 for i in range(len(routine[k])): last += item[routine[k][num-1-i]][5] past += float(dis[routine[k][num-2-i],routine[k][num-1-i]] / 40.0) + \ item[routine[k][num-1-i]][-2] if routine[k][num-2-i] == 0: break if k < 4: now = 500000 - last else: now = 350000 - last future = item[routine[k][num]][-2] + float(dis[routine[k][num], routine[k][num-1]] / 40.0 + dis[routine[k][num], 0] / 40.0) if now < item[routine[k][num]][5]: routine[k].insert(num, 0) elif past + future > 8.5: routine[k].insert(num, 0) num += 1 return routine def crossover(r): """ the operation of crossovering a routine choose 2 way to crossover part of the them and check the validity of the routine :param r : the input routine :return : the crossovered routine """ num = 0 while True: while True: k1 = rnd.randint(0,len(r)-1) k2 = rnd.randint(0,len(r)-1) if len(r[k1]) != 0 and len(r[k2]) != 0 and k1 != k2: break length = len(r[k1]) if len([k1])<len(r[k2]) else len(r[k2]) # for j in range(2): i = rnd.randint(1,length) temp1 = r[k1][0:i]+r[k2][i:] temp2 = r[k2][0:i]+r[k1][i:] r[k1] = temp1 r[k2] = temp2 r = simplify(r) # print '-----go on crossover-----' if num > 100: print r = generateRoutine() if isValid(r): # r = simplify(r) return r num += 1 def geneticOptimize(item = itemList, popsize = 100, elite = 0.7, maxiter = 100): """ """ # Build the initial population pop = [] for i in range(popsize): routine = generateRoutine() pop.append(routine) saves = 99999999 saver = [] for i in range(maxiter): print '===============',i,'===============' scores = [(cost(v),v) for v in pop] scores.sort(key=lambda x:x[1]) ranked = [v for (s,v) in scores] if saves > cost(scores[0][1]): saves = cost(scores[0][1]) saver = scores[0][1] print saver print saves topelite = int(popsize*elite) pop = ranked[0:topelite] while True: c = rnd.randint(0,topelite-1) new = crossover(pop[c]) print 'new--->',new pop.append(new) if len(pop) >= popsize: break return saver,saves,scores a, b, c = geneticOptimize() print a print b print '=============scores=============' print c[0] print c[1] print c[2]

求得較優解為:
Min = 68546.568980205644
0 >>> [0, 1, 0, 2, 0, 17, 18, 0, 24, 25, 0, 28, 0, 17, 18, 0, 28, 0, 39, 0, 22, 37, 0]
1 >>> []
2 >>> []
3 >>> []
4 >>> [0, 7, 0, 9, 0, 10, 11, 0, 12, 0, 22, 23, 0, 34, 0, 8, 0, 12, 19, 0, 32, 0, 38, 0]
5 >>> [0, 3, 0, 6, 0, 14, 19, 20, 21, 0, 26, 0, 31, 0, 32, 0, 33, 0, 35, 0, 36, 0, 3, 0]
6 >>> []
7 >>> [0, 4, 0, 5, 0, 8, 0, 13, 15, 0, 16, 27, 0, 29, 0, 30, 0, 37, 0, 38, 39, 0, 36, 0]
最優路徑規劃

具體怎麼建立初始種群怎麼變異都在程式碼中有詳盡註釋。

因為這次拖了很長時間,就不詳細寫了,如果有問題可以發郵件諮詢。

Email:[email protected]

相關推薦

物流路徑規劃遺傳演算法解決例項

網上有很多關於遺傳演算法的教程,但基本千篇一律。這次物流課做了一個跟路徑規劃相關的案例,拿出來與大家分享。 先貼案例。案例摘自《企業物流管理》。 《 R&T批發公司》 R&T批發公司給全印度的零售商批發日用商品。公司在全國有很

【搞搞演算法遺傳演算法解決多目標規劃問題_論文閱讀筆記

這是2014年4月在其他部落格寫的,轉帖到CSDN的部落格上。 許老師給了很多多目標GA的論文,全英文讀起來比較慢,用Google翻譯+靈格斯詞典解決了詞彙問題,理解起來並不是很難,這也是GA演算法的特點——演算法本身容易理解,演算法知識不全的人(比如我)也能比較快地運用

數學建模 of python(遺傳演算法解決TSP問題)

吉吉: 在這個問題中,我們的個體就是一條一條的路線了,其目的就是找到一條總距離最短的路線。基本步驟與前兩篇文章基本類似,不過在本問題中,我們用城市路線中每個城市的經緯度來表示個體(城市路線)的DNA。 在產生後代的過程中,需要注意的是,因為我們的個體是路線,所以不能將兩個

matlab手寫遺傳演算法解決一元函式最值問題(例項

問題:找出y=x4-4x3+3x+5 (xÎ[0,6])在[0,6]之間的最小值。 思路:用33位0,1變數來編碼x,3位編碼整數,30位編碼小數。理論上30位編碼小數可以將最小值對應的x精確到小數點後九位. 下面是我解決這個問題所有的函式,複製就可以運行了,不明白可以私

遺傳演算法解決路線規劃問題(Vehicle Routing Problem based on GA)

I.問題描述 車輛路徑問題(Vehicle Routing Problem,VRP),車輛路徑問題是一種組合優化問題,它由Dantzig 和 Ramser在1959年共同提出。VRP是指一定數量的客戶,各自有不同數量的貨物需求,配送中心向客戶提供貨物,由一個車隊負責分送貨物

遺傳演算法解決車輛路徑問題

車輛路徑問題車輛路線問題(VRP)最早是由Dantzig和Ramser於1959年首次提出,它是指一定數量的客戶,各自有不同數量的貨物需求,配送中心向客戶提供貨物,由一個車隊負責分送貨物,組織適當的行車路線,目標是使得客戶的需求得到滿足,並能在一定的約束下,達到諸如路程最短、

Matlab實現遺傳演算法求車輛倒車的最佳路徑

現如今智慧啟發式演算法很普遍,用處也很多,遺傳演算法、模擬退火、蟻群演算法、粒子群演算法等都是常用的幾個智慧演算法,借用之前做的數模題目的例子,大致記錄一下遺傳演算法的Matlab實現。   題目具體分析就不闡述了,核心要求是給出由理想起始點倒車入庫的泊車策略,包括車速、

(轉)遺傳演算法優化BP神經網路的Matlab程式設計例項

此文章首次在simwe公開發表,屬於GreenSim團隊原創作品,轉載請註明!由於BP網路的權值優化是一個無約束優化問題,而且權值要採用實數編碼,所以直接利用Matlab遺傳演算法工具箱。以下貼出的程式碼是為一個19輸入變數,1個輸出變數情況下的非線性迴歸而設計的,如果要應用於其它情況,只需改動編解碼函式即可

遺傳演算法解決推箱子問題

遺傳演算法 遺傳演算法(Genetic Algorithm)是一類借鑑生物界的進化規律(適者生存,優勝劣汰遺傳機制)演化而來的隨機化搜尋方法。最早聽說這個演算法是在一門公選課上,當時瞭解的還包括蟻群演算法等。總之,這種演算法通過模擬自然界物種的繁衍,來尋找適宜生存的種群,達到尋找相

遺傳演算法解決尋路問題——Python描述

概要 我的上一篇寫遺傳演算法解決排序問題,當中思想借鑑了遺傳演算法解決TSP問題,本質上可以認為這是一類問題,就是這樣認為:尋找到一個序列X,使F(X)最大。 詳解介紹 排序問題:尋找一個序列,使得這個序列的逆序對的倒數最大。 TSP問題:尋找一個序列,使得這個序列的總路徑長的倒數最大。 這兩個問題

遺傳演算法上機系列之遺傳演算法求函式最值問題(附自己寫的程式碼)

本文基於下面的最值問題進行求解: maxf(x1,x2)=21.5+x1sin(4πx1)+x2sin(20πx2)\ max f(x_1,x_2)=21.5+x_1sin(4\pi x_1)+x_2sin(20\pi x_2)maxf(x1​,x2​)=21.

遺傳演算法解決TSP旅行商問題(附:Python實現)

前言 我先囉嗦一下:不是很喜歡寫計算智慧的演算法,因為一個演算法就要寫好久。前前後後將近有兩天的時間。 好啦,現在進入正題。 巡迴旅行商問題(TSP)是一個組合優化方面的問題,已經成為測試組合優化新演算法的標準問題。應用遺傳演算法解決 TSP 問題,首先對訪問

Python遺傳演算法程式碼例項講解

目錄 例項: 程式碼講解: 難度較大的程式碼: 全部程式碼:   例項: 求解函式的最大值y=xsin(10x)+xsin(2x),自變數取值:0--5,用Python畫出的影象如下 (注:此程式碼好像有一些感覺不對的地方,首先:沒有保留那些適應度

遺傳演算法加強足球遊戲的人工智慧

Population用std::vector容器儲存物種的所有個體(m_iColonySize個Chromosome的例項),m_dIntercrossRate、m_dAgamogenesisRate和m_dMutantRate三個變數分別是交叉率、複製率和變異率,其中染色體交叉是自然界中生物繁殖的最常見方式

遺傳演算法解決單變數函式值得優化問題

      最近稍微學習一下智慧演算法的設計,就滿Internet搜尋,最終發現遺傳演算法是大家學習最多的,也是在各個領域內進行函式優化,解析解求解過程中很重要的一種方法! 學習遺傳演算法,首先為了上手較快,我推薦大家先使用Matlab,這個工具進行矩陣分析有應用,真的很管

從零開始實現遺傳演算法(遺傳演算法破解密碼)

本系列文章的所有原始碼都將會開源,需要原始碼的小夥伴可以去我的 Github fork! 上一篇文章我們動手實驗了用遺傳演算法求解函式在給定區間的最大值。本篇文章再來看一個實驗:用遺傳演算法破解密碼。 在這個問題中,我們的個體就是一串字串了,其目的就

路徑規劃之 A* 演算法

演算法介紹 A*(念做:A Star)演算法是一種很常用的路徑查詢和圖形遍歷演算法。它有較好的效能和準確度。本文在講解演算法的同時也會提供Python語言的程式碼實現,並會藉助matplotlib庫動態的展示演算法的運算過程。 A*演算法最初發表於1968年,由Stanford研究院的Peter Hart

初學遺傳演算法解決tsp問題(C++)

前言 斷斷續續學遺傳到現在快一個禮拜了,之前一直在看思想,死想活想,始終不敢去自己程式碼實現。 今天硬著頭皮開始寫,寫不下去就找博文看,總算是初步的實現了,邁出了智慧演算法學習的第一小步,心情不可謂不激動。 好吧,說正經的。 tsp&

使用遺傳演算法解決多變數函式優化問題!

        很多朋友在碰到多變數值優化的問題的時候不能很好的將問題轉化,利用有效編碼的方法將解的個數,解的編碼很好的很合理的進行設計,因此不能利用遺傳演算法進行問題的求解!        其實,簡單的來說,就是將多個變數的數值編碼編排進去,進行組合,只需要增長基因個體的

遺傳演算法解決TSP問題

讀了原作者mylovestart用遺傳演算法實現的tsp問題,學習了ga演算法。 但發現原作者mylovestart的jiaopei()函式寫的有問題,交叉後要確保每個城市有且僅走了一次,修改了jiaopei()的程式碼如下: //交配,對每個染色體產生交配概率,滿足交配