Skip to content

Instantly share code, notes, and snippets.

@nbro
nbro / double_bridge.md
Last active March 12, 2017 22:41
In-place double-bridge or 4-opt move

I've implemented a double-bridge (or 4-opt) move in place, i.e. without any additional containers than the original. I'm sharing it with you first because I would like to know if it's correct or if I can improve it and second because I thought it could be helpful to someone else (since I have not found anything on the web).

/*
 * DOUBLE-BRIDGE-COMPUTE-GAIN
 *
 * Computes and returns the gain of a random double-bridge move.
 * The indices of the vertices used are also returnd as 2nd, 3rd and 4th parametrs of the array returned.
 * */
std::array<int, 4> double_bridge_in_place_compute_gain(const MatrixGraph &m, const VectorTour &t) {