资源简介
非常简单的Python蚁群算法,智能算法入门,欢迎下载!
代码片段和文件信息
‘‘‘
Created on Apr 3 2015
@author: Ke Wang
@see: Artificial Bee Colony Algorithm ABCA 蚁群算法
‘‘‘
import random
import copy
import numpy as np
import time
class Source():
‘‘‘
Location Pattern
Near Location
Distance
Fitness
‘‘‘
def __init__(self **sourceInfo):
self.setPara(**sourceInfo)
self.fitness = self.getFitness(self.pattern)
#//__init__
def setPara(self **sourceInfo):
self.sourceInfo = sourceInfo
self.limit = sourceInfo[‘limit‘]
self.pattern = sourceInfo[‘pattern‘]
self.randLocation = sourceInfo[‘randLocation‘] #function
self.getDistance = sourceInfo[‘getDistance‘] #function
if ‘location‘ not in sourceInfo:
self.location = self.randLocation()
else:
self.location = sourceInfo[‘location‘]
#//setPara
def getFitness(self source):
self.fitness = 1.0/self.getDistance(self.patternself.location)
return self.fitness
#//getFitness
def compareSource(self newSource):
return self.fitness - newSource.fitness
#//compareSource
###### create Near Source ######
def createNearSource(self anotherBeelocation):
theSourceInfo = copy.deepcopy(self.sourceInfo)
theSourceInfo[‘location‘] = self.location[:]
for i in range(len(self.location)):
theSourceInfo[‘location‘][i] = self.location[i] + random.uniform(-11)*(self.location[i]-anotherBeelocation[i])
nearSource = Source(**theSourceInfo)
return nearSource
#//createNearSource
class Bee():
‘‘‘
Leader Bee
next action:
~1 recruit and back current source
~2 give up current source to explore
~3 don‘t recruit and go back current source
‘‘‘
def __init__(self abc **para):
self.source = Source(**abc.sourceInfo)
self.setPara(**para)
self.abc = abc
self.state = self.actionChoice()
#//__init__
def setPara(self **para):
if ‘fitnessThreshold‘ not in para: self.fitnessThreshold = 0
else: self.fitnessThreshold = para[‘fitnessThreshold‘]
#//setPara
def actionChoice(self):
if self.source.fitness < self.fitnessThreshold or self.source.limit <= 0:
self.isRecruit = 1
self.exploreNewSource()
self.source.limit-=1
return 2 #if source is ran out or not fit then give up this and explore new one
if random.random() < 0: ### parameter that leader bee don‘t recruit and back source
self.isRecruit = 0
self.source.limit -=1
return 3
else:
self.isRecruit = 1
self.source.limit -=1
return 1
#//actionChoice
- 上一篇:Python爬虫教程千万别错过
- 下一篇:树莓派目标跟踪代码python
相关资源
- 树莓派目标跟踪代码python
- Python爬虫教程千万别错过
- get_wuyou.zip
- python入门到精通某智付费课程超级完
- 用python代码把背景颜色过滤掉
- python所有源代码
- PyHook3-1.6.1-cp36-cp36m-win32.whl
- L2正则化python实现案例()
- tensorflow手写数字识别python源码案例
- 批量excel转shp(面)python
- python ds evidence theory code
- Python串口调试助手
- 推荐系统物质扩散代码python
- 基于python的行人重识别代码
- 基于Python语言的SAD算法进行双目立体
- Python 聊天室 客户端和服务端 聊天
- python随机森林应用
- 肺实质分割python代码
- 基于python2.7的LeNet5源代码实现
- caffe_log绘制accuracy和loss曲线python3
- Python+OpenCv实现AI人脸识别身份认证系
- Tensorflow之CNN实现CIFAR-10图像的分类p
- python零基础入门视频 百度云资源
- Python和pyqt5中安装VTK实现三维数据可视
- Python3.x+Pyqt5实现界面左侧导航栏的抽
- Python3.x+Pyqt5制作GUI界面的案例
- Python-2.7.2-xcompile.patch
- PIL中文手册.pdf
- Python操作MySQL数据进行图片存取操作
- win 10 python 3.7 pygraphviz 安装包
评论
共有 条评论