snopt / snopt-matlab

Matlab interface for sparse nonlinear optimizer SNOPT
MIT License
55 stars 23 forks source link

snopt-matlab interface not working with GPOPS #1

Closed Reederoo closed 6 years ago

Reederoo commented 8 years ago

I am testing GPOPS (as available on Matlab Central File Exchange http://www.mathworks.com/matlabcentral/fileexchange/21729-gpops) Which requires SNOPT.

I am using the trial version of snoptmex along with the snopt-matlab files from this project.

When I run GPOPS, I get the following errror: gpops (line 364) "Error using snsolve, Too many output arguments."

The line of code where the error occurs is: [x,F,xmul,Fmul,info,xstate,Fstate,ns,ninf,sinf,mincw,miniw,minrw] = snsolve(init,xlow,xupp,xmul,xstate,Flow,Fupp,Fmul,Fstate,ObjAdd,ObjRow,AA,iAfun,jAvar,iGfun,jGvar,userfun);

This does not match the current snsolve interface, but the GPOPS files are from 2008. I wonder if there is an older version of snsolve that is compatible with this calling syntax?

Thanks for any help on this.

gnowzil commented 8 years ago

The best solution would be to update GPOPS.... This github rep is less than a year old so unfortunately, it won't have the files you need. I'll try to look in our own files to see if I can find a compatible version.

novatig commented 7 years ago

Could you share past manuals or any description of the inputs to snsolve and snoptcmex used by GPOPS?

[x,F,xmul,Fmul,info,xstate,Fstate,ns,ninf,sinf,mincw,miniw,minrw] = ...
    snsolve(init,xlow,xupp,xmul,xstate,...
    Flow,Fupp,Fmul,Fstate,ObjAdd,ObjRow,...
    AA,iAfun,jAvar,iGfun,jGvar,userfun);

[uFout,FFout,umulFout,FmulFout,informF] = snoptcmex(...
            solveopt,uguess,ulow,uupp,umul,ustate,...
            Flow,Fupp,Fmul,Fstate,ObjAdd,ObjRow,...
            A,iAfun,jAvar,iGfun,jGvar,usrfun);

At least it would be possible to reverse engineer an update to the function calls.

gnowzil commented 7 years ago

snoptcmex was developed by other people before I started working with SNOPT. I don't have any info on it unfortunately. It might be possible to modify GPOPS to use the current snoptmex-based interface.

mengqlTHU commented 2 years ago

After reading the source code of snopt-matlab, I think I have found the solution to make GPOPS work with the newest SNOPT 7. First, in gpops.m, replace

[x,F,xmul,Fmul,info,xstate,Fstate,ns,ninf,sinf,mincw,miniw,minrw] = 
snopt(init,xlow,xupp,xmul,xstate,Flow,Fupp,Fmul,Fstate,ObjAdd,ObjRow,AA,iAfun,jAvar,iGfun,jGvar,userfun);

with

A_struct = struct('row',iAfun,'col',jAvar,'val',AA);
G_struct = struct('row',iGfun,'col',jGvar);
[x,F,info,xmul,Fmul] = snopt(init, xlow, xupp, xmul, xstate,...
                          Flow, Fupp, Fmul, Fstate,...
                          userfun, ObjAdd, ObjRow,A_struct,G_struct);

Second, in gposNlp2oc.m, replace

[u0out,F0out,xmul0out,Fmul0out,inform0] = 
snoptcmex(solveopt,uguess,ulow,uupp,umul,ustate,Flow,Fupp,Fmul,Fstate,ObjAdd,ObjRow,A,iAfun,jAvar,iGfun,jGvar,usrfun);
....

[uFout,FFout,umulFout,FmulFout,informF] = 
snoptcmex(solveopt,uguess,ulow,uupp,umul,ustate,Flow,Fupp,Fmul,Fstate,ObjAdd,ObjRow,A,iAfun,jAvar,iGfun,jGvar,usrfun);

with

A_struct = struct('row',iAfun,'col',jAvar,'val',A);
G_struct = struct('row',iGfun,'col',jGvar); 
[u0out,F0out,inform0,xmul0out,Fmul0out,xstate,Fstate,output] = 
snopt (uguess, ulow, uupp, umul, ustate,...
                                         Flow, Fupp, Fmul, Fstate, usrfun,...
                                         ObjAdd, ObjRow,...
                                         A_struct, G_struct);
...

A_struct = struct('row',iAfun,'col',jAvar,'val',A);
G_struct = struct('row',iGfun,'col',jGvar); 
[uFout,FFout,informF,xmulFout,FmulFout,xstate,Fstate,output] = snopt (uguess, ulow, uupp, umul, ustate,...
                                         Flow, Fupp, Fmul, Fstate, usrfun,...
                                         ObjAdd, ObjRow,...
                                         A_struct, G_struct);