-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
132 lines (108 loc) · 4.25 KB
/
application.py
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python
"""Application file that runs all algorithms for the RailNL case that were
created by Team Gekke Hackers.
Algorithms:
0. Hillclimber > works for Holland map and National map
1. Hillclimber with simulated annealing > works for Holland map and National map
2. Greedy > due to performance only works for Holland map
__author__ = "Sietze Berends, Daan Uittenhout, Floris Holstege"
__version__ = "1.0"
__maintainer__ = "Sietze Berends"
__email__ = "[email protected]"
__status__ = "Final"
"""
# Built-in modules
from datetime import datetime
import sys
# Own modules and classes
from Algorithms.hillclimberiterator import HillclimberIterator
from Algorithms.greedy import Greedy
from Classes.lijnvoering import Lijnvoering
def main():
if len(sys.argv) != 6:
print("Usage: application.py arg1 arg2 arg3 arg4 arg5")
print("Recommended configuration: application.py holland 500 1600 a " +\
"True")
print("arg1: choose the map (String: 'Holland' or 'National')")
print("arg2: amount of hillclimbers (int > 0, recommended: 500)")
print("arg3: amount of iterations (int > 0, recommended: 1600)")
print("arg4: simulated annealing (String: 'a', 'b', 'c', 'd' or 'e')" +\
", recommended: a)")
print("arg5: show additional details (Bool, recommended: True)")
else:
print("filename: " + sys.argv[0])
print("map: " + sys.argv[1])
print("runs: " + sys.argv[2])
print("iterations: " + sys.argv[3])
print("annealing: " + sys.argv[4])
print("details: " + sys.argv[5])
# Track how long the application runs
startTime = datetime.now()
# Configure the algorithms
hollandFilepath = "CsvFiles/ConnectiesHolland.csv"
netherlandsFilepath = "CsvFiles/ConnectiesNationaal.csv"
mapChoice = ""
# check for map
print(sys.argv[1].lower())
if (sys.argv[1].lower() != "national" and sys.argv[1].lower() !=
"holland"):
print("To choose a map, please enter 'National' or 'Holland'")
return
elif sys.argv[1].lower() == "national":
mapChoice += str(netherlandsFilepath)
else:
mapChoice += str(hollandFilepath)
# check for positive integer
try:
if isinstance(int(sys.argv[2]), int):
if int(sys.argv[2]) > 0:
amountOfHillclimbers = int(sys.argv[2])
else:
print("Please enter a positive integer")
return
else:
print("Please enter a positive integer")
return
except:
print("Please enter an integer")
return
# check for positive integer
try:
if isinstance(int(sys.argv[3]), int):
if int(sys.argv[3]) > 0:
iterationsInHillclimber = int(sys.argv[3])
else:
print("Please enter a positive integer")
return
else:
print("Please enter a positive integer")
return
except:
print("Please enter an integer")
return
# check simulated annealing yes/no/cooling strategy/hardcoded
if sys.argv[4] in ("a", "b", "c", "d", "e"):
simulatedAnnealing = sys.argv[4]
else:
print("use 'a', 'b', 'c', 'd', 'e' for arg4")
return
# check for boolean to print details or not
if sys.argv[5].lower() == "true":
additionalDetails = True
elif sys.argv[5].lower() == "false":
additionalDetails = False
else:
print("Use 'True' or 'False' for arg5")
return
# # # Run hillclimber algorithm on Holland map
# # hc = HillclimberIterator(mapChoice, amountOfHillclimbers
# # , iterationsInHillclimber, simulatedAnnealing
# # , additionalDetails)
# hc.algorithm()
# Run greedy algorithm on Holland map
Greedy()
# Print the runtime
timeElapsed = datetime.now()-startTime
print('Time elapsed (hh:mm:ss.ms) {}'.format(timeElapsed))
if __name__ == '__main__':
main()