How to get the minimization value of the objective function, not negative maximum value.

46 views
Skip to first unread message

bin sun

unread,
Nov 28, 2017, 5:18:14 PM11/28/17
to YALMIP
Dear Johan,

I have five available positions and I choose two of them. distB and I are dependent on the positions. I want to get the maximum value and minimum value of B=distB*I'. I can get the maximum value( using f=-sum(distB*I');) but when I try to get the minimum value I get the negative max( using f=sum(distB*I');). Could you tell me how to get the minimum value? (not negative maximum value)


The code is attached:
d=[1*5 matrix]
c=[5*5 maxtrix]
dshort=0.15;
distB=2e-7./[-dshort,dist1-dshort,2*dist1-dshort,3*dist1-dshort,4*dist1-dshort;-(dist1+dshort),-dshort,dshort,dshort+dist1,dshort+2*dist1;
        -(2*dist1+dshort),-(dist1+dshort),-dshort,dshort,dshort+dist1; -(3*dist1+dshort),-(2*dist1+dshort),-(dist1+dshort),-(0*dist1+dshort),dshort];

I=intvar(1,5); 
pos=binvar(1,5); 
intvar Ibase;   
f=-sum(distB*I');
desired = [ zeros(1,3) Ibase  Ibase];
F=[implies(pos,I== 0)]; 
F=F+[sum(pos)==3]; 

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(distB*I')

Johan Löfberg

unread,
Nov 29, 2017, 1:31:04 AM11/29/17
to YALMIP
Not clear what you mean with "get"

If you want to minimize f, you use the objective objective = f, and the minimum value will be value(f)

If you want to maximize f, you use the objective objective = -f, and the maximum value will be value(f)

bin sun

unread,
Nov 29, 2017, 9:13:38 AM11/29/17
to YALMIP
Yeah. I use f=-sum(distB*I'); to get the maximum value is 
B =1.0e-03 *
    0.2459
    0.3826
    0.9564
   -0.0000
But when I use f=sum(distB*I'); to get the minimum value I get 
B =

   1.0e-03 *
   -0.0000
   -0.9564
   -0.3826
   -0.2459
This is not what I want. I hope to get sumB equal to zero or a very small positive value.

Thank you very much,
Best,
Bin

Johan Löfberg

unread,
Nov 29, 2017, 9:56:34 AM11/29/17
to YALMIP
Impossible to say anything out of context. For anyone just looking at those numbers, it's pretty close to zero...

Maximization leading to stuff*1e-3 and minimization leading to -stuff*1e-3 tells me the problem is badly scaled.

bin sun

unread,
Nov 29, 2017, 10:01:03 AM11/29/17
to YALMIP
So if I want to restrict the objective function is positive. How can I do that? 

Another similiar problem I have if use f=-sum(I); to get the maximum, I get: 456. But if use f=sum(I); to get minimum, I get -456. This is not what I need. I hope to get some very small positive value.

Johan Löfberg

unread,
Nov 29, 2017, 10:18:07 AM11/29/17
to YALMIP
If you want something to be positive, you just add the constraint something>=0, like always.

bin sun

unread,
Nov 29, 2017, 11:41:53 AM11/29/17
to YALMIP
Maximum value can be calculate correctly using the code attached. I hope to get the minimum value and I get the code like this and I add the code F=F+[distB*I'], then B=[0;0;0;0]. Can you tell me how to change this code? I choose three positions from 5 available positions. Unchoose part have I=0, choose part follow the restrict:F=F+[(c*(I.^2)')./d' <= 1]; And My objective function is f=sum(distB*I');

d=[401933.568419812,401933.568419812,401933.568419812,401933.568419812,401933.568419812];
c=[1,0.385740902327350,0.252086400923626,0.180051756213799,0.134338625773115;0.385740902327350,1,0.385740902327350,0.252086400923626,0.180051756213799;0.252086400923626,0.385740902327350,1,0.385740902327350,0.252086400923626;0.180051756213799,0.252086400923626,0.385740902327350,1,0.385740902327350;0.134338625773115,0.180051756213799,0.252086400923626,0.385740902327350,1];
I=intvar(1,5); 
pos=binvar(1,5); 
intvar Ibase; 
dshort=0.15;
distB=2e-7./[-dshort,dist1-dshort,2*dist1-dshort,3*dist1-dshort,4*dist1-dshort;-(dist1+dshort),-dshort,dshort,dshort+dist1,dshort+2*dist1;
        -(2*dist1+dshort),-(dist1+dshort),-dshort,dshort,dshort+dist1; -(3*dist1+dshort),-(2*dist1+dshort),-(dist1+dshort),-(0*dist1+dshort),dshort];
f=sum(distB*I');
desired = [ zeros(1,2) Ibase  Ibase Ibase];
F=[implies(pos,I== 0)]; 
F=F+[sum(pos)==2]; 

Johan Löfberg

unread,
Nov 29, 2017, 11:49:35 AM11/29/17
to YALMIP
Undefined function or variable 'dist1'.
 

bin sun

unread,
Nov 29, 2017, 11:50:37 AM11/29/17
to YALMIP
L=1; %buried depth
dist1=0.3;  %distance between each other
dist2=0.5;   %distance of two row
n=15;   %how many cables

Johan Löfberg

unread,
Nov 29, 2017, 12:00:30 PM11/29/17
to YALMIP
To begin with, with the unnecessary multiplcation with 2e-7, your objective coefficients is in the order of 1e-5. Completely unnecessary introduction of bad data.

What is the problem then? When I minimize I get


>> value(I)

ans =

  476.0000  476.0000  476.0000         0         0

and when I maximize I get

>> value(I)

ans =

         0         0  476.0000  476.0000  476.0000


with objectives 7011 and -7011 respectively (after removing the unnecessary scaling with 2e-7)...

bin sun

unread,
Nov 29, 2017, 12:04:41 PM11/29/17
to YALMIP
The value I calculated have direction. So -7011 and 7011 just different direction but same result. What I want is to get the result have big I but zero sum(B)(f=sum(distB*I');). For example, if I=476, change the positions can get sumB=0 

Johan Löfberg

unread,
Nov 29, 2017, 12:14:23 PM11/29/17
to YALMIP
You get what you ask for. Now you asked for a small sum, hence you get a small sum. If you want to a small absolute value, you have to minimize that objective

bin sun

unread,
Nov 29, 2017, 12:25:15 PM11/29/17
to YALMIP
So I should write objective function like: f=sum(abs(distB*I'));?

Johan Löfberg

unread,
Nov 29, 2017, 12:28:53 PM11/29/17
to YALMIP
We don't now what you actually want. Either that or perhaps abs(sum((distB*I'))), or sum((distB*I').^2), ....We don't know how you define "small"
Reply all
Reply to author
Forward
0 new messages