1
1
import random
2
2
import numpy as np
3
3
import pandas
4
+ import matplotlib .pyplot as plt
4
5
5
6
"""
6
7
This simple program will try to sort out a seating chart from a list of
@@ -139,6 +140,9 @@ def pick_friend_of(self, guestname):
139
140
140
141
def seat_guest (self , guestname ):
141
142
n = guestname
143
+ if len (self .open ) == 0 :
144
+ print "No more seats!"
145
+ return
142
146
seatindex = self .open .pop (random .randrange (len (self .open )))
143
147
self .chart [seatindex [0 ]][seatindex [1 ]] = n
144
148
@@ -148,19 +152,18 @@ def seat_guest(self, guestname):
148
152
self .toseat .remove (n )
149
153
150
154
def seat_guest_here (self , guestname , index ):
151
- n = guestname
152
155
# check if the seat is open
153
156
if self .open .count (index ) == 0 :
154
157
print "the seat is already filled!!"
155
158
return None
156
159
else :
157
160
self .open .remove (index )
158
- self .chart [index [0 ]][index [1 ]] = n
161
+ self .chart [index [0 ]][index [1 ]] = guestname
159
162
160
163
# update the seatdict, and seated
161
- self .seated .append (n )
162
- self .seatdict [n ] = index
163
- self .toseat .remove (n )
164
+ self .seated .append (guestname )
165
+ self .seatdict [guestname ] = index
166
+ self .toseat .remove (guestname )
164
167
165
168
def seat_guestfriend (self , guestname , friendname ):
166
169
"""
@@ -355,3 +358,55 @@ def metropolisstep(self, temp=0.1):
355
358
else :
356
359
print "it's temporarily worse but keep it"
357
360
return friendcount1
361
+
362
+ def main (excelfilein ,excelfileout ):
363
+ guestlist = GuestList ()
364
+ guestlist .fromExcel (excelfilein )
365
+ guestlist .print_friendlist ()
366
+
367
+
368
+ nguests = len (guestlist .guests )
369
+ print nguests
370
+ seatsper = 8
371
+ print nguests / seatsper
372
+
373
+ chart = SeatingChart (guestlist , nguests / seatsper + 1 , seatsper )
374
+ org = Organizer (guestlist , chart )
375
+ # Seat everyone
376
+ print "Seat guests with a friend"
377
+ org .seatguestsfriends ()
378
+ print "now do Metropolis algorithim to increase friendships"
379
+ count0 = org .friendcount ()
380
+ nsteps = 1000
381
+ friendsT1 = np .zeros (nsteps )
382
+ steps = np .arange (nsteps )
383
+ for i in steps :
384
+ print i
385
+ friendsT1 [i ] = org .metropolisstep (temp = 0.01 )
386
+ count1 = org .friendcount ()
387
+ print "Metropolis algorithm added {0} friends" .format (count1 - count0 )
388
+ print "export seating chart to an excel file"
389
+ plt .plot (steps , friendsT1 , label = 'T1' )
390
+ plt .xlabel = "step"
391
+ plt .ylabel = "friendships"
392
+ plt .show ()
393
+ org .sc .to_excel (excelfileout )
394
+
395
+
396
+ if __name__ == '__main__' :
397
+ import sys
398
+ umesg = "python -m seatingchart.seatingchar excelfilein (excelfileout)"
399
+ if len (sys .argv ) > 1 :
400
+ # print 'nothing here'
401
+ if len (sys .argv ) > 2 :
402
+ excelfilein = sys .argv [1 ]
403
+ excelfileout = sys .argv [2 ]
404
+ main (excelfilein , excelfileout )
405
+ else :
406
+ excelfilein = sys .argv [1 ]
407
+ excelfileout = excelfilein [:- 5 ]+ "out" + excelfilein [- 5 :]
408
+ main (excelfilein , excelfileout )
409
+ else :
410
+ print umesg
411
+
412
+
0 commit comments