define an objective function by .m file

46 views
Skip to first unread message

mengyuli

unread,
Nov 5, 2017, 7:52:08 AM11/5/17
to YALMIP
Hi,

I defined an objective function by a .m file as: 

Objective = @(vx)loadcalkxdays3opt(x,vx,tripnumwd,tripnumwe,energycon,capacity,chargingrate,chargingeff,random,a,atemp);

When I tried to run the optimisation problem, an error occurs as:

Error using solvesdp (line 91)
Second argument (the objective function h) should be an sdpvar or logdet object (or empty).

My initial codes are:
x = sdpvar(10,1);
Constraints=[ x == 0:30:90];
Objective = @(vx)loadcalkxdays3opt(x,vx,tripnumwd,tripnumwe,energycon,capacity,chargingrate,chargingeff,random,a,atemp);
ops = sdpsettings( 'solver','Cplex');
sol = optimize(Constraints,Objective,ops);

My question is if this error is because my objective function is in m file, which is not compatible in Yalmip language?

Thank you very much for your help.

Cheers,
MY

Johan Löfberg

unread,
Nov 5, 2017, 9:46:05 AM11/5/17
to YALMIP
Nope, black-box optimization is not the intended use for YALMIP.

mengyuli

unread,
Nov 5, 2017, 9:32:24 PM11/5/17
to YALMIP
Thank you very much for your reply. Then if I still want to use the YALMIP, how can I change my code. 

My objective function is min (diff), where diff is defined from .m file as:

function diff=loadtotal(x)
[power1]=load(x,1); %load is the subfunction
[power2]=load(x,2);
[power3]=load(x,3);
diff=max(power1+power2+power3)-1000;

Johan Löfberg

unread,
Nov 6, 2017, 1:23:53 AM11/6/17
to YALMIP
if load does something complicated (i.e. general black-box function), you cannot use it

mengyuli

unread,
Nov 6, 2017, 1:31:24 AM11/6/17
to YALMIP
Thank you very much for your reply. Yes, I see. Then if constraints can be defined by the .m file in Yalmip?

Johan Löfberg

unread,
Nov 6, 2017, 1:39:51 AM11/6/17
to YALMIP
What constraint?

mengyuli

unread,
Nov 6, 2017, 2:05:43 AM11/6/17
to YALMIP
My objective function is min (diff), where diff is defined from .m file as:
function diff=loadtotal(x)
[power1]=load(x,1); %load is the subfunction
[power2]=load(x,2);
[power3]=load(x,3);
diff=max(power1+power2+power3)-1000;

If I reshape the problem as:

Objective = max(power1+power2+power3)-1000;
where Constraints=[power1==load(x,1)];
Constraints=[power2==load(x,2)];
Constraints=[power3==load(x,3)];

Johan Löfberg

unread,
Nov 6, 2017, 2:24:18 AM11/6/17
to YALMIP
As I said, if load is a complicated black-box funtion (involving if-else etc) it will not work

You probably mean ismember(x,0:30:90), otherwise you are saying that the vector x is fixed
Reply all
Reply to author
Forward
0 new messages