-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfinalcode2.py
More file actions
53 lines (50 loc) · 1.92 KB
/
finalcode2.py
File metadata and controls
53 lines (50 loc) · 1.92 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
#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: William
#
# Created: 02/12/2012
# Copyright: (c) William 2012
# Licence: <your licence>
#-------------------------------------------------------------------------------
#!/usr/bin/env python
import framework, GeneticAlgorithm, simulatedannealing, ASAGA
alg = [GeneticAlgorithm.Environment,simulatedannealing.model,ASAGA.Environment]
letter = ["A","B","C"]
probPath = "samplesets/Final Run/"
dataFile = "data/final.csv"
dataProgFile = "data/finalProg.csv"
dataMatrixFile = "data/finalMatrix.txt"
def main():
file = open(dataFile, "w")
file.write("\"Treatment\",\"Problem\",\"Outcome\",\"Real Time\",\"CPU Time\",\"#Generations\",\"Starting State\"\n")
file.close()
file = open(dataProgFile, "w")
file.write("")
file.close()
file = open(dataMatrixFile, "w")
file.write("")
file.close()
for i in range(1,31):
problem = framework.timetableProblem()
name = str(i)
if len(name) == 1:
name = "0" + name
problem.setupXML(probPath + name + ".xml")
for j in range(0,3):
for k in range(0,30):
print str(i) + letter[j] + str(k)
mod = alg[j](problem)
rundata = mod.run()
file = open(dataFile, "a")
file.write(letter[j] + "," + str(i) + "," + ",".join([str(dat) for dat in rundata[0:4] + rundata[5:6]]) + "\n")
file.close()
file = open(dataProgFile, "a")
file.write(letter[j] + "," + str(i) + "," + ",".join(rundata[4]) + "\n")
file.close()
file = open(dataMatrixFile, "a")
file.write(letter[j] + str(i) + "\n" + rundata[6] + "\n\n")
file.close()
if __name__ == '__main__':
main()