当前位置:网站首页>例题 非线性整数规划
例题 非线性整数规划
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。
边栏推荐
- TCP拥塞控制详解 | 2. 背景
- Deep learning image data automatic annotation [easy to understand]
- 一年頂十年
- P6774 [NOI2020] 时代的眼泪(分块)
- Ocio V2 reverse LUT
- 2322. Remove the minimum fraction of edges from the tree (XOR and & Simulation)
- Changwan group rushed to Hong Kong stocks: the annual revenue was 289million, and Liu Hui had 53.46% voting rights
- Smart trash can (V) - light up OLED
- ETH数据集下载及相关问题
- Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers
猜你喜欢

Soul, a social meta universe platform, rushed to Hong Kong stocks: Tencent is a shareholder with an annual revenue of 1.28 billion

Linux Installation PostgreSQL + Patroni cluster problem

In MySQL and Oracle, the boundary and range of between and precautions when querying the date

剑指 Offer 25. 合并两个排序的链表

OpenHarmony如何启动远程设备的FA

【Leetcode】14. Longest Common Prefix

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

【Leetcode】14. 最长公共前缀

Sword finger offer 21 Adjust the array order so that odd numbers precede even numbers

Eye of depth (III) -- determinant of matrix
随机推荐
2、 Expansion of mock platform
Fuyuan medicine is listed on the Shanghai Stock Exchange: the market value is 10.5 billion, and Hu Baifan is worth more than 4billion
酒仙网IPO被终止:曾拟募资10亿 红杉与东方富海是股东
电脑自带软件使图片底色变为透明(抠图白底)
871. Minimum refueling times
C语言自定义函数的方法
chmod命令原理及用法详解[通俗易懂]
Flutter: 动作反馈
[leetcode] 14. Préfixe public le plus long
对接保时捷及3PL EDI案例
JS delete substring in string
TCP congestion control details | 2 background
Tech talk activity preview | building intelligent visual products based on Amazon kVs
Atcoder beginer contest 169 (B, C, D unique decomposition, e mathematical analysis f (DP))
Notice on holding a salon for young editors of scientific and Technological Journals -- the abilities and promotion strategies that young editors should have in the new era
Un an à dix ans
Eth data set download and related problems
What if the default browser cannot be set?
配置基于接口的ARP表项限制和端口安全(限制用户私自接入傻瓜交换机或非法主机接入)
Domestic relatively good OJ platform [easy to understand]