welcome guest
login or register

Add new reply

Neither, I just wrote it here straight from my mind. Today I understood what I was after. My explanation was wrong.

The idea was to find the farthest turning point where you can go straightly. Then find from that point the farthest point where you can go without turning etc. It doesn't necessarily find the shortest route, but now when I think about it, it actually feels rather natural. However, it's pretty likely not what you needed. I'm very sorry for my lack of talent.

In JavaScript-like pseudocode:

First produce a route from beginning to end and put it in a list:

Route = list of turning points with Route[0] as beginning and Route[n] as the end.

function find_straight(a,b) /* returns a straight route (without turns from point a to the point b if there's one, returns NULL if there isn't. That's probably something you're using already. */

/* Here's the new algorithm represented as function */

function straighten_route(Route) {
/* introduce four local variables */
var Beginning = 0
var End = n
var i = 1
var New_route = [] /* an empty list */

/* Set the original beginning as the beginning of a new route */
New_route[0] = Route[0]

/* go on until Beginning has reached the end point of the route */
while (Beginning < n) {

while (find_straight(Route[Beginning],Route[End]) == Null)
{
/* move the end point towards the beginning until a straight route is found */
End = End - 1
}

/* When there is a straight route (remember that there's always a straight one at least to the next turn in the original route) */

/* add it to the new route */
New_route[i] = Route[End]

/* increment i */
i = i + 1

/* set found turn as a new beginning and End back to n */
Beginning = End
End = n
}

/* return the solution */
return New_route
}

CAPTCHA
Please reply with a single word.
Fill in the blank.