Up: 3 The Great Deluge
Previous: 3.1 Getting started
Next: 3.3 Decreasing the tyde
Now we are looking for a new path. To get a new path we need two edges that have no common knots.
If there are no such edges, it means that the current path has only three or less knots, the only chance to find a better solution is to reverse the path if this is possible.
In most cases the problems have more than three knots, so that we can find these two edges by choosing them randomly from our path using the condition that they have no common knots.
The path will be splitted into two pieces by removing these edges. First we try to build a new path connecting the startknot of the first chosen edge with the startknot of the second one. Then the path that starts with the endknot of our newly added edge must be reverseable and the end of this path must have a possible connection to its startknot (see figure below).
Figure:
First try to change path [swapEdge2.png]
|
|
If this fails we try it the other way round, swapping the edges.
Figure:
Second try to change path [swapEdge2.png]
|
|
If this fails, too, the last chance is to reverse our path (see figure below). If this also fails, these two edges lead to no solution and after decreasing the tyde there will be the possibility that in the next turn two other edges will be taken.
Figure:
Try to reverse the path [reversePath.png]
|
|
But if one of these procedures above succeed and generate a new path this path must be checked, if it is a new solution. If the length of the path is too long, so it is above the tyde, the path will be canceled. If it is beneath the tyde it will be our new current solution. Is it even better than our best solution it will become our best solution.
Now the tyde will decrease.
Up: 3 The Great Deluge
Previous: 3.1 Getting started
Next: 3.3 Decreasing the tyde