%@ Language=VBScript %><% option explicit %>
<% Response.Buffer = FALSE %>
<% Response.ContentType = "image/svg+xml" %>
<%
DIM ScreenWidth, ScreenHeight
DIM timeout
DIM msg '-- for errors
DIM RWline1, RWline2, RWline3, RWline4, RWline5
'--- attribute values and measures for individuals in the population ---
DIM A_value, B_value, A_value_parent, B_value_parent
DIM A_max, B_max, A_min, B_min, A_diff, B_diff
DIM A_value_sum, A_value_SQ_sum, A_value_var, A_value_var_max
DIM B_value_sum, B_value_SQ_sum, B_value_var, B_value_var_max
DIM A_plus, B_plus, A_minus, B_minus
DIM A_opt, B_opt
'--- populations ---
DIM pop_count_ur, pop_count_max
DIM pop_count_parent, pop_count_parent1, pop_count_child, pop_count_child1
DIM pop_count_genX
DIM pop_count
'--- pop arrays
DIM aPop_ur()
DIM aPop_genX() 'copy of aPop_2gen for child for gen_x
DIM aPop_2gen() '0,1; 4,5; for parent and for child - switch back and forth
'-- col 2=AB_dist, and 3=offspring_count -- set for child, used for parent
'-- there are two concepts of distance: from rhw optimum and from the pop_average
'-- dist, as used here, refers to distance from the optimum
DIM parent_offset 'column 0 or 3 in aPop_2gen containing parent's attributes A and B
DIM child_offset 'column 0 or 3 in aPop_2gen containing child's attributes A and B
DIM child_offset_B, parent_offset_B 'offset+1 = column 1 or 4
DIM child_offset_dist, parent_offset_dist 'offset+2 = column 2 or 5
DIM child_offset_cell, parent_offset_cell 'offset+3 = column 3 or 6
'--- the selection process: how many kids a parent will have ---
DIM select1, AB_dist_select, AB_dist_select1, rand_select
DIM select_type '0=whole population; 1=local pop within cell
'--- reproduction of individuals in the parent population (parent generation) ---
DIM AB_dist, AB_parent_dist
DIM AB_child_dist_max, AB_child_dist_min, AB_child_dist_sum, AB_child_dist_avg
DIM AB_parent_dist_max, AB_parent_dist_min, AB_parent_dist_avg
DIM AB_parent_dist_range, AB_parent_dist_range1 'difference between most optimal (closest) parent and least
DIM AB_parent_dist_pos, AB_parent_dist_pos1 'position of a parent in the range (dist-min) - global, local
'pos/range gives us a number that indicates distance relative to other parents
DIM AB_dist_max_max
DIM offspring_count
DIM parent_no_kids, parent_1_kid, parent_2_kids, parent_3_kids
DIM parent_4_kids, parent_5_kids, parent_6_kids, parent_7_kids
DIM offspring_max 'max offspring per parent
DIM offspring_0_1, offspring_1_2, offspring_2_3
DIM offspring_3_4, offspring_4_5, offspring_5_6
DIM offspring_6_7, offspring_7_8
'--- geographic cells ---
DIM cell_count, cellNo
DIM aCell(6,100), aCell_ur(3,100), aCell_X(3,100)
' 0&3=cell_count, 1&4=dist_min, 2&5=dist_max
' uses child_offset and parent_offset to exchange columns
' also uses child_offset_cell_min = child_offset+1
' also uses child_offset_cell_max = child_offset+2
DIM child_offset_cell_min, parent_offset_cell_min
DIM child_offset_cell_max, parent_offset_cell_max
'--- generations ---
DIM gen_count, gen_count1, gen_count_max, gen_count_limit
DIM gen_count_genX
DIM aGen_stats() '0=pop_count_parent, 1=pop_growth_rate
'2=AB_child_dist_avg, 3=AB_child_dist_max, 4=AB_child_dist_min
'4=offspring/parent, 5=
'--- operating params
DIM randNo
DIM x1 'horizontal
DIM y1 'vertical
DIM i1, i2, i3 'integers for display
'-- display, test, and development
DIM test 'to trigger the print out
DIM test1 'to display the print out
DIM display_right 'for right side of monitor
' 0=pop stats, 1=cell stats, 2=cells
select_type = 1 '0=whole population; 1=local pop within cell
test=2 '>0 allows print, =0 for diagnostics
display_right = 2 '0=pop stats, 1=cell stats, 2=cells
'' extend the timeout to allow for long files
timeout = Server.ScriptTimeout
'' Response.Write "Initial timeout=" & timeout & " "
Server.ScriptTimeout = 1200 '3600
' ------ set up constants for the simulation --------
ScreenWidth = Request.Cookies("Humble")("ScreenWidth")
ScreenHeight = Request.Cookies("Humble")("ScreenHeight")
'--- init_Pop
A_max = Request.Cookies("Humble")("max_A")
B_max = Request.Cookies("Humble")("max_B")
A_min = Request.Cookies("Humble")("min_A")
B_min = Request.Cookies("Humble")("min_B")
A_diff = A_max - A_min
B_diff = B_max - B_min
pop_count_ur = Request.Cookies("Humble")("urPopCount") - 1
pop_count_max = Request.Cookies("Humble")("PopCountLimit")
'--- init_Opt
A_opt = Request.Cookies("Humble")("Opt_A")
B_opt = Request.Cookies("Humble")("Opt_B")
'--- initCopy
gen_count_max = Request.Cookies("Humble")("CopyStepCount") 'max generations
gen_count_genX = CInt(Request.Cookies("Humble")("CopyStepGen_x"))
parent_no_kids = Request.Cookies("Humble")("parent_no_kids")
parent_1_kid = Request.Cookies("Humble")("parent_1_kid")
parent_2_kids = Request.Cookies("Humble")("parent_2_kids")
parent_3_kids = Request.Cookies("Humble")("parent_3_kids")
parent_4_kids = Request.Cookies("Humble")("parent__4_kids")
parent_5_kids = Request.Cookies("Humble")("parent_5_kids")
parent_6_kids = Request.Cookies("Humble")("parent_6_kids")
parent_7_kids = Request.Cookies("Humble")("parent_7_kids")
AB_dist_select = CDbl(Request.Cookies("Humble")("DistRate")) / 100.0
rand_select = 1.0 - AB_dist_select
' rand_select = CDbl(Request.Cookies("Humble")("RandRate"))
offspring_max = Request.Cookies("Humble")("CopyRate")
A_plus = Request.Cookies("Humble")("A_plus") * 2 'simplify calculation
A_minus = Request.Cookies("Humble")("A_minus") * 2
B_plus = Request.Cookies("Humble")("B_plus") * 2
B_minus = Request.Cookies("Humble")("B_minus") * 2
'--- inSelect
ReDIM aPop_ur(3,(pop_count_ur+1))
ReDIM aPop_2gen(7,pop_count_max+1) '4 for parent and 4 for child - switch back and forth
ReDIM aGen_stats(6,gen_count_max+1)
'-- still to do: bias to growth, shrinking ---
' -- normally offspring_count = 1, each parent gets 1 offspring --
' -- max distance from optimum - from 4 corners - extreme -------
AB_dist_max_max = SQR((A_opt-0)^2 + (B_opt-0)^2)
AB_dist = SQR((A_opt-0)^2 + (B_opt-100)^2)
IF AB_dist > AB_dist_max_max THEN
AB_dist_max_max = AB_dist
END IF
AB_dist = SQR((A_opt-100)^2 + (B_opt-0)^2)
IF AB_dist > AB_dist_max_max THEN
AB_dist_max_max = AB_dist
END IF
AB_dist = SQR((A_opt-100)^2 + (B_opt-100)^2)
IF AB_dist > AB_dist_max_max THEN
AB_dist_max_max = AB_dist
END IF
' -- max offspring and reproduction rates (lottery) --
offspring_0_1 = parent_no_kids / 100.0
offspring_1_2 = parent_1_kid / 100.0
offspring_2_3 = parent_2_kids / 100.0
offspring_3_4 = parent_3_kids / 100.0
offspring_4_5 = parent_4_kids / 100.0
offspring_5_6 = parent_5_kids / 100.0
offspring_6_7 = parent_6_kids / 100.0
offspring_7_8 = parent_7_kids / 100.0
offspring_7_8 = offspring_0_1 + offspring_1_2 + offspring_2_3 + offspring_3_4 + offspring_4_5 + offspring_5_6 + offspring_6_7 + offspring_7_8
offspring_6_7 = offspring_0_1 + offspring_1_2 + offspring_2_3 + offspring_3_4 + offspring_4_5 + offspring_5_6 + offspring_6_7
offspring_5_6 = offspring_0_1 + offspring_1_2 + offspring_2_3 + offspring_3_4 + offspring_4_5 + offspring_5_6
offspring_4_5 = offspring_0_1 + offspring_1_2 + offspring_2_3 + offspring_3_4 + offspring_4_5
offspring_3_4 = offspring_0_1 + offspring_1_2 + offspring_2_3 + offspring_3_4
offspring_2_3 = offspring_0_1 + offspring_1_2 + offspring_2_3
offspring_1_2 = offspring_0_1 + offspring_1_2
offspring_0_1 = offspring_0_1
' **************************************************************************
'-- every individual is referred to twice, once as child and then as parent --
' ------ initialize parameters that vary from generation to generation ------
parent_offset = 4 'initial value, will exchange with child_offset
child_offset = 0 'initially ur population (generation 0)
child_offset_B = child_offset+1
child_offset_dist = child_offset+2
child_offset_cell = child_offset+3
child_offset_cell_min = child_offset+1
child_offset_cell_max = child_offset+2
' ------ initialize urPopulation: first children in first population ------
' --- record the first (ur) generation in a separate array as well ---
AB_child_dist_max = 0
AB_child_dist_min = 1000
AB_child_dist_sum = 0
A_value_sum = 0
A_value_SQ_sum = 0
B_value_sum = 0
B_value_SQ_sum = 0
FOR cell_count = 0 TO 99
aCell(child_offset,cell_count) = 0
aCell(child_offset_cell_min,cell_count) = 1000
aCell(child_offset_cell_max,cell_count) = 0
NEXT
' start random number generator
RANDOMIZE
FOR pop_count = 0 TO pop_count_ur
A_value = A_min + ROUND( RND * A_diff)
A_value_sum = A_value_sum + A_value
A_value_SQ_sum = A_value_SQ_sum + A_value^2
aPop_ur(0,pop_count) = A_value
aPop_2gen(child_offset,pop_count) = A_value
B_value = (B_min + ROUND( RND * B_diff)) * 2
B_value_sum = B_value_sum + B_value
B_value_SQ_sum = B_value_SQ_sum + B_value^2
aPop_ur(1,pop_count) = B_value
aPop_2gen(child_offset_B,pop_count) = B_value
'dist
AB_dist = SQR((A_opt-A_value)^2 + (B_opt-B_value)^2) 'used when ur becomes parent
aPop_ur(2,pop_count) = AB_dist
aPop_2gen(child_offset_dist,pop_count) = AB_dist 'child distance from optimum - for repro.
AB_child_dist_sum = AB_child_dist_sum + AB_dist 'for getting the average
IF AB_dist > AB_child_dist_max THEN
AB_child_dist_max = AB_dist '**max distance between pop_ur and optimum
ELSEIF AB_dist < AB_child_dist_min THEN
AB_child_dist_min = AB_dist
END IF
'cell
cellNo = INT( RND * 100.0)
IF cellNo > 99 THEN
cellNo = 99
END IF
aCell(child_offset,cellNo) = aCell(child_offset,cellNo) + 1
aPop_2gen(child_offset_cell,pop_count) = cellNo
IF AB_dist < aCell(child_offset_cell_min,cellNo) THEN
aCell(child_offset_cell_min,cellNo) = AB_dist
END IF
IF AB_dist > aCell(child_offset_cell_max,cellNo) THEN
aCell(child_offset_cell_max,cellNo) = AB_dist
END IF
NEXT
'-- generation statistics ---
IF pop_count_ur > 0 THEN
AB_child_dist_avg = AB_child_dist_sum / (pop_count_ur + 1)
END IF
pop_count_child = pop_count_ur
A_value_var = (((pop_count_child+1)*A_value_SQ_sum) - (A_value_sum^2)) / (pop_count_child*(pop_count_child+1))
IF A_value_var > A_value_var_max THEN
A_value_var_max = A_value_var
END IF
B_value_var = (((pop_count_child+1)*B_value_SQ_sum) - (B_value_sum^2)) / (pop_count_child*(pop_count_child+1))
IF B_value_var > B_value_var_max THEN
B_value_var_max = B_value_var
END IF
FOR cell_count = 0 TO 99
aCell_ur(0,cell_count) = aCell(child_offset,cell_count)
aCell_ur(1,cell_count) = aCell(child_offset_cell_min,cell_count)
aCell_ur(2,cell_count) = aCell(child_offset_cell_max,cell_count)
NEXT
' **************************************************************************
'--- Loop through the evolution generations with gen_count = CopyStepCount ------
' ------ each generation has both parents and children ---------
FOR gen_count = 0 TO gen_count_max - 1
' test1 = gen_count
IF pop_count_child > 0 THEN 'must have individuals in the population
'--- record generation X in a separate array, the parents ---
IF gen_count = gen_count_genX THEN
ReDIM aPop_genX(3,(pop_count_child+1))
FOR pop_count = 0 TO pop_count_child
aPop_genX(0,pop_count) = aPop_2gen(child_offset,pop_count)
aPop_genX(1,pop_count) = aPop_2gen(child_offset_B,pop_count)
NEXT 'FOR pop_count = 0 TO pop_count_child
pop_count_genX = pop_count_child
FOR cell_count = 0 TO 99
aCell_X(0,cell_count) = aCell(child_offset,cell_count)
aCell_X(1,cell_count) = aCell(child_offset_cell_min,cell_count)
aCell_X(2,cell_count) = aCell(child_offset_cell_max,cell_count)
NEXT
END IF
'*********************************************************************
' --- change pointers so that the children become parents in turn ---
' --- * also collect distance info -- for selection * ---
parent_offset_B = parent_offset '** used as temporary storage in swap
parent_offset = child_offset
child_offset = parent_offset_B '** from temporary storage in swap
child_offset_B = child_offset+1
child_offset_dist = child_offset+2
child_offset_cell = child_offset+3
child_offset_cell_min = child_offset+1
child_offset_cell_max = child_offset+2
parent_offset_B = parent_offset+1
parent_offset_dist = parent_offset+2
parent_offset_cell = parent_offset+3
parent_offset_cell_min = child_offset+1
parent_offset_cell_max = child_offset+2
pop_count_parent = pop_count_child
AB_parent_dist_max = AB_child_dist_max
AB_parent_dist_min = AB_child_dist_min
AB_parent_dist_avg = AB_child_dist_avg
AB_parent_dist_range = AB_parent_dist_max - AB_parent_dist_min
AB_child_dist_max = 0
AB_child_dist_min = 1000
AB_child_dist_sum = 0
A_value_sum = 0
A_value_SQ_sum = 0
B_value_sum = 0
B_value_SQ_sum = 0
pop_count_child = -1 'start new incremental count, but increment first at use
pop_count_parent1 = 0 'count of parent that stops at pop_count_max
FOR cell_count = 0 TO 99
aCell(child_offset,cell_count) = 0
aCell(child_offset_cell_min,cell_count) = 1000
aCell(child_offset_cell_max,cell_count) = 0
NEXT
'*********************************************************************
'--- start with the parents, the children of the previous generation ---
'---- Loop through the individuals in the parent generation ----
FOR pop_count = 0 TO pop_count_parent
'the population grows or shrinks - in pop_count_child
'once the maximum allotment for children has been exceeded,
' the remaining parents cannot reproduce and are ignored
IF pop_count_child < (pop_count_max-offspring_max) THEN 'allow of offspring_count
pop_count_parent1 = pop_count + 1 'one more parent in offspring lottery
'--- get parent's values and distance from optimum -- calculated as child
A_value_parent = aPop_2gen(parent_offset,pop_count) 'previous child is now parent
B_value_parent = aPop_2gen(parent_offset_B,pop_count)
cellNo = aPop_2gen(parent_offset_cell,pop_count) 'cell in which parent resides
AB_parent_dist = aPop_2gen(parent_offset_dist,pop_count)
AB_parent_dist_pos = AB_parent_dist - AB_parent_dist_min 'relative distance from global range optimum
IF select_type = 0 THEN
AB_dist_select1 = (1.0 - (AB_parent_dist_pos / AB_parent_dist_range)) * AB_dist_select
ELSE
AB_parent_dist_range1 = aCell(parent_offset_cell_max,cellNo) - aCell(parent_offset_cell_min,cellNo)
IF AB_parent_dist_range1 > 0.1 THEN
AB_parent_dist_pos1 = AB_parent_dist - aCell(parent_offset_cell_min,cellNo) 'local pos
AB_dist_select1 = (1.0 - (AB_parent_dist_pos1 / AB_parent_dist_range1)) * AB_dist_select
ELSE 'probably a single individual in the cell - use the global selection
' AB_dist_select1 = (1.0 - (AB_parent_dist_pos / AB_parent_dist_range)) * AB_dist_select
AB_dist_select1 = (0.5) * AB_dist_select
END IF
END IF
'--- basic reproduction lottery on which parent has children, and how many
randNo = RND * rand_select
'--- ignore distance selection for the moment
select1 = randNo + AB_dist_select1
IF select1 > offspring_6_7 THEN
offspring_count = 0
ELSEIF select1 > offspring_5_6 THEN
offspring_count = 6
ELSEIF select1 > offspring_4_5 THEN
offspring_count = 5
ELSEIF select1 > offspring_3_4 THEN
offspring_count = 4
ELSEIF select1 > offspring_2_3 THEN
offspring_count = 3
ELSEIF select1 > offspring_1_2 THEN
offspring_count = 2
ELSEIF select1 > offspring_0_1 THEN
offspring_count = 1
ELSE
offspring_count = 0
END IF
'-- copy to first child, add variablity to attributes A and B independently --
IF offspring_count > 0 THEN
pop_count_child = pop_count_child + 1
randNo = RND
IF randNo < 0.5 THEN
A_value = A_value_parent-(0.5-randNo)*A_minus
ELSEIF randNo > 0.5 THEN
A_value = A_value_parent+(randNo-0.5)*A_plus
ELSE
A_value = A_value_parent
END IF
A_value = ROUND( A_value)
A_value_sum = A_value_sum + A_value
A_value_SQ_sum = A_value_SQ_sum + A_value^2
aPop_2gen(child_offset,pop_count_child) = A_value
randNo = RND
IF randNo < 0.5 THEN
B_value = B_value_parent-(0.5-randNo)*B_minus
ELSEIF randNo > 0.5 THEN
B_value = B_value_parent+(randNo-0.5)*B_plus
ELSE
B_value = B_value_parent
END IF
B_value = ROUND( B_value)
B_value_sum = B_value_sum + B_value
B_value_SQ_sum = B_value_SQ_sum + B_value^2
aPop_2gen(child_offset_B,pop_count_child) = B_value
'dist
AB_dist = SQR((A_opt-A_value)^2 + (B_opt-B_value)^2)
aPop_2gen(child_offset_dist,pop_count_child) = AB_dist
AB_child_dist_sum = AB_child_dist_sum + AB_dist
IF AB_dist > AB_child_dist_max THEN
AB_child_dist_max = AB_dist
ELSEIF AB_dist < AB_child_dist_min THEN
AB_child_dist_min = AB_dist
END IF
'cell
aCell(child_offset,cellNo) = aCell(child_offset,cellNo) + 1
aPop_2gen(child_offset_cell,pop_count_child) = cellNo
IF AB_dist < aCell(child_offset_cell_min,cellNo) THEN
aCell(child_offset_cell_min,cellNo) = AB_dist
END IF
IF AB_dist > aCell(child_offset_cell_max,cellNo) THEN
aCell(child_offset_cell_max,cellNo) = AB_dist
END IF
END IF ' offspring_count > 0
' -------------------------- copy to second child ------------
IF offspring_count > 1 THEN
pop_count_child = pop_count_child + 1
randNo = RND
IF randNo < 0.5 THEN
A_value = A_value_parent-(0.5-randNo)*A_minus
ELSEIF randNo > 0.5 THEN
A_value = A_value_parent+(randNo-0.5)*A_plus
ELSE
A_value = A_value_parent
END IF
A_value = ROUND( A_value)
A_value_sum = A_value_sum + A_value
A_value_SQ_sum = A_value_SQ_sum + A_value^2
aPop_2gen(child_offset,pop_count_child) = A_value
randNo = RND
IF randNo < 0.5 THEN
B_value = B_value_parent-(0.5-randNo)*B_minus
ELSEIF randNo > 0.5 THEN
B_value = B_value_parent+(randNo-0.5)*B_plus
ELSE
B_value = B_value_parent
END IF
B_value = ROUND( B_value)
B_value_sum = B_value_sum + B_value
B_value_SQ_sum = B_value_SQ_sum + B_value^2
aPop_2gen(child_offset_B,pop_count_child) = B_value
'dist
AB_dist = SQR((A_opt-A_value)^2 + (B_opt-B_value)^2)
aPop_2gen(child_offset_dist,pop_count_child) = AB_dist
AB_child_dist_sum = AB_child_dist_sum + AB_dist
IF AB_dist > AB_child_dist_max THEN
AB_child_dist_max = AB_dist
ELSEIF AB_dist < AB_child_dist_min THEN
AB_child_dist_min = AB_dist
END IF
'cell
aCell(child_offset,cellNo) = aCell(child_offset,cellNo) + 1
aPop_2gen(child_offset_cell,pop_count_child) = cellNo
IF AB_dist < aCell(child_offset_cell_min,cellNo) THEN
aCell(child_offset_cell_min,cellNo) = AB_dist
END IF
IF AB_dist > aCell(child_offset_cell_max,cellNo) THEN
aCell(child_offset_cell_max,cellNo) = AB_dist
END IF
END IF ' offspring_count > 1
' -------------------------- copy to third child ------------
IF offspring_count > 2 THEN
pop_count_child = pop_count_child + 1
randNo = RND
IF randNo < 0.5 THEN
A_value = A_value_parent-(0.5-randNo)*A_minus
ELSEIF randNo > 0.5 THEN
A_value = A_value_parent+(randNo-0.5)*A_plus
ELSE
A_value = A_value_parent
END IF
randNo = RND
IF randNo < 0.5 THEN
B_value = B_value_parent-(0.5-randNo)*B_minus
ELSEIF randNo > 0.5 THEN
B_value = B_value_parent+(randNo-0.5)*B_plus
ELSE
B_value = B_value_parent
END IF
A_value = ROUND( A_value)
A_value_sum = A_value_sum + A_value
A_value_SQ_sum = A_value_SQ_sum + A_value^2
aPop_2gen(child_offset,pop_count_child) = A_value
B_value = ROUND( B_value)
B_value_sum = B_value_sum + B_value
B_value_SQ_sum = B_value_SQ_sum + B_value^2
aPop_2gen(child_offset_B,pop_count_child) = B_value
'dist
AB_dist = SQR((A_opt-A_value)^2 + (B_opt-B_value)^2)
aPop_2gen(child_offset_dist,pop_count_child) = AB_dist
AB_child_dist_sum = AB_child_dist_sum + AB_dist
IF AB_dist > AB_child_dist_max THEN
AB_child_dist_max = AB_dist
ELSEIF AB_dist < AB_child_dist_min THEN
AB_child_dist_min = AB_dist
END IF
'cell
aCell(child_offset,cellNo) = aCell(child_offset,cellNo) + 1
aPop_2gen(child_offset_cell,pop_count_child) = cellNo
IF AB_dist < aCell(child_offset_cell_min,cellNo) THEN
aCell(child_offset_cell_min,cellNo) = AB_dist
END IF
IF AB_dist > aCell(child_offset_cell_max,cellNo) THEN
aCell(child_offset_cell_max,cellNo) = AB_dist
END IF
END IF ' offspring_count > 2
' -------------------------- copy to fourth child ------------
IF offspring_count > 3 THEN
pop_count_child = pop_count_child + 1
randNo = RND
IF randNo < 0.5 THEN
A_value = A_value_parent-(0.5-randNo)*A_minus
ELSEIF randNo > 0.5 THEN
A_value = A_value_parent+(randNo-0.5)*A_plus
ELSE
A_value = A_value_parent
END IF
randNo = RND
IF randNo < 0.5 THEN
B_value = B_value_parent-(0.5-randNo)*B_minus
ELSEIF randNo > 0.5 THEN
B_value = B_value_parent+(randNo-0.5)*B_plus
ELSE
B_value = B_value_parent
END IF
A_value = ROUND( A_value)
A_value_sum = A_value_sum + A_value
A_value_SQ_sum = A_value_SQ_sum + A_value^2
aPop_2gen(child_offset,pop_count_child) = A_value
B_value = ROUND( B_value)
B_value_sum = B_value_sum + B_value
B_value_SQ_sum = B_value_SQ_sum + B_value^2
aPop_2gen(child_offset_B,pop_count_child) = B_value
'dist
AB_dist = SQR((A_opt-A_value)^2 + (B_opt-B_value)^2)
aPop_2gen(child_offset_dist,pop_count_child) = AB_dist
AB_child_dist_sum = AB_child_dist_sum + AB_dist
IF AB_dist > AB_child_dist_max THEN
AB_child_dist_max = AB_dist
ELSEIF AB_dist < AB_child_dist_min THEN
AB_child_dist_min = AB_dist
END IF
'cell
aCell(child_offset,cellNo) = aCell(child_offset,cellNo) + 1
aPop_2gen(child_offset_cell,pop_count_child) = cellNo
IF AB_dist < aCell(child_offset_cell_min,cellNo) THEN
aCell(child_offset_cell_min,cellNo) = AB_dist
END IF
IF AB_dist > aCell(child_offset_cell_max,cellNo) THEN
aCell(child_offset_cell_max,cellNo) = AB_dist
END IF
END IF ' offspring_count > 3
' -------------------------- copy to fifth child ------------
IF offspring_count > 4 THEN
pop_count_child = pop_count_child + 1
randNo = RND
IF randNo < 0.5 THEN
A_value = A_value_parent-(0.5-randNo)*A_minus
ELSEIF randNo > 0.5 THEN
A_value = A_value_parent+(randNo-0.5)*A_plus
ELSE
A_value = A_value_parent
END IF
randNo = RND
IF randNo < 0.5 THEN
B_value = B_value_parent-(0.5-randNo)*B_minus
ELSEIF randNo > 0.5 THEN
B_value = B_value_parent+(randNo-0.5)*B_plus
ELSE
B_value = B_value_parent
END IF
A_value = ROUND( A_value)
A_value_sum = A_value_sum + A_value
A_value_SQ_sum = A_value_SQ_sum + A_value^2
aPop_2gen(child_offset,pop_count_child) = A_value
B_value = ROUND( B_value)
B_value_sum = B_value_sum + B_value
B_value_SQ_sum = B_value_SQ_sum + B_value^2
aPop_2gen(child_offset_B,pop_count_child) = B_value
'dist
AB_dist = SQR((A_opt-A_value)^2 + (B_opt-B_value)^2)
aPop_2gen(child_offset_dist,pop_count_child) = AB_dist
AB_child_dist_sum = AB_child_dist_sum + AB_dist
IF AB_dist > AB_child_dist_max THEN
AB_child_dist_max = AB_dist
ELSEIF AB_dist < AB_child_dist_min THEN
AB_child_dist_min = AB_dist
END IF
'cell
aCell(child_offset,cellNo) = aCell(child_offset,cellNo) + 1
aPop_2gen(child_offset_cell,pop_count_child) = cellNo
IF AB_dist < aCell(child_offset_cell_min,cellNo) THEN
aCell(child_offset_cell_min,cellNo) = AB_dist
END IF
IF AB_dist > aCell(child_offset_cell_max,cellNo) THEN
aCell(child_offset_cell_max,cellNo) = AB_dist
END IF
END IF ' offspring_count > 4
' -------------------------- copy to sixth child ------------
IF offspring_count > 5 THEN
pop_count_child = pop_count_child + 1
randNo = RND
IF randNo < 0.5 THEN
A_value = A_value_parent-(0.5-randNo)*A_minus
ELSEIF randNo > 0.5 THEN
A_value = A_value_parent+(randNo-0.5)*A_plus
ELSE
A_value = A_value_parent
END IF
randNo = RND
IF randNo < 0.5 THEN
B_value = B_value_parent-(0.5-randNo)*B_minus
ELSEIF randNo > 0.5 THEN
B_value = B_value_parent+(randNo-0.5)*B_plus
ELSE
B_value = B_value_parent
END IF
A_value = ROUND( A_value)
A_value_sum = A_value_sum + A_value
A_value_SQ_sum = A_value_SQ_sum + A_value^2
aPop_2gen(child_offset,pop_count_child) = A_value
B_value = ROUND( B_value)
B_value_sum = B_value_sum + B_value
B_value_SQ_sum = B_value_SQ_sum + B_value^2
aPop_2gen(child_offset_B,pop_count_child) = B_value
'dist
AB_dist = SQR((A_opt-A_value)^2 + (B_opt-B_value)^2)
aPop_2gen(child_offset_dist,pop_count_child) = AB_dist
AB_child_dist_sum = AB_child_dist_sum + AB_dist
IF AB_dist > AB_child_dist_max THEN
AB_child_dist_max = AB_dist
ELSEIF AB_dist < AB_child_dist_min THEN
AB_child_dist_min = AB_dist
END IF
'cell
aCell(child_offset,cellNo) = aCell(child_offset,cellNo) + 1
aPop_2gen(child_offset_cell,pop_count_child) = cellNo
IF AB_dist < aCell(child_offset_cell_min,cellNo) THEN
aCell(child_offset_cell_min,cellNo) = AB_dist
END IF
IF AB_dist > aCell(child_offset_cell_max,cellNo) THEN
aCell(child_offset_cell_max,cellNo) = AB_dist
END IF
END IF ' offspring_count > 5
' -------------------------- copy to seventh child ------------
IF offspring_count > 6 THEN
pop_count_child = pop_count_child + 1
randNo = RND
IF randNo < 0.5 THEN
A_value = A_value_parent-(0.5-randNo)*A_minus
ELSEIF randNo > 0.5 THEN
A_value = A_value_parent+(randNo-0.5)*A_plus
ELSE
A_value = A_value_parent
END IF
randNo = RND
IF randNo < 0.5 THEN
B_value = B_value_parent-(0.5-randNo)*B_minus
ELSEIF randNo > 0.5 THEN
B_value = B_value_parent+(randNo-0.5)*B_plus
ELSE
B_value = B_value_parent
END IF
A_value = ROUND( A_value)
A_value_sum = A_value_sum + A_value
A_value_SQ_sum = A_value_SQ_sum + A_value^2
aPop_2gen(child_offset,pop_count_child) = A_value
B_value = ROUND( B_value)
B_value_sum = B_value_sum + B_value
B_value_SQ_sum = B_value_SQ_sum + B_value^2
aPop_2gen(child_offset_B,pop_count_child) = B_value
'dist
AB_dist = SQR((A_opt-A_value)^2 + (B_opt-B_value)^2)
aPop_2gen(child_offset_dist,pop_count_child) = AB_dist
AB_child_dist_sum = AB_child_dist_sum + AB_dist
IF AB_dist > AB_child_dist_max THEN
AB_child_dist_max = AB_dist
ELSEIF AB_dist < AB_child_dist_min THEN
AB_child_dist_min = AB_dist
END IF
'cell
aCell(child_offset,cellNo) = aCell(child_offset,cellNo) + 1
aPop_2gen(child_offset_cell,pop_count_child) = cellNo
IF AB_dist < aCell(child_offset_cell_min,cellNo) THEN
aCell(child_offset_cell_min,cellNo) = AB_dist
END IF
IF AB_dist > aCell(child_offset_cell_max,cellNo) THEN
aCell(child_offset_cell_max,cellNo) = AB_dist
END IF
END IF ' offspring_count > 6
' -----------------------------------------------------------------------
ELSE
IF gen_count_limit = 0 THEN
gen_count_limit = gen_count
END IF
END IF '(pop_count_child < (pop_count_max-offspring_max))
NEXT 'FOR pop_count = 0 TO pop_count_parent
'---- end of loop through the individuals within the parent generation
' -----------------------------------------------------------------------
'*********************************************************************
'-- generation statistics ---
aGen_stats(0,gen_count) = pop_count_child + 1
aGen_stats(1,gen_count) = (pop_count_child + 1) / pop_count_parent1
IF pop_count_child > 0 THEN
AB_child_dist_avg = AB_child_dist_sum / (pop_count_child+1)
aGen_stats(2,gen_count) = AB_child_dist_avg
aGen_stats(3,gen_count) = AB_child_dist_max
aGen_stats(4,gen_count) = AB_child_dist_min
ELSEIF pop_count_child = 0 THEN
AB_child_dist_avg = AB_child_dist_sum
aGen_stats(2,gen_count) = AB_child_dist_avg
aGen_stats(3,gen_count) = AB_child_dist_max
aGen_stats(4,gen_count) = AB_child_dist_min
ELSE
' test = 0 'go for diagnostics
aGen_stats(2,gen_count) = AB_dist_max_max - 10
aGen_stats(3,gen_count) = AB_dist_max_max - 20
aGen_stats(4,gen_count) = AB_dist_max_max - 30
END IF
IF pop_count_parent1 = 0 THEN
pop_count_parent1 = pop_count_parent
END IF
IF pop_count_child > 2 THEN
A_value_var = (((pop_count_child+1)*A_value_SQ_sum) - (A_value_sum^2)) / (pop_count_child*(pop_count_child+1))
END IF
IF A_value_var > A_value_var_max THEN
A_value_var_max = A_value_var
END IF
aGen_stats(5,gen_count) = A_value_var
IF pop_count_child > 2 THEN
B_value_var = (((pop_count_child+1)*B_value_SQ_sum) - (B_value_sum^2)) / (pop_count_child*(pop_count_child+1))
END IF
IF B_value_var > B_value_var_max THEN
B_value_var_max = B_value_var
END IF
aGen_stats(6,gen_count) = B_value_var
ELSE
IF gen_count_limit = 0 THEN
gen_count_limit = gen_count
END IF
END IF 'pop_count_child > 0
NEXT 'FOR gen_count = 0 TO gen_count_max - 1
'---- end of loop through all of the generations ----
'*********************************************************************
IF gen_count_limit = 0 THEN
gen_count_limit = gen_count_max
END IF
'---------------------------------------------------------------------------
'*********************************************************************
'---------------------------------------------------------------------------
' set it up for a graph bounding box of 2000 horizontal by 1000 vertical
' the viewBox has to be larger, to allow for left (and right?) parameter stuff
' the graph should have 20 by 10 internal dividers (grid pattern)
%>
<%
'' reset the timeout
Server.ScriptTimeout = timeout
Response.End '-----------------------------------------------------------%>