Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConstraintFunction simplification #20

Open
aescande opened this issue Jan 12, 2017 · 3 comments
Open

ConstraintFunction simplification #20

aescande opened this issue Jan 12, 2017 · 3 comments

Comments

@aescande
Copy link
Contributor

Is there some cases where ConstraintFunction here is templated by multiple classes. There are no such case in Tasks and I could find one in client code either.

Getting rid of the variadic template gives a much simpler code:

template<typename Fun>
class ConstraintFunction : public Constraint, public Fun
{
public:
	virtual ~ConstraintFunction() {}

	void addToSolver(QPSolver& sol)
	{
		sol.addConstraint(this);
  		static_cast<Fun*>(this)->addToSolver(sol);
	}

	void addToSolver(const std::vector<rbd::MultiBody>& mbs, QPSolver& sol)
	{
		sol.addConstraint(mbs, this);
	  	static_cast<Fun*>(this)->addToSolver(sol);
	}

	void removeFromSolver(QPSolver& sol)
	{
		sol.removeConstraint(this);
   		static_cast<Fun*>(this)->removeFromSolver(sol);
	}
};

The impact on client code is minimal to non-existent. At worse, it is a matter of removing a few ...

@haudren
Copy link
Collaborator

haudren commented Jan 13, 2017

Hum good question... In the distant past, that is to say 783e8ba, MotionConstr used to be a ConstraintFunction<Inequality, Bound>, which made sense as we did not have GenInequality. I guess that this feature is not really needed anymore, but the question is: do we see some possible uses for it in the future ?

@jorisv
Copy link
Collaborator

jorisv commented Jan 13, 2017 via email

@aescande
Copy link
Contributor Author

It is only a matter of simplification and readability, nothing more. It can also help a bit to reduce compilation times.

I'm not sold on the fact that we will need to address weird corner cases in Tasks. In my understanding, Tasks is dealing with low-level constraints and having composite constraints would be dealt with at the mc_rtc/mc_ros level.
However, if we want to think it further, let's consider all the type of mixes (FUN1, FUN2) we could have:

  • FUN1 == FUN2 makes no sense/ is trivially reduced to FUN1
  • Ineqality and GenInequality can be treated as GenInequality with no or barely no overhead (depending on the solver: no overhead with LSSOL).
  • Equality and one of the two flavors of inequality: this should be treated as a single GenInequality, and the solver should handle the case where lb_i == ub_i (LSSOL does that automatically, and for QLD the handling can be done at the same place double-sided inequalities are transformed to single sided).
  • Bound and another type of constraint: it could once again be dealt with as GenInequality, but here it is sub-optimal because we lose the sparse structure of the bound constraints, which can usually be handled efficiently by a QP solver. However, the only case where I can see this mix happen is through the use of slack variables. I don't think the actual framework is ready for this case, because it involves adding variables and so asks for a more involved variable management. Also the use of slack variables is a choice of resolution scheme, not formulation, and as such should not be considered at the task level, but in the solver (i.e. implementing a different version of QPSolver).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants