Using Lookup Tables in Optimization Formulation

523 views
Skip to first unread message

Shima Nazari

unread,
Oct 18, 2017, 5:16:19 PM10/18/17
to YALMIP


Hi,
Is it possible to use lookup tables in optimization problem formulation in YALMIP?
I want to determine an electric motor efficiency based on its speed and torque. The motor torque is an optimization variable and I have the efficiency in a 2D lookup table. 
I tried to use the interp2 function ( Efficiency = interp2(xi,yi,zi, xv, yv))  to determine the efficiency, but it gives me the following error:

Error using sdpvar/model (line 66)
Failed when trying to create a model for the "interp2_internal" operator

Error in expandrecursive (line 19)
    [properties,F_graph,arguments,fcn] = model(variable,method,options,allExtStruct(ext_index),w);

Error in expandmodel>expand (line 416)
            [F_expand,failure,cause] =
            expandrecursive(recover(variables(i)),F_expand,extendedvariables,monomtable,variabletype,where,level+1,options,method,[],'convex',allExtStruct,w);
            
Error in expandmodel (line 282)
                [F_expand,failure,cause] =
                expand(index_in_extended,variables,-sdpvar(Fconstraint),F_expand,extendedvariables,monomtable,variabletype,['constraint
                #' num2str(constraint)],0,options,method,[],allExtStructs,w);

Error in compileinterfacedata (line 116)
    [F,failure,cause,operators] = expandmodel(F,h,options);

Error in solvesdp (line 231)
[interfacedata,recoverdata,solver,diagnostic,F,Fremoved,ForiginalQuadratics] =
compileinterfacedata(F,[],logdetStruct,h,options,0,solving_parametric);

Error in optimize (line 31)
[varargout{1:nargout}] = solvesdp(varargin{:});

Johan Löfberg

unread,
Oct 19, 2017, 2:14:54 AM10/19/17
to YALMIP
I was going to say that interp2 isn't overloaded, but then I checked and realized I had it overloaded...

You will have to supply more code for debugging, because it works in a simple example

[xi,yi] = meshgrid(-1:0.1:1);
zi = (xi-.5).^2 + (yi-.2).^2;
sdpvar x y
z = interp2(xi,yi,zi,x,y);
optimize([],z)
value([x y]);





Shima Nazari

unread,
Oct 19, 2017, 7:06:01 PM10/19/17
to YALMIP
Thank you for the answer,
The simple case works for me too, I guess I have to dig more to find the problem,
two more questions: 
1- do you think that using a lookup table instead of regressing the data would slow the optimization?
2- does the interp2 work with all solvers? I have a hybrid system, I need to use mixed integer solvers.
Shima

Johan Löfberg

unread,
Oct 20, 2017, 2:25:46 AM10/20/17
to YALMIP
* Using a look-up table and a nonlinear solver will typically be much much slower compared to using a linear or quadratic function in a LP/QP model. When used in a nonlinear solver using callbacks etc it will slow down significantly as the function evaluation is slow, and there are no derivatives computed (unless the map is used tas a replacement o approximate a function which can be implemented in YALMIP but is really really complicated to compute). In a LP/QP setting (see below) it will be much slower as it typically will require a sos2 based approach, which means it is a combinatorial model, i.e. it turns into MILP or MIQP

* No, interp2 as it is now only works with nonlinear solvers, as it is based on function evaluation and callbacks.

* Try to simplify your model while the error still remains and post the model.I would like to see why the error is triggered. I guess it is somehow related to the use a mixed-integer solver and the lack of support for that combination in the current release.

* However, good news for you though. After answering this question yesterday, I took a look at the function, and realized I easily could add a sos2 based representation (i.e. MILP/MIQP), as I've done for interp1. I added it, and it is now available in the develop branch. The interp2 description on the wiki already explains how to use interp2 in a mixed-integer setting. I will see today if I can add support for automatic convexity/concavity detection and thus add LP models when applicable as in interp1 although that's perhaps not relevant for you
Reply all
Reply to author
Forward
0 new messages