Swap was wrong when nodes swapping were connected.

* Fixed by adding check as to whether they are connected, if so reconnect after swap.
* Disallowed nodes to point to themselves in the addEdge function.