0

this is my first question here, I've searched it all over for a long time yet no solution. I'm using QUadprog++ to solve a quadratic problem. When I use it in a test alone, it was alright. But when I implement it into my project, which contains Eigen, the Eigen operations will have errors like "Matrix A has no member named ‘lu_inverse’". If I comment the header files of Quadprog++ (Array.hh and Quadprog++.hh) out, the errors just disappear. So I assume that it was a conflict error between the header files of Eigen and Quadprog++. Does anyone have some clue? Thanks in advance!

2 Answers2

1

You can also switch to one of QuadProgpp versions which can work with Eigen types directly: https://github.com/asherikov/QuadProgpp, https://www.cs.cmu.edu/~bstephe1/eiquadprog.hpp; or try an alternative implementation of the same algorithm (also Eigen based) https://github.com/asherikov/qpmad.

asherikov
  • 56
  • 1
  • Thank you, I'll check them up. Have you tried them yet? Which one do you think is the easiest to implement? – liu jingyu Nov 22 '18 at 09:19
  • API is pretty much the same. eiquadprog (and its variants) is a rather common choice in robotic applications. qpmad may be faster on some types of problems, but is much less common. – asherikov Nov 22 '18 at 17:48
  • OK, thanks a lot! My case is just on a quadraped robot. The problem was solved and I got reasonable results. But it seems that Quadprog++ took relative long time. Before calling it, my algorithm took only 0.3 ms to finish, while calling it the time jump up to 0.8 ms, which is very close to the upper bound for solving time --1 ms. Maybe I should try some other implementations like you suggest. – liu jingyu Nov 26 '18 at 02:41
0

if your using namespace quadprogpp; then dont. your different libraries have the same typenames and thats causing the errors you have. It may be a few more characters to type quadprogpp::someFunction(); but its worth it. This is also why you shouldn't ever put a using namespace in a header ever. Its because you pollute all files that include that header with the namespace symbols and name conflicts can ensue which is the same kind of error your having right now.

the Quadprog library is in it's own namespace.

#if !defined(_ARRAY_HH)
#define _ARRAY_HH

#include <set>
#include <stdexcept>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>

namespace quadprogpp {

enum MType { DIAG };

template <typename T>
class Vector

notice how just after the #includes there is a decleration of namespace quadprogpp{} and everything that is defined in its enclosing brackets will be defined in scope to quadprogpp, so to use any of this library you have to prefix eveything with the namespace name. this is no different than using things from the standard library. I'm quite sure you've written the standard c++ hello world

#include<iostream>
int main()
{
  std::cout << "hello world!" << std::endl;
  return 0;
}

cout and endl being part of namespace std have to be prefixed with std:: to access them. Many new programmers to c++ dislike this and one of the very first things they google is how to not have to type out namespaces.

#include<iostream>

using namespace std;
int main()
{
  cout << "hello world" << endl;
  return 0;
}

the next thing new programmers often do is learn to place their definitions in header files and their program logic in cpp files. Thats when they commit the next common mistake.

#ifndef MYHEADER
#define MYHEADER
#include<string>
#include<vector>
#include<iostream>

using namespace std; //Never do this in a header. 

doing that pollutes all of your code with everything in the standard library. That may seem like a trivial thing but when you start using another library or perhaps you create your own type that has the same name as things in the standard library that causes name collisions.

That's when the compiler simply cant reason about which Vector you want. But both Quadprog.hh and Array.hh in Quadprog++ are wrapped in namespace quadprogpp to specifically prevent name collision, which is the whole purpose of namespaces. So there is somewhere in your code, likely a header file, where you've made the statement of using namespace quadprogpp;, or some other namespace that defines an Array type, and the compiler can't deduce which type your referring to in your code.

Other than removing your using namespace statements you can also prefix a typename with its namespace qualifer to disambiguate which type your talking about. In your case I'm confident your Array should be declared as quadprogpp::Array arraynamme; rather than simply Array arrayname;

johnathan
  • 2,315
  • 13
  • 20
  • 1
    You can use a namespace alias to reduce the typing: `namespace qp=quadprogpp;` Then write `qp::someFunction()`, etc. – chtz Nov 20 '18 at 06:04
  • Thank you for your reply! But acctually there is no class or namespace of "quadprogpp" in the files, or you mean that I should create something like that then use it as you suggest? – liu jingyu Nov 20 '18 at 06:56
  • @lin jingyu i looked at the source of Quadprog++, at the very least some of it is in a namespace. – johnathan Nov 20 '18 at 06:58
  • @lin jingyu Your code, somewhere in it, is using that namespace, or you should be with all the things your using in that library – johnathan Nov 20 '18 at 07:01
  • 1
    ok, I‘ll look it up. I'm new to c++ too, so there is much to learn. – liu jingyu Nov 20 '18 at 07:21
  • @johnnathan I went through the source of Quadprog++ but cannot find that namespace. I feel that it is because of the header file "Array.hh", it has some class definition of Vector and Matrix with the same name defined in Eigen. This morning to fix some other errors I changed all the Vector into Vector1 and Matrix into Matrix1, in order to differ them out. After that I stuck here. – liu jingyu Nov 20 '18 at 07:41
  • 1
    @johnnathan Thank you so much! Now I got better understanding on it. That helps me a lot! – liu jingyu Nov 21 '18 at 03:16