PDA

View Full Version : Nonlnear optimization in Qt



Tottish
26th March 2010, 10:17
Hello!
Introduction:
I'm new here and pretty much a newbie when it comes to both Qt and C++ in general. Qt Creator however seems very structured and a good way to build a GUI application with limited experience.

My problem:
Now to the reason I'm posting. I want to build an application that gets some raw data from an external source, make a nonlinear optimization calculation and plots out the result as a mark in a linediagram. My goal is that it should do this at least 10times/second.
The plotting diagram will look something like the one in this video.
YouTube-clip (http://www.youtube.com/watch?v=GFlXCoN56MM)

I have made the whole optimization-function in GNU Octave (Matlab-like environment) .m-script and was hoping that it would be easy to call from a C++ program. However it seems harder than I thought. it may only work under Linux and then maybe it won't be able to communicate with Qt?
I 'm not sure what I'm doing so if someone could take a glance at the link below and verify whether or not this kind of code is possible in the Qt-Creator IDE I would be very grateful!
OctaveWiki about calling m-files from C++ (http://wiki.octave.org/wiki.pl?CodaStandalone)

If it is not possible/very hard, is there any nice tools that might be suitable for nonlinear optimization that play nice with Qt?

Have a fantastic day!
/Tottish

wysota
26th March 2010, 19:30
What exactly do you mean by the octave program "communicating" with Qt?

Cruz
26th March 2010, 21:38
Whatever works for C++ works for Qt too. Qt IS C++. You write C++ code and you use the Qt libraries, that's all there is to it. A quick glance on that link you posted tells me that calling an octave function in an m-file from C++ means only including the octave headers and using the functions they provide. There is nothing Linux specific about this, so why wouldn't it work on Windows? Plus there is always cygwin for Linux sort of needs. Is it so hard to implement your optimization algorithm in C++ though? You might want to check out Qwt (http://qwt.sourceforge.net/) btw.

Tottish
31st March 2010, 13:36
Ooops! I thought I was getting an Email when this thread was updated, now I see I have to fix that in thread tools... sorry for the late answer.

"Whatever works for C++ works for Qt too."
Thank you for that clarification. I wasn't sure that it was that simple. Of course I haven't missed that Qt is a C++ environment but I wasn't sure about the compilers being used and if what works with one compiler necessarily does it with another. Again, thank you!

"so why wouldn't it work on Windows? Plus there is always cygwin for Linux sort of needs."
I don't know. All the info I found about it was in a Linux environment so it got me wondering. I fooled around a bit with cygwin too but never got it to work properly. Now I've got an Ubuntu machine running where I can follow the few examples I find step by step.

"Is it so hard to implement your optimization algorithm in C++ though?"
I'm not sure but since I already have the octave script I figured I might as well use it since it took a while to write. When I run it in octave it's fast enough so I hope it won't be much slower to call from C++. Should I expect any extra delay?

"You might want to check out Qwt btw."
Already did and rest assured that's the one for my ploting! =)


OK, so now I just need to get the example from the wiki I linked to to work and go from there, I suppose.
Can't get it to work at all but I guess I should post this in the noob forum since this most probably is a very basic problem. The reason I posted this here is that I figured the other noobs probably wasn't into nonlinear optimization. =)

Anyway, Thank you very much! Especially for "Whatever works for C++ works for Qt too.". Now this is possible.
Good afternoon!
/Tottish

pherthyl
31st March 2010, 18:26
Definitely this should work. Also good to leverage your Octave script. There shouldn't be much overhead calling it from C++. Many people think their algorithm would speed up if implemented in C++ (from Matlab/Octave), but often the reverse is true. Matlab at least has some incredibly well optimized routines, that will be very hard to beat. Post an update if you can't get it to work, but it does look fairly straightforward. You will need the include path set so it can find the octave header, and then likely the link path as well so it can find the octave library (docs should tell you where that is).

Tottish
31st March 2010, 18:42
Hey!
That's great to hear!
As I said I'm very much a noob so I started a thread in my proper element. =)
noob-forum-thread (http://www.qtcentre.org/threads/29449-Want-to-run-Octave-m-file?p=138304)
Check it out if you've got the time to help me out on cracking this nut!

Cheers!
/Tottish

Edit: Scroll down to last post for sourcecode