3

We're currently using Matlab's fmincon function to do non-linear optimization for a project I'm working on. We need to port that part of the project to C++ in order to integrate it with other parts of the project. Is there a good way to compile the fmincon function into a library that we can use in C++? Or, is there already a library available somewhere that implements fmincon?

If neither of the above are an option, what optimization libraries are available that would be fairly easy to switch to from fmincon?

Background info:

We're trying to optimize a waypoint flight path of a UAV to follow a given waypoint camera path along the ground as closely as possible. The waypoints between the two paths correspond temporally, so the camera gimbal will be pointed at the i-th camera waypoint when the UAV arrives at the i-th flight path waypoint. The flight path segments will all be the same length since the UAV flies at a constant speed. The turn radius is also constrained by an upper bound. There are no constraints on the camera path, so its segments may be longer or shorter than the flight path segments and it may have sharp turns. The cost function is the sum-squared distance between corresponding flight waypoints and camera waypoints (ignoring altitude differences).

6
  • 1
    In case you dont get any good answers you might wanna google "fmincon in c++" there are an insane amounts of hits!
    – stefan
    Commented Mar 25, 2011 at 23:57
  • 1
    If anyone's wondering, we settled on using the NLopt library from MIT.
    – Brandon
    Commented Jun 9, 2011 at 1:34
  • @Brandon, which of the optimizers in NLopt did you try / which was best for your problem ?
    – denis
    Commented Jul 27, 2012 at 13:40
  • @Denis It looks like I was trying COBYLA, but we never got it all working in C++. The guy who had worked on the Matlab code didn't have much experience with C++, and parts of the ported code were crashing. I was trying to help him port the optimization part, and I think we had some problems with NLopt crashing too. I'm not sure if it was because of bad inputs from other parts of the code, or me somehow using it incorrectly. We ended up shuffling data between my C++ and his Matlab code using files. It would have been nicer to have it integrated, but that worked well enough for our research.
    – Brandon
    Commented Jul 27, 2012 at 21:12
  • Our funding and the project itself were ending too soon for us to have time to debug the ported C++ code, so we just focused on preparing our demo using the things that we already had working.
    – Brandon
    Commented Jul 27, 2012 at 21:17

1 Answer 1

6

Most of the time, libraries out there won't try to be a black box magic one-size-fits-all optimization tool like fmincon is- instead they'll require you to provide more detail and make more choices on your own, which is simpler for them and should result in your software being faster. You can certainly use the MATLAB Engine or MATLAB Compiler to call fmincon from your program, but most likely your software will run a good deal faster (and you can avoid purchasing the MATLAB Compiler) if you can use a little more knowledge about the structure your optimization problem has and call an appropriate algorithm.

Your background info doesn't describe what you're doing - esp. what your feasible set is- clearly enough for me to be able to tell you what to use, so all I can do is point you in the direction of relevant resources.

Wikipedia's page on optimization links to lists of optimization software- most importantly, it describes more specific kinds of optimization problems (for instance, can you formulate your problem as quadratic programming with linear constraints?) and software appropriate for each situation.

Boyd's book on convex optimization and the linked course materials & videos are really good resources.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.