EDA365电子论坛网
标题:
yalmip的问题
[打印本页]
作者:
shuddkk
时间:
2020-7-27 09:49
标题:
yalmip的问题
% Max z=x1^2+x2^2+3*x3^2+4*x4^2+2*x5^2-8*x1-2*x2-3*x3-x4-2*x5
3 S; W* r& L* p! G6 U& k
% s.t.
2 y! c+ e9 a- ?
% 0<=xi<=99(i=1,2,...,5)
9 t5 Q. ~8 A$ }" M E) d
% x1+x2+x3+x4+x5<=400
) ~& z5 [& i* w. j
% x1+2*x2+2*x3+x4+6*x5<=800
4 S x" m# o" j7 h/ v" J* |
% 2*x1+x2+6*x3<=800
* Y; r8 k. Q D. T( p& W# C& @6 D
% x3+x4+5*x5<=200
% A2 q% v7 ^, I! G; ~. y4 u# I
x=intvar(1,5);
$ p6 ~9 o: P3 h& [
f=[1 1 3 4 2]*(x'.^2)-[8 2 3 1 2]*x';
5 A' A8 n: X+ c4 b; R- f' ~5 @
F=[x>=0;x<=99;[1 1 1 1 1]*x'<=400;[1 2 2 1 6]*x'<=800;...
# `( L, y' r$ s/ b7 \0 Q6 e
[2 1 6 0 0]*x'<=800;[0 0 1 1 5]*x'<=200]
6 q& B1 v6 O. u9 i; C/ t
solvesdp(F,-f)
& L( c7 |& x* g# j# f
double(f)
7 Q; I" I$ z8 {2 ~
double(x)
/ ^- r2 a+ y L
3 p7 l9 ^9 c0 E
3 P: j6 m. T4 Z* L
) _5 H, ]6 o" P
ans =
' [1 d8 V& m& {* {, ^
1 H) e ^' z9 C7 z- K& Z: v
-5
9 h9 H$ w$ N; T* S+ U+ L
ans =
: k2 p7 ?/ ]# _) C, j' b
8 X' U! k9 O9 p
1 1 1 1 1 求助, 这个结果是错的!!但是我真是找不出我错哪里了。
5 U0 o% Z$ L v% T* f2 z( n& D
正确解释: 53 99 99 99 0 80199
! u9 f& ^9 V% K1 A- ?
作者:
大小的小
时间:
2020-7-27 10:28
帮你顶一下
作者:
小小鲁班
时间:
2020-7-29 13:58
Warning : The continuous relaxation may be nonconvex. This means
M8 o0 \0 E, O" C0 ^4 J# ^
that the branching process is not guaranteed to find a
; m# \' z* W: u; \9 z0 H
globally optimal solution, since the lower bound can be
+ O. a9 b1 Q) M3 a
invalid. Hence, do not trust the bound or the gap...
作者:
lupkpu9
时间:
2020-7-30 09:53
x=intvar(1,5);
2 c' Z+ f/ e7 p5 G3 M3 O
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);
' s1 V# h) I6 f+ P' l
F=[];
/ P5 _5 S z+ {: b' r7 ]
F=[F x>=0;x<=99];
. S! K- P6 t* P
F=[F x(1)+x(2)+x(3)+x(4)+x(5)<=400];
- @) V$ `* o1 B; g4 A7 `
F=[F x(1)+2*x(2)+2*x(3)+x(4)+6*x(5)<=800];
. X- ^! H/ Y- T3 o7 A
F=[F 2*x(1)+x(2)+6*x(3)<=800];
# [1 B6 d& \4 k+ Y1 d% c" B
F=[F x(3)+x(4)+5*x(5)<=200];
4 d& L: t3 R6 y, q1 F" Z6 @
ops = sdpsettings('solver', '+Gurobi'); %利用cplex求解问题
) t) b0 A- k# ]* G* Q7 i8 s
optimize(F, -f, ops);
& F9 ^5 R0 F V* J5 }- q9 o# a
%solvesdp(F,-f)
! X* X; C0 Y2 X1 l% C
double(f)
( J a% K) `' u2 W# b4 y' S9 }
double(x)
* s) b% n% u1 I) U+ d
楼主试试这个程序,可以得出正确的结果
作者:
nkkopd
时间:
2020-7-30 13:39
来学习一下
欢迎光临 EDA365电子论坛网 (https://bbs.eda365.com/)
Powered by Discuz! X3.2