-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdinner.py
97 lines (77 loc) · 3.29 KB
/
dinner.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
# -*- coding: utf-8 -*-
"""
Dinner Time Optimizer
dinner.py
Dinner time optimizer using a simple modified genetic annealing algorithm.
TO-DO: Sort out the fact that [3,3,3] is treated as better
"""
import argparse
from GeneticAlg import *
# printIntro()
#
# Overloaded function to print the answer title of the program (in sweet ASCII
# art) and the input data. Takes in a People object. Uses printPeople() function
def printIntro(people = None):
print "# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #"
print "# ____ #"
print "# (| \ o o #"
print "# | | _ _ _ _ _ ,_ _|_ _ _ _ _ #"
print "# _| || / |/ | / |/ | |/ / | | | / |/ |/ | |/ #"
print "# (/\___/ |_/ | |_/ | |_/|__/ |_/ |_/|_/ | | |_/|__ #"
print "#\t\t\t\t\t\t\t\t#"
print "# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #"
print
if people != None: printPeople(people)
# printOutput()
#
# Function to print the answer generated by the DinnerTime program. Takes in an
# array of DayAnswer objects. Uses printWeekSolution() function.
def printOutput(week):
printWeekSolution(week)
# printPeople()
#
# Prints all of the people in the given People object and their personId. Also
# prints the total number of people in the given object. Used by the
# printOutput() function but can be called from main for debugging.
def printPeople(people):
print "Name\t\tpersonId\tAvailability"
for peep in people.people:
print str(peep.name) + "\t\t" + str(peep.personId) + "\t\t",
for j in range(DINNERS_PER_WEEK):
# Print day of the week (stylized)
if j == 0: print DINNER_DAYS[j],
else: print "\t\t\t\t" + DINNER_DAYS[j],
# Print times available
for i in range(POSSIBLE_TIMES):
if str(peep.availability[i + (j * 5)]) == "1":
print DINNER_TIMES[i],
print
print
print "Number of people: " + str(people.numPeople)
# printWeekSolution()
#
# Prints an array of DayAnswer objects that represent a week in dinners. Takes
# in an array of DayAnswers.
def printWeekSolution(week):
# Loop print example: "Mon 6:00 - Fit: 100.00 - Att. [1, 1, 1, 1]"
for day in range(DINNERS_PER_WEEK):
print("{0:3.3s}".format(DINNER_DAYS[day])), #
print DINNER_TIMES[week.dayAnswers[day].time] + " - Fit: " \
+ str.format("{0:6.2f}", week.dayAnswers[day].fitness) + " - Att. "\
+ str(week.dayAnswers[day].idList),
if (day % 2) == 1: print # Print in two columns
print "Week solution fitness: " + str.format("{0:.2f}", (week.fitness)) \
+ " - Guest Att. " + str(week.guestAttendance[0:3])
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
if __name__ == '__main__':
printIntro()
parser = argparse.ArgumentParser(description='DinnerTime application. '
'www.github.com/ywatanabe/DinnerTime')
parser.add_argument('-c', type = int, default = 10, dest = 'cycles',
help = 'number of cycles. default = 10)')
parser.add_argument('-p', type = int, default = 1000, dest = 'popSize',
help = 'size of the population. default = 1000')
args = parser.parse_args()
answers = startCycle(args.cycles, args.popSize)
for i in range(NUM_ANSWERS):
printOutput(answers[i])