drake

Is specifying the same decision variable multiple times in AddConstraint problematic?


Given the following two ways of creating the same constraint

Case 1

def constraint(x):
    return x[0] + x[1] # or potentially something much more complicated
...
x = prog.NewContinuousVariables(2,)
prog.AddConstraint(constraint, ..., vars=[x[0], x[0]]) # same decision variable specified twice

Case 2

def constraint(x):
    return 2*x[0]
x = prog.NewContinuousVariables(2,)
prog.AddConstraint(constraint, ..., vars=[x[0]])
# constraint function written in a way that decision variable only specified once

My question is, are these two cases equivalent, both performance-wise and numerically?

The reason I ask is, I'm iteratively building up a constraint involving a long chain of vars in which there may be duplicates of the same decision variable. I'm wondering if I should spend the effort to refactor the constraint such that each decision variable only appears once, or is drake smart enough to handle that for me.


Solution

  • Drake should handle duplicated variables for you. If you encounter unexpected behaviors with duplicated variables, please file a GitHub issue. Thanks