On Monday, 30 July 2012 at 12:36:21 UTC, maarten van damme wrote:
For fun I started implementing a program that uses genetics
algorithm's to solve the travelling salesman problem. I want to
sort
an array of chromosome structures according to their fitness. I
now
get the error:
core.exception.AssertError@C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.
d(6714): Failed to sort range of type chromosome[]. Actual
result is: [chromosom
e([city(20, 0), city(25, 25), city(10, 65), city(50, 50),
city(75, 30), city(0,
10)]), chromosome([city(10, 65), city(50, 50), city(25, 25),
city(75, 30), city(
...
I have no idea what is wrong with my code and the error is not
very informative.
Does anyone have any idea as to what the problem could be?
(full code is at
https://dl.dropbox.com/u/15024434/travelling_salesman.d , If
it's not
something obvious then I'm going to try to reduce it to
something as
small as possible)
Maarten
I couldn't have access to your code, but my *guess* would be that
the provided "less", or in your probable case, your "opCmp", is
not transitive.
Eg, if you have 3 cities A, B and C, then if A<B and B<C, then
you MUST have A<C.
Could you post here your implementation of opCmp?
If you are trying to implement traveling salesman, then I don't
think "sort" is the algorithm should be using.