Optimal behavior composition for robotics