VB5, VB6 Construct a Data Web
Listing 1 You
need to model the data appropriately before the GA can get its teeth into the
Traveling Salesperson Problem. This code gets the linking process underway.
Public Sub RandomiseWeb(nodeCount As Long,
linkPercent _
As Long, WorldHeight As Single, WorldWidth _
As Single, WorldDepth As Single)
For Index = 1 To nodeCount
X = RndNum(0, WorldHeight) - WorldHeight / 2
Y = RndNum(0, WorldWidth) - WorldWidth / 2
Z = (RndNum(0, WorldDepth) - WorldDepth / 2) * -1
Addnode X, Y, Z
Next
linkCount = linkPercent * (nodeCount *(nodeCount - 1) _
/ 2) / 100
Do Until links.Count = linkCount
Set NdStart = RndObj(nodes)
Set NdTarget = RndObj(nodes)
Addlink NdStart, NdTarget
Loop
End Sub
Public Function linkUp(From As GAwebLib.node, Dest _
As GAwebLib.node)
Set Nd1 = From
Set Nd2 = Dest
Nd1.links.Add Me
Nd2.links.Add Me
a = Nd2.Y - Nd1.Y
b = Nd2.Z - Nd1.Z
c = Nd2.X - Nd1.X
a = a * a
b = b * b
c = c * c
Length = Format(Sqr(a + Sqr(b + c)), "Fixed")
End Function
VB5, VB6 Keep the System Fluid
Listing 2 Mutation, crossover, and replication
enable you to create a dynamic
balance that keeps the system teetering on the
edge of chaos.
|