开发者

Find the right/best track combination for a given distance, using a genetic algorithm

开发者 https://www.devze.com 2023-01-23 21:16 出处:网络
I have a list of tracks (model railroad tracks) with different length, example: TrackA on 3.0cm, TrackB on 5.0cm,

I have a list of tracks (model railroad tracks) with different length, example: TrackA on 3.0cm, TrackB on 5.0cm, TrackC on 6.5cm, TrackD on 10.5cm

Then I want to find out of what kind of track I should put together to get from point A to point B with a given distance and a margin. And I should also be able to a prioritizes the use of track type.

Example; Distance from point A to B is 1.7m, and I have lot of TrackC and few of TrackB. 开发者_如何转开发And I will allow a margin on +/- 0.5cm to the distance.

What kind of tracks should I use, and how many of each track, and how many combination do I have, sorted after the track where I have most of.

I have Google after some C# help using genetic algorithm, but I am lost in, how I can implement this in a good methode.

Please help..


This is how you do it. Ill assume you are familiar with the basic G.A. concepts:

Each individual in the population much consist of various 'lengths of track'.

The primitive set would therefore be a set of constants corresponding to the lengths you have available fore example { 3, 4, 5}

The fitness of each individual is therefore said to be the sum of total error. Or more simply: say your track is supposed to be 1 metre long. If an individual is 1 metre long exactly, there is no error and the fitness is 0. If another individual has a length of 0.5m, its fitness is 0.5. So the lower the better.


So your algorithm goes like:

  1. Construct a population (maybe randomly but there are other techniques for initialisation such as ramped half-and-half, full etc... look them up).
  2. Assess the fitness of each individual. If any have fitness within a certain margin, you're done.
  3. Else advance by one generation via crossover / reproduction / mutation.
  4. Goto #2
0

精彩评论

暂无评论...
验证码 换一张
取 消