A Genetic Algorthm Sample in T-SQL

  • Comments posted to this topic are about the item A Genetic Algorthm Sample in T-SQL

  • Great article.

    Even had a generation (749) get a perfect score of 500.

  • This is pretty interesting but I am still wondering how can I implement this into some of the complex processes I have for my job? Thanks for the thought provoking article.

    Ross

  • WOW... this is very interesting. I can see several possible applications in the Manufacturing Scheduling area: find the least cost path through a matrix of items where the "cans" are the cost in time to move from one item to another.... these procedures are a good place to start...

  • Very interesting article and I like to learn more about the concepts. On a practical level, how does one read the @rules table?

    For example, my first lines turned out:

    nsewca

    000014

    000114

    000211

    How can I link this back to the original grid to see what the computer decided?

    thanks!

  • Bill, this is great! I have been interested in Genetic Algorithms for quite some time, but I never thought of implementing them in T-SQL! Great stuff.

    Zach Mided
    www.AllianceGlobalServices.com

  • I like the article as I'm always want to learn something new! But I cannot say that I have understood everything and I certainly need to print this out and ready it through in a quite hour. :unsure:

  • Pieter as I understand it your rules say...

    IF North is empty and South is empty and East is empty and West is empty and there's a can on the current position THEN pick up can

    ELSE

    IF North is empty and South is empty and East is empty and West has a can and there's a can on the current position THEN pick up can

    ELSE

    IF North is empty and South is empty and East is empty and West has a wall and there's a can on the current position THEN move South

    To work out how it applies to the grid - pick a square, see want adjacent and on the current square and find the rule that matches (though when there are more than one matching rules it would depend on bit of dna created that rule)

  • youngi,

    in my example:

    nsewca

    000014

    000114

    000211

    starting at top left as indicated by article

    Line 1: instruction is not to move and pick up the can

    Line 2: Move 1 square to west and pick up can (however you would hit the wall)

    Line 3: Move an additional 2 squares to west and leave can (you would hit wall again)

    I am unsure what the A score represents.

    Somehow, I would have expected to be able to read the route the robot is going to take, based on prior leanings. Where am I going wrong?

    Thanks a bunch.

  • I'm so happy everyone is finding this article potentially useful. I apologize for "hiding" the rules table as a math formula instead of implementing it as a real table but the code runs twice as fast this way. It is important to remember the robot has no memory about previous moves; it only knows what adjacent squares look like now and makes a preprogrammed dna decision on what to do based on this current view. I could add some random walls in the grid and the robot would adapt and still perform very well.

  • "nsewc" is the specific view which defines the precise dna action that will be performed. The "a" is the action the robot will do which is either move one square or pick up the current can. The robot will never move a sequence of squares or pickups because it has no memory of previous actions.

  • Pieter

    The first square 0,0 is the rule has n=2;s=1;e=1;w=2;c=1

    as per

    --1100010010

    --1101101111

    ...

    this then selects the gene number 206 (from 2*81+1*27+1*9+2*3+1*1+1) from the dna. The rules are not in order of execution - their just the conditions extracted from the dna string

  • Awesome!!!!

    A real eye opener, wonder if other optimization techniques might also be simulated in SQL

  • youngi (1/14/2010)


    Pieter

    The first square 0,0 is the rule has n=2;s=1;e=1;w=2;c=1

    as per

    --1100010010

    --1101101111

    ...

    this then selects the gene number 206 (from 2*81+1*27+1*9+2*3+1*1+1) from the dna. The rules are not in order of execution - their just the conditions extracted from the dna string

    Ok, I get this for the first "turn". What about the second turn? If location 0,0 gets set to 0 then I would expect a rule for n=2;s=1;e=1;w=2;c=0 as that is what the robot would see after the first turn. I don't have a rule for that. I guess I'm not looking at something right.

  • If you run the included "DecipherDNA" script and do a "select *" at the bottom of it, you will see all 243 possible views numbered. These are the 243 rules hidden in the math formula as a sort of virtual table. The robot's dna strand is 243 characters long and matches up to these 243 views.

Viewing 15 posts - 1 through 15 (of 41 total)

You must be logged in to reply to this topic. Login to reply