当前位置:网站首页>例题 非线性整数规划
例题 非线性整数规划
2022-07-02 14:48:00 【__Rain】
例1
题目如下
采用蒙特卡洛法(随机取样法)
虽然计算最优解不太现实,但是应用概率理论可以证明,在一定的计算量的情况下,完全可以得出一个满意解
此算法实现非常简单,易于理解,暴力循环随机数维护最大值即可
1)首先编写 M M M 文件 m e n g t e . m mengte.m mengte.m 定义目标函数 f f f 和约束向量函数 g g g,程序如下
注意到 g g g 的本质是一个 5 × 1 5\times1 5×1 的列向量
function [f,g]=mengte(x);
%输入参数x, 返回值[f,g], 函数名称mengte
f=x(1)^2+x(2)^2+3*x(3)^2+4*x(4)^2+2*x(5)^2-8*x(1)-2*x(2)-3*x(3)...
-x(4)-2*x(5);
g=[sum(x)-400
x(1)+2*x(2)+2*x(3)+x(4)+6*x(5)-800
2*x(1)+x(2)+6*x(3)-200
x(3)+x(4)+5*x(5)-200];
end
2)编写 M M M 文件 w o r k . m work.m work.m 求解问题答案
rand('state', sum(clock));
Max=-10000000;%函数最值初始化为负无穷
tic%显示运行时间
for i=1:10^6
x=99*rand(5,1);%生成5*1的随机实数矩阵
x1=floor(x);x2=ceil(x);%取整
[f,g]=mengte(x1);
if sum(g<=0)==4%输入参数为x1时,如果所有不等式都满足
if Max<=f%维护一下函数最值
Max=f;
ans=x1;
end
end
[f,g]=mengte(x2);%重复
if sum(g<=0)==4
if Max<=f
Max=f;
ans=x2;
end
end
end
ans,Max
toc
lingo解法
model:
sets:
row/1..4/:b;
col/1..5/:c1,c2,x;
link(row,col):a;
endsets
data:
c1=1,1,3,4,2;
c2=-8,-2,-3,-1,-2;
a=1 1 1 1 1
1 2 2 1 6
2 1 6 0 0
0 0 1 1 5;
b=400,800,200,200;
enddata
max=@sum(col:c1*x^2+c2*x);
@for(row(i):@sum(col(j):a(i,j)*x(j))<b(i));
@for(col:@gin(x));
@for(col:@bnd(0,x,99));
end
例二



解:
1)编写 M M M 文件 f u n 1. m fun1.m fun1.m 定义目标函数
function f=fun1(x);
f=sum(x.^2)+8;
2)编写 M M M 文件 f u n 2. m fun2.m fun2.m 定义非线性约束条件
function [g,h]=fun2(x);
g=[-x(1)^2+x(2)-x(3)^2%非线性不等式约束
x(1)+x(2)^2+x(3)^3-20];
h=[-x(1)-x(2)^2+2%非线性等式约束
x(2)+2*x(3)^2-3];
3)编写主程序
options=optimset('largescale', 'off');
[x,y]=fmincon('fun1',rand(3,1),[],[],[],[],...
zeros(3,1),[],'fun2',options)
可以求得 x 1 = 0.5522 , x 2 = 1.2033 , x 3 = 0.9478 x_1=0.5522,x_2=1.2033,x_3=0.9478 x1=0.5522,x2=1.2033,x3=0.9478 时,最小值 y = 10.6511 y=10.6511 y=10.6511。
边栏推荐
- Goodbye, shucang. Alibaba's data Lake construction strategy is really awesome!
- Sword finger offer 21 Adjust the array order so that odd numbers precede even numbers
- 剑指 Offer 27. 二叉树的镜像
- 【Leetcode】14. 最长公共前缀
- Easy language ABCD sort
- Sword finger offer 26 Substructure of tree
- Nexus简介及小白使用IDEA打包上传到Nexus3私服详细教程
- 几行代码搞定RPC服务注册和发现
- Geoserver: publishing PostGIS data sources
- Timing / counter of 32 and 51 single chip microcomputer
猜你喜欢

Use of openpose

上传代码到远程仓库报错error: remote origin already exists.

A few lines of code to complete RPC service registration and discovery

移动应用性能工具探索之路

Blog theme "text" summer fresh Special Edition

Tech Talk 活动预告 | 基于Amazon KVS打造智能视觉产品

使用知行之桥的API端口,提供资源供合作伙伴访问

Understand one article: four types of data index system

深度之眼(二)——矩阵及其基本运算

Experience home office, feel the completion of the project | community essay solicitation
随机推荐
Timing / counter of 32 and 51 single chip microcomputer
IDEA2021.1 安装教程
Eth data set download and related problems
How openharmony starts FA of remote devices
chmod命令原理及用法详解[通俗易懂]
IP address translation address segment
畅玩集团冲刺港股:年营收2.89亿 刘辉有53.46%投票权
一年顶十年
ssb门限_SSB调制「建议收藏」
[leetcode] 14. Préfixe public le plus long
Ocio V2 reverse LUT
人生的开始
剑指 Offer 26. 树的子结构
关于我
Configure MySQL under Linux to authorize a user to access remotely, which is not restricted by IP
Easy language ABCD sort
The computer comes with software to make the background color of the picture transparent (matting white background)
QStyle实现自绘界面项目实战(二)
Tech talk activity preview | building intelligent visual products based on Amazon kVs
宝宝巴士创业板IPO被终止:曾拟募资18亿 唐光宇控制47%股权