problems when changing objective function from first order to second order

25 views
Skip to first unread message

bin sun

unread,
Dec 5, 2017, 8:05:34 PM12/5/17
to YALMIP
Dear Johan,

I build a program to get the maximum value. At first, all values are on x-direction, So the objective function is first order matrix: f=-sum(conBx*I');
But then the values have both x-direction and y-direction values, So the objective function is second order matrix: f=-((sum(conBx*I'))^2+(sum(conBy*I'))^2);
Then MATLAB can't solve it. I think the problem changes to Quadratic programming. Could you tell me how to solve this problem? (All intvar can be sdpvar if need)

The code are attached below.

Thank you very much for your time,
Best,
Bin
Message has been deleted

bin sun

unread,
Dec 5, 2017, 8:08:27 PM12/5/17
to YALMIP

conBx=[0,0,0,0,0,1.83486238532110,1.83486238532110,1.10497237569061,0.615384615384615,0.369685767097967,0.977995110024450,0.977995110024450,0.831600831600832,0.640000000000000,0.475624256837099;0,0,0,0,0,1.10497237569061,1.83486238532110,1.83486238532110,1.10497237569061,0.615384615384615,0.831600831600832,0.977995110024450,0.977995110024450,0.831600831600832,0.640000000000000;0,0,0,0,0,0.615384615384615,1.10497237569061,1.83486238532110,1.83486238532110,1.10497237569061,0.640000000000000,0.831600831600832,0.977995110024450,0.977995110024450,0.831600831600832;0,0,0,0,0,0.369685767097967,0.615384615384615,1.10497237569061,1.83486238532110,1.83486238532110,0.475624256837099,0.640000000000000,0.831600831600832,0.977995110024450,0.977995110024450;-1.83486238532110,-1.83486238532110,-1.10497237569061,-0.615384615384615,-0.369685767097967,0,0,0,0,0,1.83486238532110,1.83486238532110,1.10497237569061,0.615384615384615,0.369685767097967;-1.10497237569061,-1.83486238532110,-1.83486238532110,-1.10497237569061,-0.615384615384615,0,0,0,0,0,1.10497237569061,1.83486238532110,1.83486238532110,1.10497237569061,0.615384615384615;-0.615384615384615,-1.10497237569061,-1.83486238532110,-1.83486238532110,-1.10497237569061,0,0,0,0,0,0.615384615384615,1.10497237569061,1.83486238532110,1.83486238532110,1.10497237569061;-0.369685767097967,-0.615384615384615,-1.10497237569061,-1.83486238532110,-1.83486238532110,0,0,0,0,0,0.369685767097967,0.615384615384615,1.10497237569061,1.83486238532110,1.83486238532110;-0.977995110024450,-0.977995110024450,-0.831600831600832,-0.640000000000000,-0.475624256837099,-1.83486238532110,-1.83486238532110,-1.10497237569061,-0.615384615384615,-0.369685767097967,0,0,0,0,0;-0.831600831600832,-0.977995110024450,-0.977995110024450,-0.831600831600832,-0.640000000000000,-1.10497237569061,-1.83486238532110,-1.83486238532110,-1.10497237569061,-0.615384615384615,0,0,0,0,0;-0.640000000000000,-0.831600831600832,-0.977995110024450,-0.977995110024450,-0.831600831600832,-0.615384615384615,-1.10497237569061,-1.83486238532110,-1.83486238532110,-1.10497237569061,0,0,0,0,0;-0.475624256837099,-0.640000000000000,-0.831600831600832,-0.977995110024450,-0.977995110024450,-0.369685767097967,-0.615384615384615,-1.10497237569061,-1.83486238532110,-1.83486238532110,0,0,0,0,0];
conBy=[-6.66666666666667,6.66666666666667,2.22222222222222,1.33333333333333,0.952380952380953,-0.550458715596330,0.550458715596330,0.994475138121547,0.923076923076923,0.776340110905730,-0.146699266503667,0.146699266503667,0.374220374220374,0.480000000000000,0.499405469678954;-2.22222222222222,-6.66666666666667,6.66666666666667,2.22222222222222,1.33333333333333,-0.994475138121547,-0.550458715596330,0.550458715596330,0.994475138121547,0.923076923076923,-0.374220374220374,-0.146699266503667,0.146699266503667,0.374220374220374,0.480000000000000;-1.33333333333333,-2.22222222222222,-6.66666666666667,6.66666666666667,2.22222222222222,-0.923076923076923,-0.994475138121547,-0.550458715596330,0.550458715596330,0.994475138121547,-0.480000000000000,-0.374220374220374,-0.146699266503667,0.146699266503667,0.374220374220374;-0.952380952380953,-1.33333333333333,-2.22222222222222,-6.66666666666667,6.66666666666667,-0.776340110905730,-0.923076923076923,-0.994475138121547,-0.550458715596330,0.550458715596330,-0.499405469678954,-0.480000000000000,-0.374220374220374,-0.146699266503667,0.146699266503667;-0.550458715596330,0.550458715596330,0.994475138121547,0.923076923076923,0.776340110905730,-6.66666666666667,6.66666666666667,2.22222222222222,1.33333333333333,0.952380952380953,-0.550458715596330,0.550458715596330,0.994475138121547,0.923076923076923,0.776340110905730;-0.994475138121547,-0.550458715596330,0.550458715596330,0.994475138121547,0.923076923076923,-2.22222222222222,-6.66666666666667,6.66666666666667,2.22222222222222,1.33333333333333,-0.994475138121547,-0.550458715596330,0.550458715596330,0.994475138121547,0.923076923076923;-0.923076923076923,-0.994475138121547,-0.550458715596330,0.550458715596330,0.994475138121547,-1.33333333333333,-2.22222222222222,-6.66666666666667,6.66666666666667,2.22222222222222,-0.923076923076923,-0.994475138121547,-0.550458715596330,0.550458715596330,0.994475138121547;-0.776340110905730,-0.923076923076923,-0.994475138121547,-0.550458715596330,0.550458715596330,-0.952380952380953,-1.33333333333333,-2.22222222222222,-6.66666666666667,6.66666666666667,-0.776340110905730,-0.923076923076923,-0.994475138121547,-0.550458715596330,0.550458715596330;-0.146699266503667,0.146699266503667,0.374220374220374,0.480000000000000,0.499405469678954,-0.550458715596330,0.550458715596330,0.994475138121547,0.923076923076923,0.776340110905730,-6.66666666666667,6.66666666666667,2.22222222222222,1.33333333333333,0.952380952380953;-0.374220374220374,-0.146699266503667,0.146699266503667,0.374220374220374,0.480000000000000,-0.994475138121547,-0.550458715596330,0.550458715596330,0.994475138121547,0.923076923076923,-2.22222222222222,-6.66666666666667,6.66666666666667,2.22222222222222,1.33333333333333;-0.480000000000000,-0.374220374220374,-0.146699266503667,0.146699266503667,0.374220374220374,-0.923076923076923,-0.994475138121547,-0.550458715596330,0.550458715596330,0.994475138121547,-1.33333333333333,-2.22222222222222,-6.66666666666667,6.66666666666667,2.22222222222222;-0.499405469678954,-0.480000000000000,-0.374220374220374,-0.146699266503667,0.146699266503667,-0.776340110905730,-0.923076923076923,-0.994475138121547,-0.550458715596330,0.550458715596330,-0.952380952380953,-1.33333333333333,-2.22222222222222,-6.66666666666667,6.66666666666667];
c=[1,0.385740902327350,0.252086400923626,0.180051756213799,0.134338625773115,0.325338695211755,0.295705615296013,0.240842798639231,0.191650596650322,0.153143736484782,0.222078208657532,0.214373745067129,0.194964191180765,0.170819554580032,0.146923179202373;0.385740902327350,1,0.385740902327350,0.252086400923626,0.180051756213799,0.295705615296013,0.325338695211755,0.295705615296013,0.240842798639231,0.191650596650322,0.214373745067129,0.222078208657532,0.214373745067129,0.194964191180765,0.170819554580032;0.252086400923626,0.385740902327350,1,0.385740902327350,0.252086400923626,0.240842798639231,0.295705615296013,0.325338695211755,0.295705615296013,0.240842798639231,0.194964191180765,0.214373745067129,0.222078208657532,0.214373745067129,0.194964191180765;0.180051756213799,0.252086400923626,0.385740902327350,1,0.385740902327350,0.191650596650322,0.240842798639231,0.295705615296013,0.325338695211755,0.295705615296013,0.170819554580032,0.194964191180765,0.214373745067129,0.222078208657532,0.214373745067129;0.134338625773115,0.180051756213799,0.252086400923626,0.385740902327350,1,0.153143736484782,0.191650596650322,0.240842798639231,0.295705615296013,0.325338695211755,0.146923179202373,0.170819554580032,0.194964191180765,0.214373745067129,0.222078208657532;0.325338695211755,0.295705615296013,0.240842798639231,0.191650596650322,0.153143736484782,1,0.466460145990755,0.329302816953880,0.252086400923626,0.200224074540065,0.393354638909619,0.363016356053394,0.306125955898918,0.253820992122854,0.211436578165977;0.295705615296013,0.325338695211755,0.295705615296013,0.240842798639231,0.191650596650322,0.466460145990755,1,0.466460145990755,0.329302816953880,0.252086400923626,0.363016356053394,0.393354638909619,0.363016356053394,0.306125955898918,0.253820992122854;0.240842798639231,0.295705615296013,0.325338695211755,0.295705615296013,0.240842798639231,0.329302816953880,0.466460145990755,1,0.466460145990755,0.329302816953880,0.306125955898918,0.363016356053394,0.393354638909619,0.363016356053394,0.306125955898918;0.191650596650322,0.240842798639231,0.295705615296013,0.325338695211755,0.295705615296013,0.252086400923626,0.329302816953880,0.466460145990755,1,0.466460145990755,0.253820992122854,0.306125955898918,0.363016356053394,0.393354638909619,0.363016356053394;0.153143736484782,0.191650596650322,0.240842798639231,0.295705615296013,0.325338695211755,0.200224074540065,0.252086400923626,0.329302816953880,0.466460145990755,1,0.211436578165977,0.253820992122854,0.306125955898918,0.363016356053394,0.393354638909619;0.222078208657532,0.214373745067129,0.194964191180765,0.170819554580032,0.146923179202373,0.393354638909619,0.363016356053394,0.306125955898918,0.253820992122854,0.211436578165977,1,0.524174672752980,0.385740902327350,0.306520997093035,0.252086400923626;0.214373745067129,0.222078208657532,0.214373745067129,0.194964191180765,0.170819554580032,0.363016356053394,0.393354638909619,0.363016356053394,0.306125955898918,0.253820992122854,0.524174672752980,1,0.524174672752980,0.385740902327350,0.306520997093035;0.194964191180765,0.214373745067129,0.222078208657532,0.214373745067129,0.194964191180765,0.306125955898918,0.363016356053394,0.393354638909619,0.363016356053394,0.306125955898918,0.385740902327350,0.524174672752980,1,0.524174672752980,0.385740902327350;0.170819554580032,0.194964191180765,0.214373745067129,0.222078208657532,0.214373745067129,0.253820992122854,0.306125955898918,0.363016356053394,0.393354638909619,0.363016356053394,0.306520997093035,0.385740902327350,0.524174672752980,1,0.524174672752980;0.146923179202373,0.170819554580032,0.194964191180765,0.214373745067129,0.222078208657532,0.211436578165977,0.253820992122854,0.306125955898918,0.363016356053394,0.393354638909619,0.252086400923626,0.306520997093035,0.385740902327350,0.524174672752980,1];
d=[401933.568419812,401933.568419812,401933.568419812,401933.568419812,401933.568419812,401933.568419812,401933.568419812,401933.568419812,401933.568419812,401933.568419812,401933.568419812,401933.568419812,401933.568419812,401933.568419812,401933.568419812];


I=intvar(1,15); 
pos=binvar(1,15); 
intvar Ibase;     %balanced


f=-((sum(conBx*I'))^2+(sum(conBy*I'))^2);

desired = [ zeros(1,12) Ibase  Ibase Ibase];   
F=[implies(pos,I== 0)];
F=F+[sum(pos)==12];

F=F+[(c*(I.^2)')./d' <= 1]; 
F=F+[sort(I)==desired];      
F=F+[0<=I<=600];   
F=F+[1<=Ibase<=600]; 

sol=optimize(F,f);
I=value(I)   
pos=value(pos)
Ibase=value(Ibase)
B=value(conBx*I')
B=value(conBy*I')

bin sun

unread,
Dec 5, 2017, 9:15:27 PM12/5/17
to YALMIP

The problem looks like below. I have 15 sources(black circle) and I measure at 12 positions(red points). So  all black circles will produce Bvalue on all red points. So each point have x direction and y direction Bvalue. I don't want to maximum the combine Bvalue at each point. (like point 1: sqrt(Bx1^2+By1^2). I hope to combine all points' Bvalue together. So I add all x direction values together ((sum(conBx*I')) and add all y direction values together(sum(conBy*I')) and get the objective function: f=-((sum(conBx*I'))^2+(sum(conBy*I'))^2);

My opinion is to move all 12 Bvectors to a same point and get the total combined Bvalue. I am not sure if the idea is correct.


Thank you very much for your time,

Bin 


Johan Löfberg

unread,
Dec 6, 2017, 2:14:58 AM12/6/17
to YALMIP
your problem is not that it is quadratic, your problem is that it is a nonconvex quadratic.

you have to use a global solver, such as bmibnb, baron

bin sun

unread,
Dec 6, 2017, 7:50:45 AM12/6/17
to YALMIP
Oh. Thank you very much. 
My objective is to get the maximum combined value of x and y direction. Problems like this do you have some better method? Is there any method to change the objective function to get a convex problem but get the same result I need?

Thanks,
Best,
Bin

Johan Löfberg

unread,
Dec 6, 2017, 10:06:43 AM12/6/17
to YALMIP
no, maximization of norm-like functions is nonconvex

Johan Löfberg

unread,
Dec 6, 2017, 10:15:45 AM12/6/17
to YALMIP
but if you change to norm(,1) or norm(,inf) yalmip will derive the milp representation of the nonconvex cost

bin sun

unread,
Dec 6, 2017, 10:18:36 AM12/6/17
to YALMIP
Thank you very much. Can you tell me change what to the norm? Or give me a title so I can go to check the link on Yalmip website.

Thank you very much for your help,
Best,
Bin

Johan Löfberg

unread,
Dec 6, 2017, 10:24:46 AM12/6/17
to YALMIP
Reply all
Reply to author
Forward
0 new messages