当前位置:网站首页>例题 非线性整数规划
例题 非线性整数规划
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。
边栏推荐
- LeetCode:1380. Lucky number in matrix -- simple
- Jiuxian's IPO was terminated: Sequoia and Dongfang Fuhai were shareholders who had planned to raise 1billion yuan
- Flutter: 动作反馈
- The poor family once again gave birth to a noble son: Jiangxi poor county got the provincial number one, what did you do right?
- Baobab's gem IPO was terminated: Tang Guangyu once planned to raise 1.8 billion to control 47% of the equity
- 【Leetcode】13. Roman numeral to integer
- 亚马逊云科技 Community Builder 申请窗口开启
- Fuyuan medicine is listed on the Shanghai Stock Exchange: the market value is 10.5 billion, and Hu Baifan is worth more than 4billion
- PhD battle-11 preview | review and prospect backdoor attack and defense of neural network
- Use of openpose
猜你喜欢

Interpretation of key parameters in MOSFET device manual

酒仙网IPO被终止:曾拟募资10亿 红杉与东方富海是股东

如何与博格华纳BorgWarner通过EDI传输业务数据?

Eth data set download and related problems

剑指 Offer 21. 调整数组顺序使奇数位于偶数前面

MOSFET器件手册关键参数解读

Geoserver: publishing PostGIS data sources

Error when uploading code to remote warehouse: remote origin already exists

几行代码搞定RPC服务注册和发现

伟立控股港交所上市:市值5亿港元 为湖北贡献一个IPO
随机推荐
Easy language ABCD sort
亚马逊云科技 Community Builder 申请窗口开启
QStyle实现自绘界面项目实战(二)
P6774 [NOI2020] 时代的眼泪(分块)
默认浏览器设置不了怎么办?
Talk about an experience of job hopping and being rejected
Changwan group rushed to Hong Kong stocks: the annual revenue was 289million, and Liu Hui had 53.46% voting rights
移动应用性能工具探索之路
A few lines of code to complete RPC service registration and discovery
Interpretation of key parameters in MOSFET device manual
Error when uploading code to remote warehouse: remote origin already exists
OpenHarmony如何启动远程设备的FA
Use of openpose
VMware install win10 image
visibilitychange – 指定标签页可见时,刷新页面数据
What if the default browser cannot be set?
The beginning of life
超卓航科上市:募资9亿市值超60亿 成襄阳首家科创板企业
traceroute命令讲解
IDEA2021.1 安装教程