matlab遗传算法程序

matlab遗传算法程序,第1张

在matlab里没有

for

i

=

1

to

80

...

endfor

这样的语法的

在matlab里应该是:

for

i

=

1:

1:

80

...

end

1:1:80

第一个1是初始值,第二个是每次+1的孝李意思

当然如果是我古若败竖寡闻那也请见谅~~哈巧枯迟哈~~

function

my_ga()

options=gaoptimset

%设置变量范围

options=gaoptimset(options,'PopInitRange',[09])

%设置种群大小

options=gaoptimset(options,'PopulationSize',100)

%设置迭代次数

options=gaoptimset(options,'Generations',100)

%选择选择函数

options=gaoptimset(options,'SelectionFcn',@selectionroulette)

%选择交叉函数

options=gaoptimset(options,'CrossoverFcn',@crossoverarithmetic)

%选择变异函数

options=gaoptimset(options,'MutationFcn',@mutationuniform)

%设置绘判尘简兄明图:解的变化、种群平均值的变化

options=gaoptimset(options,'PlotFcns',{@gaplotbestf})

%执行遗传算法,fitness.m是掘裤函数文件

[x,fval]=ga(@fitness,1,options)

x = intlinprog(f,intcon,A,b,Aeq,beq)就可以了毁梁

用法团余培举例:塌唯

Write the objective function vector and vector of integervariables.

f = [-3-2-1]

intcon = 3

Write the linear inequality constraints.

A = [1,1,1]

b = 7

Write the linear equality constraints.

Aeq = [4,2,1]

beq = 12

Write the bound constraints.

lb = zeros(3,1)

ub = [InfInf1]% Enforces x(3) is binary

Call intlinprog.

x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/8188593.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存