  The stability and convergence rate of Olver's collocation method for the
numerical solution of Riemann-Hilbert problems (RHPs) is known to depend very
sensitively on the particular choice of contours used as data of the RHP. By
manually performing contour deformations that proved to be successful in the
asymptotic analysis of RHPs, such as the method of nonlinear steepest descent,
the numerical method can basically be preconditioned, making it asymptotically
stable. In this paper, however, we will show that most of these preconditioning
deformations, including lensing, can be addressed in an automatic, completely
algorithmic fashion that would turn the numerical method into a black-box
solver. To this end, the preconditioning of RHPs is recast as a discrete,
graph-based optimization problem: the deformed contours are obtained as a
system of shortest paths within a planar graph weighted by the relative
strength of the jump matrices. The algorithm is illustrated for the RHP
representing the Painlev\'e II transcendents.
