-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomGenerator.py
More file actions
80 lines (61 loc) · 2.95 KB
/
Copy pathRandomGenerator.py
File metadata and controls
80 lines (61 loc) · 2.95 KB
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
import Logger
import GenePool
import ProblemPool
import NeuralNetwork
def singleRandomStructureTest(numInput, numOutput, numLayer, logger, numSimulation):
prbPool = ProblemPool.PROBLEM_POOL()
prbPool.initByGenStr(numInput, numOutput, numLayer, logger, numSimulation)
geenpool = GenePool.GENE_POOL()
geenpool.initGenePool(prbPool, 100)
numGeneration = 0
limitGeneration = 500
learningState = True
while learningState:
if len(geenpool.genePool) < 1:
print "All dead"
break
else:
print "\n\tGeneration " + str(numGeneration) + " is started. Pool size: "+ str(len(geenpool.genePool)) + "\n"
geenpool.doGame(mode=2)
#gp.statLayerCount()
geenpool.evaluationLR(True)
# geenpool.statLayerCount()
# numSimulation,numGeneration,nameCategory,strContent,numBlock=-1
logger.writeGenerationResult(numSimulation,numGeneration,"Percent",geenpool.getStrGenerationPercent())
logger.writeGenerationResult(numSimulation,numGeneration,"Diversity",geenpool.getStrDiversity())
learningState = geenpool.checkLearningState(True)
if not learningState:
break
if limitGeneration == numGeneration:
print "\nGeneration is over a hundred. It is too long time... The simulation end."
learningState = False
break
geenpool.crossover()
geenpool.mutation()
geenpool.evolution()
geenpool.resetCounter()
geenpool.newGene()
print "\n\tGeneration " + str(numGeneration) + " is Ended."
numGeneration += 1
print "\n--------------------------------RESULT------------------------------\n"
geenpool.resetCounter()
geenpool.doGame(mode=2)
geenpool.remainBestOne()
geenpool.resetCounter()
geenpool.excuteBlock(withoutSight = True, mode=2)
geenpool.calSolvingPercentage()
logger.writeSimulationResult(numSimulation, "Result_Percent", geenpool.getStrGenerationPercent())
logger.writeBlockResult(numSimulation, "Result_Str", geenpool.getStrStructureBest())
print "\n---------------------------------------------------------------------"
simulLogger = Logger.LOGGER()
simulLogger.initLogger("Aritifitial Generated","../results/",activate=True)
numSimulation = 0
for iterInput in range(2,14):
for iterOutput in range(2,7):
for iterLayer in range(1,4):
singleRandomStructureTest(iterInput,iterOutput,iterLayer,simulLogger, numSimulation)
# nn = NeuralNetwork.NEURAL_NETWORK()
# nn.genRandomStructure(iterInput, iterOutput, iterLayer)
# print iterInput, iterOutput, iterLayer
# print nn
numSimulation += 1