drake icon indicating copy to clipboard operation
drake copied to clipboard

Option to add slack variables on GCS edges

Open bernhardpg opened this issue 1 year ago • 3 comments

Is your feature request related to a problem? Please describe. I would like a more flexible way to formulate costs and constraints on the edges in GCS using slack variables. Right now, the slack variables need to be defined as part of the convex set by increasing its ambient dimension.

For instance, say one would like to implement the cost:

min max(1/x_1, 1/x_2) st. x_1, x_2 >= 0

over a two-dimensional convex set (x_1 and x_2).

This one can do by adding the slack variable s and reformulating as follows:

min s st. s >= 1 / x_1, s >= 1 / x_2, x_1, x_2, s >= 0

which is readily encoded using RotatedLorentzConeConstraints:

min s st. s * x_1 >= 1, s * x_2 >= 1, x_1, x_2, s >= 0

The way to do this right now in GCS is the following:

  1. Have some convex set in mind with ambient dimension 2
  2. Extend the dimension of the set to 2 + 1 (to accommodate for the slack variable)
  3. Add the RSOC constraint on the edges/vertices, using the convex set variables OR add the RSOC constraint as part of the ConvexSet definition (which is not generally supported).

This approach has some problems:

  • Imagine the scenario where one would like to implement i.e. a cost that is SOC representable on some of the edges incident to a vertex, but not all. This is not possible with the current workflow, as the slack variable is embedded in the convex set itself. The closest one can get right now is to omit the constraint on the edges where one don't want the cost, but then there is a unused slack variable in the set.
  • The slack variables may not naturally be bounded and hence the ConvexSet might be unbounded and not compact.

Describe the solution you'd like I think it would be helpful to have a function on the edges which adds and returns a slack variable directly to the underlying internal MathematicalProgram in GCS, called something like Edge.CreateSlackVariable(...).

The Edge.AddConstraint(binding) and Edge.AddCost(binding) functions would then have to figure out whether the variables in the binding are "convex set" variables or slack variables, and accordingly retrieve the spatial flow variables (in the case of "convex set" variables) or just use the variable itself (in the case of slack variables).

I believe this should also be easy to extend to have a similar function for vertices.

bernhardpg avatar Feb 21 '24 00:02 bernhardpg

@TobiaMarcucci @RussTedrake WDYT?

bernhardpg avatar Feb 21 '24 00:02 bernhardpg

I think this feature would also allow the subspace mechanics in GcsTrajectoryOptimization to work with arbitrary convex sets, since adding point-in-set constraints for some convex sets requires adding additional variables.

cohnt avatar Feb 22 '24 00:02 cohnt

See Remark 5.1 in Tobia's thesis.

RussTedrake avatar Apr 22 '24 11:04 RussTedrake

I believe this is resolved by #21403. @bernhardpg -- please re-open if I'm wrong.

RussTedrake avatar Aug 19 '24 12:08 RussTedrake