Search code examples
drake

MathematicalProgram: Group lumped parameters by defining new variables


I have a version of the following problem: I have a MathematicalProgram with decision variables a, b, c that only ever appear in lumped form, such as ab, bc. I now want to construct a new set of decision variables, defining m1 := ab and m2 := bc and solve the MathematicalProgram with respect to these new variables.

The idea is that the optimization should now be linear in the new set of parameters, and I really only care about their lumped values. However, I don't know how lumping occurs a priory and hence can only define the non-lumped parameters. In particular, I obtain the lumped parameters from DecomposeLumpedParameters.

How would I go about achieving this? Is there a way of doing this automatically with the MathematicalProgram API, or can I achieve this somehow by substituting the old parameters with the new ones in my expressions?


Solution

  • I don't believe there is a super clean answer to the most general version of this problem.

    As you've written it, you have costs and/or constraints with an Eval method of the form

    f(a,b,c) = ab + bc + ...
    

    and you want to automatically convert this to

    g(x=ab, y=bc) = x + y + ...
    

    For costs/constraints that support Eval<Expression>, one could actually use DecomposeLumpedParameters again on the cost/constraint evaluator to extract those terms. But in general it is hard to go in this direction. (It's much easier to go from g(x,y) => f(a,b,c), but because you can do symbolic substitution of x=ab, y=bc, or nested function evaluation for cost/constraints that only support Eval<AutoDiffXd>.)

    But, having talked to you about this briefly face2face, I think for your specific problem there is almost certainly a more narrow solution to your particular instance, which should work on the expressions before you get to the generality of MathematicalProgram.