资源简介
粒子群算法结合遗传算法的机器人路径规划算法
代码片段和文件信息
from random import randint
from random import random
from math import sqrt
from math import floor
class Particle:
g_best = [0 99 99 99 99]
CROSSOVER_PROB = 0.7
MUTATION_PROB = 0.1
W = 0.8
C1 = 1.5
C2 = 1.5
VMAX = 1
VMIN = -1
XMAX = 99
XMIN = 0
THE_MAP = None
T = 10
def __init__(self):
def starting_pos():
“““ Helper function for initializing the position of
each particle
“““
start = []
for i in range(0 3):
start.append(randint(0 99))
start = [0] + start + [99]
return start
def starting_vel():
“““ Helper function for initializing the velocity of
each particle
“““
vel = []
for i in range(0 3):
vel.append(randint(int(Particle.VMIN) int(Particle.VMAX)))
vel = [0] + vel + [0]
return vel
self.v = starting_vel()
self.x = starting_pos()
self.p_best = self.x[:]
self.fit = 0
def update_velocity(self):
“““Updates the velocity of each dimension in the particle“““
for i in range(1 len(self.v) - 1):
vel = Particle.W * self.v[i] + Particle.C1 * random()\
* (self.p_best[i] - self.x[i]) + Particle.C2 * random() * \
(Particle.g_best[i] - self.x[i])
if vel > Particle.VMAX:
pass
elif vel < Particle.VMIN:
pass
else:
self.v[i] = vel
def update_position(self):
“““Updates the position of each dimension in the particle“““
for i in range(1 len(self.x) - 1):
new_pos = int(floor((self.x[i] + self.v[i])))
if new_pos > Particle.XMAX:
pass
elif new_pos < Particle.XMIN:
pass
else:
self.x[i] = new_pos
def mutate(self):
“““Changes some parts of x based on mutation probability“““
for i in range(1 len(self.x) - 1): #don‘t mutate start of goal
dont_mutate = random()
if Particle.MUTATION_PROB > dont_mutate:
self.x[i] = randint(0 99)
def crossover(self other_particle):
“““Takes two particles and exchanges part of the solution at
a specific point
“““
crossover_position = randint(1 len(self.x) - 1)
new1_first_half = self.x[:crossover_position]
new1_second_half = other_particle.x[crossover_position:]
new = Particle()
new.x = new1_first_half
new.x.extend(new1_second_half)
new.v = self.v
new.fit = self.fit
new.p_best = self.p_best
return new
@staticmethod
def squares_of_line(segment):
“““Returns the squares a line seg
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6832 2020-11-16 17:21 classes.py
文件 4401 2020-11-16 17:21 gui.py
文件 7035 2020-11-16 17:21 pso_ga.py
文件 759 2020-11-16 17:21 README.md
文件 3238516 2020-11-16 17:21 Report.pdf
文件 79 2020-11-16 17:21 __main__.py
文件 291 2020-11-16 17:21 .idea\GA-PSO-hybrid-master.iml
文件 288 2020-11-16 17:21 .idea\misc.xm
文件 299 2020-11-16 17:21 .idea\modules.xm
文件 1730 2020-11-16 17:21 .idea\workspace.xm
文件 174 2020-11-16 17:21 .idea\inspectionProfiles\profiles_settings.xm
- 上一篇:dqn_agent-master
- 下一篇:《Python神经网络编程》源代码
相关资源
- turtlebot沿墙
- pygame-1.9.6-cp38-cp38-win_amd64.whl
- Game Programming with Python Lua And Ruby
- time series forecasting with python gakhov 高清
- pygame入门《飞机大战》源码及素材
- 零基础学习python pygame 飞机大战可执行
- pygame-1.9.6-cp37-cp37m-win32.whl
- python粒子群代码
- pso-rbf python实现
- ga-bp代码,python,pycharm
- python粒子群算法优化svm模型
- 粒子群算法Python实现.zip
- Python 植物大战僵尸代码实现
- python植物大战僵尸代码,目前全网最
- 贪吃蛇(pygame入门级)示例源码2089
- pygame教程飞机大战
- python贪吃蛇(pygame入门级示例源码)
- python弹球小游戏源码(基于pygame)
- pygame贪吃蛇
- NSGA2算法实现 Python
- Pygame游戏源代码:中国象棋
- python制作象棋程序源码(pygame)
- pygame音乐播放器
- PYTHON绘制世界人口地图
- python game
- python pygame flappybird 卷轴类小游戏
- 《Python和Pygame游戏开发指南》随书源
- Python科学计算最佳实践——SciPy指南(
- Pygame中文文档.pdf
- 蜗牛绕墙爬(python小游戏源码)
评论
共有 条评论