Reputation: 189
How do I get the number of binary variables to my mathematical program?
How do I get a reference to a vector of all the aggregate binary variables?
Also, how do I get the Gurobi std output (this could also tell the number of binary variables)? Example here: How to get how many binary variables used by Gurobi?
Many thanks.
Upvotes: 0
Views: 33
Reputation: 5533
You'll need to loop through the variables and check which are binary:
from pydrake.solvers import MathematicalProgram
from pydrake.symbolic import Variable
prog = MathematicalProgram()
x = prog.NewContinuousVariables(2)
b = prog.NewBinaryVariables(3)
binaries = [
x for x in prog.decision_variables() if x.get_type() == Variable.Type.BINARY
]
print(len(binaries))
Upvotes: 3