没有合适的资源?快使用搜索试试~ 我知道了~
遗传算法解决欺骗性问题1
资源详情
资源评论
资源推荐
作业 5:GA 实验
The deceptive functions are a family of functions in which there exists low-order building blocks
that do not combine to form the higher-order building blocks. Here, a deceptive problem that
consists of 25 copies of the order-4 fully deceptive function DF2 is constructed for this paper.
DF2 can be described as follows:
f(0000)=28
f(0001)=26
f(0010)=24
f(0011)=18
f(0100)=22
f(0101)=6
f(0110)=14
f(0111)=0
f(1000)=20
f(1001)=12
f(1010)=10
f(1011)=2
f(1100)=8
f(1101)=4
f(1110)=6
f(1111)=30
This problem has a maximal function value of 750.
代码如下:
import numpy as np
import math
from matplotlib import pyplot as plt
DNA_size = 100 # DNA 长度
population_size = 400 # 种群大小
cross_rate = 0.85 # 交叉率
mutation_rate = 0.0005 # 变异率
iter_N = 180 # 迭代 270 次
population_value = [] # 适应值数组,用来装适应值
child_new = []
population = np.random.randint(2, size=(population_size, DNA_size)) # 初始化种群 DNA,小
于 2 表示数值为 0 或 1。大小为 400x100 的矩阵
np.set_printoptions(threshold=np.inf)
def translation(population): # 翻译 DNA
for i in range(population_size):
sum = 0 # 归 0
for j in range(25):
x_bits = list(population[i][4 * j:4 * (j + 1)])
if (x_bits == [0, 0, 0, 0]):
sum = sum + 28
elif (x_bits == [0, 0, 0, 1]):
sum = sum + 26
elif (x_bits == [0, 0, 1, 0]):
sum = sum + 24
elif (x_bits == [0, 0, 1, 1]):
sum = sum + 18
elif (x_bits == [0, 1, 0, 0]):
顾露
- 粉丝: 15
- 资源: 315
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0