Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12345»»»

A Genetic Algorthm Sample in T-SQL Expand / Collapse
Author
Message
Posted Thursday, January 14, 2010 7:59 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 1:05 PM
Points: 137, Visits: 869
"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.
Post #847560
Posted Thursday, January 14, 2010 8:09 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, March 21, 2011 8:37 AM
Points: 4, Visits: 17
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

Post #847576
Posted Thursday, January 14, 2010 8:12 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, August 29, 2014 9:48 AM
Points: 3, Visits: 12
Awesome!!!!
A real eye opener, wonder if other optimization techniques might also be simulated in SQL
Post #847580
Posted Thursday, January 14, 2010 9:08 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, September 4, 2014 7:52 AM
Points: 361, Visits: 1,535
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.
Post #847644
Posted Thursday, January 14, 2010 9:18 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 1:05 PM
Points: 137, Visits: 869
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.
Post #847660
Posted Thursday, January 14, 2010 9:21 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, September 4, 2014 7:52 AM
Points: 361, Visits: 1,535
Bill Talada (1/14/2010)
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.


Ooops I got ya. It's just showing what it does if it is sitting on a can right now. Thanks. This is really cool.
Post #847664
Posted Thursday, January 14, 2010 10:46 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, February 16, 2012 3:34 PM
Points: 10, Visits: 57
.
Post #847752
Posted Thursday, January 14, 2010 10:57 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, September 4, 2014 7:52 AM
Points: 361, Visits: 1,535
jeremiah.thomas (1/14/2010)
I think i am with Valued member. how do we read the grid that decipherDNA creates?

here is a short example of the grid:

n s e w c a
0 0 0 0 1 4
0 0 0 1 1 4
0 0 0 2 1 4
0 0 1 0 1 4
0 0 1 1 1 1
0 0 1 2 1 3
0 0 2 0 1 4
0 0 2 1 1 1
0 1 0 0 1 3




Ok, I have it figured out now. That first line is not what the robot did first. It's what it would do if it encountered that situation, (no can north,south,east,west but it's current location had a can. It would pick it up as indicated by the last digit "4". What you need to do is take it's starting location of 0,0 and determine what the robot would see at that location. It sees 2 1 1 2 1 (that's wall north and west, can south, east and current location.) Now find that in the results of the DecipherDNA script. Oh, first remove the WHERE CLAUSE on the last line. select * from @rules is what you want.
Post #847758
Posted Thursday, January 14, 2010 11:04 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, February 16, 2012 3:34 PM
Points: 10, Visits: 57
thank you very much that makes alot of sense now.
Post #847764
Posted Thursday, January 14, 2010 12:04 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, July 22, 2010 8:59 AM
Points: 110, Visits: 952
"awesome" - you did an excellent job of making genetic algorithms approachable

I would like to implement this kind of problem solver to our real world situation. What I would love to see next is a deconstruction of a non-toy example that could be solved by GA. I realize that's meta-programming, but if you could express a guide to fitting problems with GA solutions it would be extremely valuable. (even if it's only a "How to approach..." on determining genes or fitness scoring for a specific environment)

I was expecting "A Genetic Algorthm Sample in T-SQL" to use more declarative programming than a procedural approach. Do you think it is possible to construct your example as a selection from a cross product of genetics? I'm imagining a recursive CTE to manage iterations limited by a generational average score below the previous generational average. If you think it's not possible (or simply unfeasibly difficult) does that fact indicate that GA solutions are perhaps ill-suited for modelling in SQL ?

thanks for giving me something interesting to think about today. :)
Post #847809
« Prev Topic | Next Topic »

Add to briefcase ««12345»»»

Permissions Expand / Collapse