To reroute wires between connected objects, the Lee Algorithm is used. Here some links:
http://foghorn.cadlab.lafayette.edu/MazeRouter.html
http://cc.ee.ntu.edu.tw/~cchen/course/simulation/CAD/unit5D.pdf
http://www.ece.northwestern.edu/~haizhou/357/lec6.pdf