JobShopScheduling/src/main.py

66 lines
1.6 KiB
Python
Raw Normal View History

2017-06-20 15:05:38 +02:00
#! /usr/bin/env python
2017-06-19 00:15:15 +02:00
2017-07-12 17:55:16 +02:00
import sys
import getopt
from SchedulingAlgorithms import simanneal as sim
from Outpout import output as o
def usage():
s= """
Command line options:
-h show this help
-p activate pretty output (matplotlib)
-l assume that a file contains multiple problems, default is only 1
-i index of the problem you want solved. has no effect without l
Invocation:
python [-hlp] file
"""
return s
def main():
js1 = False
plot = False
try:
opts, args = getopt.getopt(sys.argv[1:], 'hpli:')
except getoptGetoptError as err:
print(err)
sys.exit()
if ('-h', '') in opts:
print(usage())
if ('-p', '') in opts:
print("Plotting enabled.")
plot = True
if('-l', '') in opts:
js1 = True
idx = [int(x[1]) for x in opts if x[0]=='-i']
idx = idx[0] if idx else -1
if not args:
print("No file given.")
sys.exit()
else:
infile = args[0]
if js1:
from Parser import js1_style as parser
else:
from Parser import js2_style as parser
print("Parsing file: " + infile)
problem = parser.parse_file(infile)
if js1 and idx == -1:
print("File contains " + str(len(problem)) + " problems.")
idx = int(input("Which problem do you want so solve? [0-" + str(len(problem)-1) + "] "))
problem = problem[idx]
print(problem)
sim.init(problem)
solution = sim.anneal()
print(solution)
print(sim.rate(solution))
if plot:
o.create_plot(problem, solution)
if __name__ == "__main__":
2017-06-19 00:15:15 +02:00
main()
2017-07-12 17:55:16 +02:00