当前位置:网站首页>Example nonlinear integer programming
Example nonlinear integer programming
2022-07-02 17:26:00 【__ Rain】
example 1
The title is as follows 
Using Monte Carlo method ( Random sampling method )
Although calculating the optimal solution is not realistic , But the application of probability theory can prove , In the case of a certain amount of calculation , A satisfactory solution can be obtained
The implementation of this algorithm is very simple , Easy to understand , Maintain the maximum value of random number of violent cycle
1) First write M M M file m e n g t e . m mengte.m mengte.m Define the objective function f f f and Constraint vector function g g g, The procedure is as follows
be aware g g g The essence of 5 × 1 5\times1 5×1 The column vector
function [f,g]=mengte(x);
% Input parameters x, Return value [f,g], The name of the function 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) To write M M M file w o r k . m work.m work.m Answer the question
rand('state', sum(clock));
Max=-10000000;% The maximum value of the function is initialized to negative infinity
tic% Show run time
for i=1:10^6
x=99*rand(5,1);% Generate 5*1 Random real matrix of
x1=floor(x);x2=ceil(x);% integer
[f,g]=mengte(x1);
if sum(g<=0)==4% Input parameter is x1 when , If all inequalities are satisfied
if Max<=f% Maintain the maximum value of the function
Max=f;
ans=x1;
end
end
[f,g]=mengte(x2);% repeat
if sum(g<=0)==4
if Max<=f
Max=f;
ans=x2;
end
end
end
ans,Max
toc
lingo solution
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
Example 2



Explain :
1) To write M M M file f u n 1. m fun1.m fun1.m Define the objective function
function f=fun1(x);
f=sum(x.^2)+8;
2) To write M M M file f u n 2. m fun2.m fun2.m Define nonlinear constraints
function [g,h]=fun2(x);
g=[-x(1)^2+x(2)-x(3)^2% Nonlinear inequality constraints
x(1)+x(2)^2+x(3)^3-20];
h=[-x(1)-x(2)^2+2% Nonlinear equality constraints
x(2)+2*x(3)^2-3];
3) Write main program
options=optimset('largescale', 'off');
[x,y]=fmincon('fun1',rand(3,1),[],[],[],[],...
zeros(3,1),[],'fun2',options)
Can be found 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 when , minimum value y = 10.6511 y=10.6511 y=10.6511.
边栏推荐
- 绿竹生物冲刺港股:年期内亏损超5亿 泰格医药与北京亦庄是股东
- Dstat use [easy to understand]
- QWebEngineView崩溃及替代方案
- After meeting a full stack developer from Tencent, I saw what it means to be proficient in MySQL tuning
- Listing of chaozhuo Aviation Technology Co., Ltd.: raising 900million yuan, with a market value of more than 6billion yuan, becoming the first science and technology innovation board enterprise in Xia
- Sword finger offer 26 Substructure of tree
- chmod命令原理及用法详解[通俗易懂]
- How to transfer business data with BorgWarner through EDI?
- Sword finger offer 25 Merge two sorted linked lists
- 伟立控股港交所上市:市值5亿港元 为湖北贡献一个IPO
猜你喜欢

【Leetcode】13. 罗马数字转整数

默认浏览器设置不了怎么办?

TCP congestion control details | 2 background

Sword finger offer 26 Substructure of tree

Listing of chaozhuo Aviation Technology Co., Ltd.: raising 900million yuan, with a market value of more than 6billion yuan, becoming the first science and technology innovation board enterprise in Xia

【Leetcode】14. 最长公共前缀

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

How to transfer business data with BorgWarner through EDI?

简单线性规划问题

Smart trash can (V) - light up OLED
随机推荐
Seven charts, learn to do valuable business analysis
A case study of college entrance examination prediction based on multivariate time series
移动应用性能工具探索之路
Sword finger offer 27 Image of binary tree
Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
si446使用记录(一):基本资料获取
13、Darknet YOLO3
Chmod command principle and usage details [easy to understand]
ETH数据集下载及相关问题
OpenHarmony如何启动FA(本地和远程)
详细介绍scrollIntoView()方法属性
[leetcode] 14. Préfixe public le plus long
从收集到输出:盘点那些强大的知识管理工具——优秀笔记软件盘点(四)
求简单微分方程
什么是敏捷开发流程
AP and F107 data sources and processing
After meeting a full stack developer from Tencent, I saw what it means to be proficient in MySQL tuning
JS20 数组扁平化
uniapp H5页面调用微信支付
si446使用记录(二):使用WDS3生成头文件