roboptim / roboptim-core

RobOptim Core Layer: interface and basic mathematical tools
http://www.roboptim.net
GNU Lesser General Public License v3.0
65 stars 35 forks source link

Running a new program #104

Closed VishnuDevA7 closed 9 years ago

VishnuDevA7 commented 9 years ago

Hi, I am quite new to Linux as such. I am trying to use Roboptim ipopt plugin to optimize a highly nonlinear function with nonlinear constraints. Initially to begin with, I tried to edit the example.cc file where I replaced the "td-dummy" solver with "ipopt" plugin. I am facing issues such as when compiled with g++ from terminal I get a lot of statements saying undefined references to some or the other boost libraries. Can you please provide me an example with a main function which makes use of ipopt plugin for the same problem as in example and show me how to compile and run it? Thanks !

bchretien commented 9 years ago

First, you should not try to compile the examples manually. We use CMake to generate Makefiles (and you can see how to use it here). Since there are several dependencies and compilation flags that need to be passed, compiling it manually is not an option, especially if you're not familiar with RobOptim.

You may also want to check roboptim-tutorial. The master branch contains source files with methods to be implemented, and the answers branch shows how things can be done.

VishnuDevA7 commented 9 years ago

Thanks a lot!

VishnuDevA7 commented 9 years ago

Hi, I was trying to run the first tutorial example. I have fixed everything as required and compiled it using cmake in the build directory. But now when I run it as an executable file using ./001-function | gnuplot it says ¨Error while loading shared libraries : libroboptim-core.so.3: Cannot open shared library file : No such file or directory¨. But I do find the same file in /usr/local/roboptim-core/_build/src/ directory. So I also tried to make a copy of it in the directory where the .exe file of the 001-function is but no use. What should be done?

VishnuDevA7 commented 9 years ago

For the above problem, I exported the LD_LIBRARY_PATH as the location where the libroboptim-core.so.3 was located and I was able to get it running. But when I wanted to execute it again, I had to export the library path again. Is there a permanent fix to this? Thanks.

bchretien commented 9 years ago

If your libraries are installed in an unusual location, you should modify your .bashrc file located in ~/.bashrc (if you're using bash), then add the export in there, e.g.:

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/lib/roboptim-core"

VishnuDevA7 commented 9 years ago

Thanks! having done that I get this error for the third tutorial that libltdl failed to load plug-in roboptim-core-plugin-ipopt. I am able to view that it is installed through pkg-config --modversion. I have roboptim-core, roboptim-core-pluign-ipopt, roboptim-tutorial installed as seperate directories installed in /usr/local/. And I have libltdl package also installed. Copy pasting certain files like ipopt.hh from plugin directory into tutorial directory or core directory also doesn't help. Any suggestions??

bchretien commented 9 years ago

If you installed the plugin to /usr/local, this is solved by doing something like:

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib/roboptim-core"

The path may be slightly different. Use find /usr/local -iname "roboptim-core-plugin-ipopt.so" to find it.

VishnuDevA7 commented 9 years ago

I was able to complete all five tutorials. Thanks for the help. But I ran into some trouble as soon as I wanted to use roboptim to solve my problem. Instead of using cfsqp, I used IPOPT plugin and was able to do the tutorial. But now I wanted to something like this. I wanted a function func() to evaluate the result for impl_compute. I tried it in the following way, but was not able to do it, I got errors such as the function is undeclared for this scope and so on.

struct F : public DifferentiableFunction { F () : DifferentiableFunction (4, 1, "x₀ * x₃ * (x₀ + x₁ + x₂) + x₂") { }

void impl_compute (result_ref result, const_argument_ref x) const throw () { //result[0] = x[0] * x[3] * (x[0] + x[1] + x[2]) + x[2]; funct(result, x); }

void impl_gradient (gradient_ref grad, const_argument_ref x, size_type) const throw () { grad << x[0] * x[3] + x[3] * (x[0] + x[1] + x[2]), x[0] * x[3], x[0] * x[3] + 1, x[0] * (x[0] + x[1] + x[2]); }

void funct(result_ref result, const_argument_ref x) { //result_ref result; result[0] = x[0] * x[3] * (x[0] + x[1] + x[2]) + x[2]; //return result; }

}

I am not able to understand what goes wrong here. I also tried changing void to result_ref and made my new function return the result_ref result but no use. I also tried to understand this from the documentation. Please let me know what is going wrong.

bchretien commented 9 years ago

First you should retry without the exception specifiers (throw ()). These were removed a while ago from the API, but the answers branch of the tutorials was not completely updated after (it's fixed now).

VishnuDevA7 commented 9 years ago

Ya I did remove the throw specifiers. It still returned an error. Also if I declared my function funct() as a member of the struct F and give the function definition outside the structure it throws me the error (expected constructor, destructor or type conversion before '(' token). Also I tried this : Since the function funct is a member of structure F, I declared it in inside the structure as

void funct(result_ref result, const_argument_ref x) and defined it outside the structure after the main() as F.funct(result_ref result, const_argument_ref x) which now says expected unqualified id before (.) token.

Running it this way, void F::funct(result_ref result, const_argument_ref x) says prototype for void F::funct() does not match any in class F or discards qualifiers.

VishnuDevA7 commented 9 years ago

I was able to run it without errors once I declared it within the structure as void funct() const; and defined it outside the function as void F::funct() const { }

VishnuDevA7 commented 9 years ago

Is there a function provided by Roboptim that can calculate for the gradient through finite differences rather than we providing the gradient explicitly? My constraint functions are highly complex because they are the forward kinematics of a manipulator. And so for numerical differentiation, are any finite difference functions available in the library?

bchretien commented 9 years ago

You can use the FiniteDifferenceGradient decorator.

VishnuDevA7 commented 9 years ago

http://www.roboptim.net/roboptim-core/doxygen/v2.0/a00002.html The example in this link shows usage of computing finite difference gradients. Has the API syntax been changed or can this be still used?

bchretien commented 9 years ago

This is a link to the 2.0 API. Things may have changed a bit so try to use the latest doc. Still, for this decorator specifically, the usage is the same. If you're dealing with dense matrices:

GenericFiniteDifferenceGradient<EigenMatrixDense> fdfunction (function);

where function inherits from Function. Then just use fdfunction.

bchretien commented 9 years ago

Since this does not seem to be an actual issue, I'm now closing this.