Specifying topological constraints for either trajectory generation for mobile robots, or for searching for a periodic walking gait in a specific region of the state-space would be extremely useful. However, a topological constraint, such as homotopy of a trajectory, has a gradient of zero almost everywhere, making standard gradient decent algorithms infeasible for searching for trajectories that respect the specified topological constraint. We formulate the problem as a constrained mixed-integer quadratic program, that is easily solved by a convex optimizer.