整数规划遗传算法python_ga遗传算法工具箱求解0-1整数规划问题

该博客探讨了一个0-1整数规划问题的求解,目标是最小化由多项式函数给出的成本。问题受到一个线性等式约束,即所有决策变量的和等于2,且每个决策变量只能取0或1。博主使用了MATLAB的遗传算法(GA)工具箱,通过定义适应度函数、创建和突变操作来寻找最优解。提供的MATLAB代码展示了如何配置和运行遗传算法来解决此类问题。
摘要由CSDN通过智能技术生成

% *********************************************************

% *********************************************************

% Problem:

%

% Minf(x)=-(0.644*x(1)+0.707*x(2)+0.713*x(3)+0.735*x(4)

% +0.745*x(5)+0.1755*x(1)*x(2)-0.8916*x(4)*x(5)

%

% s.t. x(1)+x(2)+x(3)+x(4)+x(5)=2

%

x(i)={0,1}(i=1,2,3,4,5)

%

% *********************************************************

% Matlab Program:

% GA for 0-1 Integer Programming

function [x,fval] = ga001(fitnessFcn,numberOfVariables,options)

% Fitness function and number of variables

% [c,ce]=ga(

函数句柄

,

变量个数

,

不等式约束系数矩阵

,

不等式约束常量向量

,

%

等式约束系数矩阵

,

等式约束常量向量

,

变量上限

,

变量下限

,

非线性约束

)

fitnessFcn

=

@(x)

-(0.644*x(1)+0.707*x(2)+0.713*x(3)+0.735*x(4)+0.745*x(5)+0.1755*x(1)*x(2)-0.8916*x(4)*x(5));

numberOfVariables = 5;

Aeq=[1 1 1 1 1];

Beq=[2];

options

=

gaoptimset('CreationFcn',@int_pop,'MutationFcn',@int_mutation,'PlotFcns',{@gaplotbestf,@gap

lotbestindiv});

[x,fval] = ga(fitnessFcn,numberOfVariables,[],[],Aeq,Beq,[],[],[],options);

%---------------------------------------------------

% Mutation function to generate childrens satisfying the range and integer

% constraints on decision variables.

function mutationChildren = int_mutation(parents,options,GenomeLength, ...

FitnessFcn,state,thisScore,thisPopulation)

shrink = .01;

scale = 1;

scale = scale - shrink * scale * state.Generation/options.Generations;

range = options.PopInitRange;

lower = range(1,:);

upper = range(2,:);

scale = scale * (upper - lower);

mutationPop =

length(parents);

% The use of ROUND function will make sure that childrens are integers.

mutationChildren =

repmat(lower,mutationPop,1) +

...

round(repmat(scale,mutationPop,1) .* rand(mutationPop,GenomeLength));

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值