@Heath
2015-11-01T16:43:18.000000Z
字数 5231
阅读 1126
13331130 李有才
人工智能
可以使用A*算法
function Find-Route(Page page1, Page page2) return a pathpage1 <-- 初始页面page2 <-- 目标页面//按照评估函数f(n)排序的优先权队列pri-queue <-- sorted by WebPage.RelevancyToEndPage//记录访问过的节点visitedpri-queue.INSERT(page1)loop doif EMPTY(pri-queue)thenreturn failure//选择与目标网页相关度最高的节点currentPage <-- pri-queue.POPadd currentPage to visitedif currentPage is page2thenreturn pathelsefor each item in AdjacentPages(currentPage) doif item is not in visitedthencurrentPage.NEXT <-- itemrelevance ← CaltulateRelevancyToEndPage(item)pri-queue.INSERT-WITH-PRIORITY(item, relevance)
搜索引擎保存了页面之间的相互关系,可以实现一个前任函数,同样也适用双向搜索
Format:
f:g+h
1.L:0+244=244
2. 扩展L :
M:70+241=311 ,T:111+329=440
3. 扩展M :
L:140+244=384 ,D:145+242=387 ,T:111+329=440
4. 扩展L :
D:145+242=387 ,T:111+329=440 ,M:210+241=451 ,T1:251+329=580
5. 扩展D :
C:265+160=425 ,T:111+329=440 ,M:210+241=451 ,M:220+241=461 ,T1:251+329=580
6. 扩展C
T:111+329=440 ,M:210+241=451 ,M1:220+241=461 ,P:403+100=503 ,T1:251+329=580 ,R:411+193=604 ,D:385+242=627
7. 扩展T :
M:210+241=451 ,M1:220+241=461 ,L:222+244=466 ,P:403+100=503 ,T1:251+329=580 ,A:229+366=595 ,R:411+193=604 ,D:385+242=627
8. 扩展M :
M1:220+241=461 ,L:222+244=466 ,P:403+100=503 ,L1:280+244=524 ,D:285+242=527 ,T1:251+329=580 ,A:229+366=595 ,R:411+193=604 ,D1:385+242=627
9. 扩展M1 :
L:222+244=466 ,P:403+100=503 ,L1:280+244=524 ,D:285+242=527 ,L2:290+244=534 ,D2:220+75+242=537 ,T1:251+329=580 ,A:229+366=595 ,R:411+193=604 ,D1:385+242=627
10. 扩展L :
P:403+100=503 ,L1:280+244=524 ,D:285+242=527 ,M:222+70+241=533 ,L2:290+244=534 ,D2:220+75+242=537 ,T1:251+329=580 ,A:229+366=595 ,R:411+193=604 ,D1:385+242=627 ,T:222+111+329=662
11. 扩展P :
B:504+0=504 ,L1:280+244=524 ,D:285+242=527 ,M:222+70+241=533 ,L2:290+244=534 ,D2:220+75+242=537 ,T1:251+329=580 ,A:229+366=595 ,R:411+193=604 ,D1:385+242=627 ,T:222+111+329=662 ,R:500+193=693, C: 541 + 160 = 701$
12. B在队首,找到路径
a)状态空间
(n∗n)(n∗(n−1))....n
b)5n
c)曼哈顿距离
d)选择min(h1,...,h2)
a)旅行商问题要求从起点开始每个城市访问一次,最终回到起点。最小生成树连接所有点,但不能形成环,所以可以看作从旅行商问题减少了“形成环”这一限制(即通过松弛的TSP问题)得到的。
b)MST启发式考虑了城市之间的连接路径,直线距离在城市数量增多时准确性下降很快
c)
function GenerateTSP(CityNumber N) return a instanceInstance <-- the final graph to returnSquare <-- domainfor i = 1 to Nposition <-- getRandomPositionFromSquare(Square)Instance.city[N].setPosition(position)
d)
function TSPSolution(Instance instance) return a pathroads[N][N] <-- roads between sitiesstartCity <-- instacne.StartCitypri-queue <-- 按以未到达城市为根节点生成的MST的边长之和排序visitedpri-queue.INSERT(startCity)loop doif pri-queue.EMPTYthenreturn failurecurrentCity <-- pri-queue.POPvisited[currentCity] <-- truefor i in roads[N]if i is startCity and AllCityVisitedthenreturn pathif i is not currentCity and cisited[i] is faslethenvisited[i] = trueweight <-- GetMSTValue(roads, visited)pri-queue.INSETR-WITH_PRIORITY(currnetCity, weight)explored[i] <-- false
// 使用Kruskal算法求解最小生成树function Get-MST-Value(roads, visited) returns a valuecities ← Get-Unexplored-Cities(visited)edge ← Get-Roads-Between-Unexplored-Cities(roads)value ← zeroviewed ← empty setloop doif All-Viewed()thenreturn valueedgeNow ← POP-Min-Weight-Edge(edge)if edgeNow.start and edgeNow.end are all in viewedthencontinuevalue.ADD(edgeNow.weight)viewed.INSERT(edgeNow.start)viewed.INSERT(edgeNow.end)
曼哈顿距离
function Get-Manhattan-Distance() return a valuevalue <-- zerocurrentNodeState <-- the current state of the eight numtargetNodeState <-- the target state of the eight numfor node in currentNodeState donowPosition <-- node.getPosition()num <-- nowPosition.getNum()targetPosition <-- targetNodeState.getNodeAt(num).getPosition()colDis <-- abs(nowPosition.col-targetPosition.col)rowDis <-- abs(nowPosition.row-targetPosition.row)value.ADD((int)sqrt(pow(colDis, 2)+pow(rowDis, 2)))return value
错位棋子数
function Get-Wrong-Node-Count() returns a valuevalue <-- zerocurrentNodeState <-- the current state of the eight numtargetNodeState <-- the target state of the eight numfor node in currentNodeState donowPosition <-- node.getPosition()num ← nowPosition.getNum()targetPosition <-- targetNodeState.getNodeAt(num).getPosition()if nowPosition is not targetPosition thenvalue.ADD(1)return value
后续节点不正确的个数
function Get-Wrong-Node-Count() returns a valuevalue <-- zerocurrentNodeState <-- the current state of the eight numfor node in currentNodeState donowPosition <-- node.getPosition()nowNextPosition <-- nowPosition.getNext()nextNodePosition <-- node.next().getPosition()if nowNextPosition is not nextNodePosition thenvalue.ADD(1)return value
| 所使用启发式 | 求解过程中平均创建节点数(随机50次) |
|---|---|
| 曼哈顿距离 | 227 |
| 错位棋子数 | 614 |
| 后续节点不正确的数码个数 | 1983 |