-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpseudocode.txt
93 lines (63 loc) · 2.55 KB
/
pseudocode.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
SimpleGeneration(size):
population = initialize(size)
for generation i in 1..NUMBER_OF_GENERATIONS do:
newPopulation = evolve(population)
population = pickSurvivingMembers(population, newPopulation)
# export to file
return population
pickSurvivingMembers ( oldPopulation, newPopulation )
population = oldPopulation + newPopulation
sort population by fitness
removeSimilarMembers(population) # leaves ones with best fitness
trimPopulationSize ( population, MAXIMUM_POPULATION_SIZE )
return population
evolve(population):
newPopulation = empty
# crossover
for i in range CROSSOVER_SIZE do:
children = crossover( tournamentSelection(population), tournamentSelection(population))
for child in children:
child = mutate(child)
newPopulation += children
# mutation
for piece in population:
newPopulation += mutate(piece)
# filtering (intersections, MIN_ANGLE, NaN fitness etc.)
removeUnfitMembers(newPopulation)
return newPopulation
mutate(piece):
random = random from 0..1
if( random < STARTING_POINT_CHANCE )
changeStartingPoint(piece)
part = getRandomPart( piece )
if( random < CHANCE_TO_CHANGE_POINT ):
changeRandomPointInPart ( part )
else if ( random < (CHANCE_TO_CHANGE_PART + CHANCE_TO_CHANGE_POINT) ):
promotePart ( part )
else
convertToAsymmetric( piece )
# ensures piece stars and ends on y = 200 (or ends on x = 100 for symmetric pieces)
# ensures that each point p is within bounds 0 <= p <= 200 (HEIGHT, WIDTH)
fixPieceAndEnsureIsWithinBounds ( piece )
return piece
changeRandomPointInPart ( part ):
point = getRandomPointFromPart ( part ) # uniformly
point.x = random from range (point.x - OFFSET)..(point.x + OFFSET)
point.y = random from range (point.y - OFFSET)..(point.y + OFFSET)
promotePart ( part ):
switch ( part ) :
case Line:
if( random from range (0..1) < CHANCE_TO_SPLIT_LINE):
return splitLineInHalf ( part )
else:
return convertLineToArc ( part ) # part.q becomes (middle of line += 5)
case Arc:
return convertArcToDoubleArc ( part ) # q1 = q2 = part.q
case DoubleArc:
return convertDoubleArcToLine( part )
tournamentSelection ( population ):
elements = randomly pick TOURNAMENT_SIZE elements from population
sort elements by FITNESS
return best element from elements
crossover ( parent1, parent2 )
# to się jeszcze zmieni